1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
package maxloc;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.plugin.PlugIn;
import ij.WindowManager;
/*import java.util.ArrayList;
import mcib3d.geom.Voxel3D;
import mcib3d.geom.Voxel3DComparable;*/
import java.lang.Math;
public class Local_maxima implements PlugIn {
public static void main(String[] args) {
//IJ.runPlugIn("localmaxima","");
IJ.runPlugIn(new ImagePlus(), "local_maxima", "");
}
public void run (String args){
//collect of every information about the rawImage
ImagePlus image = WindowManager.getCurrentImage();
//ImageStack maxima = exec(image);
ImageStack maxima = exec(image);
if (null != maxima) {
ImagePlus scaled = new ImagePlus("Local maxima 3D", maxima);
scaled.show();
}
}
public ImageStack exec (ImagePlus img)
//public int[][][] exec (ImagePlus img)
{
//collect of every information about the image
ImageStack im = img.getStack();
int wi=im.getWidth();
int he=im.getHeight();
int dep=im.getSize();
double bool;
float dx = 0.645f;
float dy= 0.645f;
int dz= 1; //rawImage.getVoxel(10,10,10).getRoundZ();
//creation of four tabs
ImageStack gx = new ImageStack(wi, he);
ImageStack gy = new ImageStack(wi, he);
ImageStack gz = new ImageStack(wi, he);
//float[][][] gx = new float[width][height][depth];
//float[][][] gy = new float[width][height][depth];
//float[][][] gz = new float[width][height][depth];
double[][][] ng = new double[wi][he][dep];
//calcul of the 3 components of the gradient and the norm of it
for (int k=0;k<dep;k++){
for (int i=0;i<wi;i++){
for (int j=0;j<he;j++){
gx.setVoxel(i,j,k,(im.getVoxel(i+1,j,k)-im.getVoxel(i,j,k))/dx);
gy.setVoxel(i,j,k,(im.getVoxel(i,j+1,k)-im.getVoxel(i,j,k))/dy);
gz.setVoxel(i,j,k,(im.getVoxel(i,j,k+1)-im.getVoxel(i,j,k))/dz);
ng[i][j][k]=gx.getVoxel(i,j,k)*gx.getVoxel(i,j,k) + gy.getVoxel(i,j,k)*gy.getVoxel(i,j,k) + gz.getVoxel(i,j,k)*gz.getVoxel(i,j,k);
}
}
}
//creation of the image of local maxima
//int [][][] maxloc = new int[wi][he][dep];
ImageStack maxloc = new ImageStack();
for(int k=2; k <= dep-1; k++){
for (int i=2; i <= wi-1; i++){
for (int j=2; j <= he-1; j++){
if(Math.abs(gx.getVoxel(i,j,k))>=Math.abs(gy.getVoxel(i,j,k))&Math.abs(gx.getVoxel(i,j,k))> Math.abs(gz.getVoxel(i,j,k)))
{
if(ng[i][j][k]>=ng[i-1][j][k] && ng[i][j][k]>=ng[i+1][j][k])
{
bool=1;
}
else{
bool=0;
}
}
else if(Math.abs(gy.getVoxel(i,j,k))>Math.abs(gx.getVoxel(i,j,k))& Math.abs(gy.getVoxel(i,j,k))>= Math.abs(gz.getVoxel(i,j,k)))
{
if(ng[i][j][k]>=ng[i][j-1][k] && ng[i][j][k]>=ng[i][j+1][k])
{
bool=1;
}
else{
bool=0;
}
}
else if(Math.abs(gz.getVoxel(i,j,k))>=Math.abs(gx.getVoxel(i,j,k))&Math.abs(gz.getVoxel(i,j,k))> Math.abs(gy.getVoxel(i,j,k)))
{
if(ng[i][j][k]>=ng[i][j][k-1] && ng[i][j][k]>=ng[i][j][k+1]){
bool=1;
}
else{
bool=0;
}
}
else{
if(ng[i][j][k]>=ng[i-1][j][k] && ng[i][j][k]>=ng[i+1][j][k])
{
bool=1;
}
else{
bool=0;
}
}
maxloc.setVoxel(i,j,k,bool);
//maxloc[i][j][k]=bool;
}
}
}
return maxloc;
}
} |
Partager