use of mcib3d.image3d.ImageLabeller in project mcib3d-core by mcib3d.
the class Watershed3D method createNeigList.
private void createNeigList() {
voxels = new LinkedList<Voxel3DComparable>();
int sx = rawImage.sizeX;
int sy = rawImage.sizeY;
int sz = rawImage.sizeZ;
// watershed images
watershedImage = new ImageShort("watershed", sx, sy, sz);
labelQueueImage = new ImageShort("labelQ", sx, sy, sz);
// okseeds = false;
float pix;
float se;
// compute the seeds image
// threshold, // TODO 32-bits seeds ?
ImageHandler seedsLabel = seedsImage.duplicate();
seedsLabel.thresholdCut(seedsThreshold, false, true);
if ((labelSeeds)) {
log.log("Labelling ");
ImageLabeller labeller = new ImageLabeller();
seedsLabel = labeller.getLabels(seedsLabel);
}
// since seeds Label starts at 1 and watershed at 2, replace values
int max = (int) seedsLabel.getMax();
if (seedsLabel.hasOneValue(QUEUE)) {
seedsLabel.replacePixelsValue(QUEUE, max + 1);
seedsValue.put(max + 1, QUEUE);
}
if (seedsLabel.hasOneValue(DAM)) {
seedsLabel.replacePixelsValue(DAM, max + 2);
seedsValue.put(max + 2, DAM);
}
if (!seedsValue.isEmpty())
seedsLabel.resetStats(null);
for (int z = sz - 1; z >= 0; z--) {
IJ.showStatus("Processing watershed " + (z + 1));
for (int y = sy - 1; y >= 0; y--) {
for (int x = sx - 1; x >= 0; x--) {
pix = rawImage.getPixel(x, y, z);
se = seedsLabel.getPixel(x, y, z);
if (pix > rawThreshold) {
if (se > 0) {
watershedImage.setPixel(x, y, z, se);
// okseeds = true;
ArrayList<Voxel3D> list = watershedImage.getNeighborhood3x3x3ListNoCenter(x, y, z);
Collections.shuffle(list);
for (Voxel3D N : list) {
int vx = (int) N.getX();
int vy = (int) N.getY();
int vz = (int) N.getZ();
float raw = rawImage.getPixel(vx, vy, vz);
if ((raw > rawThreshold) && (seedsLabel.getPixel(vx, vy, vz) == 0) && (watershedImage.getPixel(vx, vy, vz) != QUEUE)) {
voxels.add(new Voxel3DComparable(vx, vy, vz, raw, se));
watershedImage.setPixel(vx, vy, vz, QUEUE);
labelQueueImage.setPixel(vx, vy, vz, se);
}
}
}
}
}
}
}
log.log("Watershed...");
}
use of mcib3d.image3d.ImageLabeller in project mcib3d-core by mcib3d.
the class Watershed3D_old method createArrayList.
private void createArrayList() {
voxels = new ArrayList();
int sx = rawImage.sizeX;
int sy = rawImage.sizeY;
int sz = rawImage.sizeZ;
// watershedImage
this.watershedImage = new ImageShort("watershed", sx, sy, sz);
okseeds = false;
float pix;
float se;
// compute the labelled image (in case seeds are clustered)
ImageLabeller labeller = new ImageLabeller();
ImageInt seedsLabel = labeller.getLabels(seedsImage.thresholdAboveExclusive(seedsThreshold));
// IJ.log("MAX SEEDS " + seedsLabel.getImageStats(null).getMax());
// since seedsLabel starts at 1 and watershed at 2, replace values
seedsLabel.replacePixelsValue(BORDER, (int) seedsLabel.getMax() + 1);
seedsLabel.resetStats(null);
// IJ.log("MAX SEEDS " + seedsLabel.getImageStats(null).getMax());
if (computeVolumes) {
for (int i = 0; i <= seedsLabel.getMax(); i++) {
volumeLabels.add(0.0);
}
}
for (int z = 0; z < sz; z++) {
IJ.showStatus("Processing watershed " + (z + 1));
for (int y = 0; y < sy; y++) {
for (int x = 0; x < sx; x++) {
pix = rawImage.getPixel(x, y, z);
se = seedsLabel.getPixel(x, y, z);
if (pix > rawThreshold) {
// IJ.log("seed found " + x + " " + y + " " + z+" : "+se);
if (se > 0) {
// IJ.log("seed found " + x + " " + y + " " + z);
watershedImage.setPixel(x, y, z, se);
voxels.add(new Voxel3DComparable(x, y, z, pix, se));
okseeds = true;
} else {
voxels.add(new Voxel3DComparable(x, y, z, pix, NO_LABEL));
watershedImage.setPixel(x, y, z, NO_LABEL);
}
} else {
watershedImage.setPixel(x, y, z, NO_LABEL);
}
// compute volumes (warning if seeds are float values)
if (computeVolumes) {
// volumeLabels.get((int) se)[1]++;
volumeLabels.set((int) se, volumeLabels.get((int) se) + 1);
}
}
}
}
}
Aggregations