use of mcib3d.geom.ComparatorVoxel in project mcib3d-core by mcib3d.
the class Watershed3D method processWatershed.
private void processWatershed() {
long step = 100;
createNeigList();
long t0 = System.currentTimeMillis();
if (anim) {
watershedImage.show();
}
if (rawImage.getMin() > rawThreshold) {
log.log("Setting minimum for raw image to " + rawImage.getMin());
rawThreshold = rawImage.getMin();
}
// tree set
ComparatorVoxel comp = new ComparatorVoxel();
TreeSet<Voxel3DComparable> tree = new TreeSet<Voxel3DComparable>(comp);
int idx = 1;
for (Voxel3DComparable V : voxels) {
V.setMax(idx, 0);
idx++;
tree.add(V);
}
boolean newt = true;
log.log("");
if (log instanceof IJLog)
((IJLog) (log)).setUpdate(true);
while (newt) {
newt = false;
while (!tree.isEmpty()) {
Voxel3DComparable V = tree.pollFirst();
ArrayList<Voxel3D> Nei = watershedImage.getNeighborhood3x3x3ListNoCenter(V.getRoundX(), V.getRoundY(), V.getRoundZ());
// if in DAM, do not process
if (watershedImage.getPixel(V) == DAM)
continue;
watershedImage.setPixel(V, labelQueueImage.getPixel(V));
// all free voxels around are put into queue
for (Voxel3D N : Nei) {
float rawN = rawImage.getPixel(N);
if (rawN > rawThreshold) {
// neighbor voxel not in queue yet
if ((N.getValue() == 0)) {
watershedImage.setPixel(N, QUEUE);
labelQueueImage.setPixel(N, (int) V.getLabel());
Voxel3DComparable Vnew = new Voxel3DComparable(N.getRoundX(), N.getRoundY(), N.getRoundZ(), rawN, V.getLabel());
Vnew.setMax(idx, 0);
idx++;
tree.add(Vnew);
} else // neighbor was already in Q by another label --> dam !
if ((N.getValue() == QUEUE) && (labelQueueImage.getPixel(V) != labelQueueImage.getPixel(N))) {
watershedImage.setPixel(N, DAM);
}
}
}
if (System.currentTimeMillis() - t0 > step) {
log.log("Voxels to process : " + Math.abs(tree.size()));
if (anim) {
watershedImage.updateDisplay();
}
t0 = System.currentTimeMillis();
}
}
}
log.log("Voxels to process : " + Math.abs(tree.size()));
if (log instanceof IJLog)
((IJLog) (log)).setUpdate(false);
log.log("Watershed completed.");
damImage = (ImageInt) watershedImage.createSameDimensions();
watershedImage.transfertPixelValues(damImage, 1, 255);
// replace dam values with 0
watershedImage.replacePixelsValue(1, 0);
// back to original seeds value
for (int val : seedsValue.keySet()) {
watershedImage.replacePixelsValue(val, seedsValue.get(val));
}
}
Aggregations