use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.
the class Segment3DSpots method getLocalMaximum.
public Voxel3D getLocalMaximum(int x, int y, int z, float radx, float rady, float radz) {
Voxel3D v = null;
int sizex = rawImage.sizeX;
int sizey = rawImage.sizeY;
int sizez = rawImage.sizeZ;
double vmax = Double.NEGATIVE_INFINITY;
double pix;
double rx2;
if (radx != 0) {
rx2 = radx * radx;
} else {
rx2 = 1;
}
double ry2;
if (rady != 0) {
ry2 = rady * rady;
} else {
ry2 = 1;
}
double rz2;
if (radz != 0) {
rz2 = radz * radz;
} else {
rz2 = 1;
}
double dist;
int vx = (int) Math.ceil(radx);
int vy = (int) Math.ceil(rady);
int vz = (int) Math.ceil(radz);
for (int k = z - vz; k <= z + vz; k++) {
for (int j = y - vy; j <= y + vy; j++) {
for (int i = x - vx; i <= x + vx; i++) {
if (i >= 0 && j >= 0 && k >= 0 && i < sizex && j < sizey && k < sizez) {
dist = ((x - i) * (x - i)) / rx2 + ((y - j) * (y - j)) / ry2 + ((z - k) * (z - k)) / rz2;
if (dist <= 1.0) {
pix = rawImage.getPixel(i, j, k);
if (pix > vmax) {
v = new Voxel3D(i, j, k, pix);
vmax = pix;
}
}
}
}
}
}
return v;
}
use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.
the class Segment3DSpots method segmentAll.
/**
*/
public void segmentAll() {
segmentedObjects = new ArrayList<Object3D>();
ArrayList<Voxel3D> obj;
int o = 1;
int localThreshold = localValue;
if (labelImage == null) {
this.createLabelImage();
}
// locate seeds
for (int z = 0; z < seedsImage.sizeZ; z++) {
IJ.showStatus("Segmenting slice " + (z + 1));
// IJ.log("Segmenting slice " + (z + 1));
for (int y = 0; y < seedsImage.sizeY; y++) {
for (int x = 0; x < seedsImage.sizeX; x++) {
if (seedsImage.getPixel(x, y, z) > seedsThreshold) {
// LOCAL THRESHOLD
if (localMethod == LOCAL_MEAN) {
localThreshold = (int) localMean(x, y, z);
} else if (localMethod == LOCAL_GAUSS) {
double[] gauss;
gauss = this.gaussianFit(x, y, z, false);
if (gauss != null) {
double thresh = CurveFitter.f(CurveFitter.GAUSSIAN, gauss, GAUSS_PC * gauss[3]);
// IJ.log("gauss sigma : " + gauss[3] + " thresh=" + thresh);
localThreshold = (int) thresh;
}
} else if (localMethod == LOCAL_DIFF) {
localThreshold = (int) Math.max(1, seedsImage.getPixel(x, y, z) - diff);
}
if (localThreshold > 0) {
if (show) {
IJ.log("segmenting spot at : " + x + " " + y + " " + " " + z + " lc=" + localThreshold);
}
}
switch(methodSeg) {
case SEG_CLASSICAL:
obj = this.segmentSpotClassical(x, y, z, localThreshold, o);
break;
case SEG_MAX:
obj = this.segmentSpotMax(x, y, z, localThreshold, o);
break;
case SEG_BLOCK:
obj = this.segmentSpotBlock(x, y, z, localThreshold, o);
break;
default:
obj = this.segmentSpotClassical(x, y, z, localThreshold, o);
break;
}
if ((obj != null) && (obj.size() >= volMin) && (obj.size() <= volMax)) {
segmentedObjects.add(new Object3DVoxels(obj));
// IJ.log("obj size: "+obj.size());
o++;
} else if (obj != null) {
// erase from label image
for (Voxel3D vo : obj) {
labelImage.setPixel(vo.getRoundX(), vo.getRoundY(), vo.getRoundZ(), 0);
}
if (show) {
IJ.log("object volume outside range : " + obj.size());
}
}
}
}
}
}
}
use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.
the class FHTImage3D method getTranslation.
/**
* Gets the translation attribute of the FHTImage3D class
*
* @param xcorr Description of the Parameter
* @return The translation value
*/
public static Voxel3D getTranslation(FHTImage3D xcorr) {
Voxel3D max = xcorr.getMaxPixel();
int sizex = xcorr.sizex;
int sizey = xcorr.sizey;
int sizez = xcorr.sizez;
int centerx = (int) ((sizex) / 2.0F);
int centery = (int) ((sizey) / 2.0F);
int centerz = (int) ((sizez) / 2.0F);
if (!xcorr.centered) {
if (max.getX() >= sizex - centerx) {
max.setX(max.getX() - sizex);
}
if (max.getY() >= sizey - centery) {
max.setY(max.getY() - sizey);
}
if (max.getZ() >= sizez - centerz) {
max.setZ(max.getZ() - sizez);
}
}
return max;
}
use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.
the class Image3D method computeMinMax.
/**
* compute the min and max pixels
*/
protected void computeMinMax() {
minPixel = new Voxel3D(0, 0, 0, getPix(0, 0, 0));
maxPixel = new Voxel3D(0, 0, 0, getPix(0, 0, 0));
for (int k = 0; k < sizez; k++) {
for (int j = 0; j < sizey; j++) {
for (int i = 0; i < sizex; i++) {
double val = getPix(i, j, k);
if (val < minPixel.getValue()) {
minPixel.setVoxel(i, j, k, val);
} else if (val > maxPixel.getValue()) {
maxPixel.setVoxel(i, j, k, val);
}
}
}
}
}
use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.
the class RegionGrowing method getBordersMerge.
public ArrayList<Voxel3D> getBordersMerge(int[] oldLabels, boolean outsideBorders) {
ArrayList<Voxel3D> drawBorders = new ArrayList();
int nb = oldLabels.length;
ArrayList allowedValues = new ArrayList();
allowedValues.add(BORDER);
if (outsideBorders) {
allowedValues.add(NO_LABEL);
}
for (int o : oldLabels) {
allowedValues.add(o);
}
int maxLabel = 0;
for (int z = 0; z < watershedImage.sizeZ; z++) {
for (int y = 0; y < watershedImage.sizeY; y++) {
for (int x = 0; x < watershedImage.sizeX; x++) {
int pix = watershedImage.getPixelInt(x, y, z);
if (pix > maxLabel) {
maxLabel = pix;
}
if (pix == BORDER) {
ArrayUtil neigh = watershedImage.getNeighborhood3x3x3(x, y, z);
// IJ.log("" + neigh + " " + neigh.hasOnlyValuesInt(allowedValues));
if (neigh.hasOnlyValuesInt(allowedValues)) {
drawBorders.add(new Voxel3D(x, y, z, pix));
// IJ.log("border " + x + " " + y + " " + z);
}
}
}
}
}
return drawBorders;
}
Aggregations