use of mcib3d.geom.Voxel3DComparable in project mcib3d-core by mcib3d.
the class FastFilters3D method getListMaximaFloat.
public static ArrayList<Voxel3DComparable> getListMaximaFloat(ImageFloat stackorig, float vx, float vy, float vz, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// get stack info
final float voisx = vx;
final float voisy = vy;
final float voisz = vz;
final ImageFloat ima = stackorig;
// PARALLEL
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
final ArrayList<Voxel3DComparable>[] listes = new ArrayList[n_cpus];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
listes[k] = ima.getListMaxima(voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
final ArrayList<Voxel3DComparable> liste = new ArrayList<Voxel3DComparable>();
for (ArrayList<Voxel3DComparable> li : listes) {
liste.addAll(li);
}
return liste;
}
use of mcib3d.geom.Voxel3DComparable in project mcib3d-core by mcib3d.
the class FastFilters3D method getListMaximaInt.
public static ArrayList<Voxel3DComparable> getListMaximaInt(ImageInt stackorig, float vx, float vy, float vz, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// get stack info
final float voisx = vx;
final float voisy = vy;
final float voisz = vz;
final ImageInt ima = stackorig;
// PARALLEL
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
final ArrayList<Voxel3DComparable>[] listes = new ArrayList[n_cpus];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
listes[k] = ima.getListMaxima(voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
final ArrayList<Voxel3DComparable> liste = new ArrayList<Voxel3DComparable>();
for (ArrayList<Voxel3DComparable> li : listes) {
liste.addAll(li);
}
return liste;
}
use of mcib3d.geom.Voxel3DComparable 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));
}
}
use of mcib3d.geom.Voxel3DComparable in project mcib3d-core by mcib3d.
the class Watershed3D_old method assignWatershedAccurate.
private boolean assignWatershedAccurate(int threshold) {
Voxel3DComparable voxel;
int px, py, pz;
ArrayUtil neigh;
int max, max2;
boolean loop = false;
ArrayList<Voxel3DComparable> voxelsNextRound = new ArrayList();
ArrayList<Voxel3DComparable> voxelsToProcess = new ArrayList();
for (Iterator it = voxels.iterator(); it.hasNext(); ) {
voxel = (Voxel3DComparable) it.next();
if (voxel.getValue() < threshold) {
// voxelsNextRound.addAll(voxels.subList(voxels.indexOf(voxel), voxels.size()));
break;
// voxelsNextRound.add(voxel);
// continue;
}
px = voxel.getRoundX();
py = voxel.getRoundY();
pz = voxel.getRoundZ();
if (watershedImage.getPixel(px, py, pz) == NO_LABEL) {
// 6-neighbor
// neigh = watershedImage.getNeighborhoodCross3D(px, py, pz);
// 26-neighbor
neigh = watershedImage.getNeighborhood3x3x3(px, py, pz);
max = (int) neigh.getMaximum();
if ((max == NO_LABEL) || (max == BORDER)) {
voxelsNextRound.add(voxel);
} else {
// has a neighbor already labeled // test if two differents labels around
voxelsToProcess.add(voxel);
}
}
}
// process voxels
for (Voxel3DComparable vox : voxelsToProcess) {
px = vox.getRoundX();
py = vox.getRoundY();
pz = vox.getRoundZ();
neigh = watershedImage.getNeighborhood3x3x3(px, py, pz);
max = (int) neigh.getMaximum();
max2 = (int) neigh.getMaximumBelow(max);
if ((max2 == NO_LABEL) || (max2 == BORDER)) {
watershedImage.setPixel(px, py, pz, max);
loop = true;
// compute volumes
if (computeVolumes) {
// volumeLabels.get(max)[1]++;
volumeLabels.set(max, volumeLabels.get(max) + 1);
}
// get active label
if (computeUpdatedLabels) {
String la = "" + max;
// test if exists already
boolean ok = true;
for (String S : updatedLabels) {
if ((S.compareTo(la)) == 0) {
ok = false;
break;
}
}
if (ok) {
updatedLabels.add(la);
}
}
// add the new labels sharing a border
if ((max2 == BORDER) && (computeAssociation)) {
updateAssociationBorder(px, py, pz, max);
}
// two or more labels around
} else {
watershedImage.setPixel(px, py, pz, BORDER);
// get association
if (computeAssociation) {
String asso = max + "_" + max2;
AssociationRegion assoR = new AssociationRegion();
assoR.addRegion(max);
assoR.addRegion(max2);
max2 = (int) neigh.getMaximumBelow(max2);
while ((max2 != NO_LABEL) && (max2 != BORDER)) {
asso = asso.concat("_" + max2);
assoR.addRegion(max2);
max2 = (int) neigh.getMaximumBelow(max2);
}
// if next to border update
if ((max2 == BORDER) && (computeAssociation)) {
for (String S : asso.split("_")) {
updateAssociationBorder(px, py, pz, Integer.parseInt(S));
}
}
// test if association exists already
boolean ok = true;
for (String S : associations) {
if ((S.compareTo(asso)) == 0) {
ok = false;
break;
}
}
if (ok) {
associations.add(asso);
}
assoRegions.addAssoRegion(assoR);
}
}
}
voxels = voxelsNextRound;
System.gc();
return loop;
}
use of mcib3d.geom.Voxel3DComparable in project mcib3d-core by mcib3d.
the class MaximaFinder method computePeaks.
private void computePeaks() {
imagePeaks = new ImageShort("peaks", img.sizeX, img.sizeY, img.sizeZ);
if (verbose) {
IJ.log("Finding all peaks");
}
ArrayList<Voxel3DComparable> maximaTmp = FastFilters3D.getListMaxima(img, radXY, radXY, radZ, nbCpus, false);
Collections.sort(maximaTmp);
for (Voxel3DComparable V : maximaTmp) {
imagePeaks.setPixel(V, (float) V.getValue());
}
if (verbose) {
IJ.log(maximaTmp.size() + " peaks found");
}
if (verbose) {
IJ.log("Removing peaks below noise");
}
maxima = new ArrayList<Voxel3D>();
int c = 1;
int nb = maximaTmp.size();
Date start = new Date();
Date temp;
for (Voxel3DComparable V : maximaTmp) {
if (img.getPixel(V) > 0) {
if (V.getValue() > noiseTolerance) {
maxima.add(V);
if (verbose) {
temp = new Date();
if ((temp.getTime() - start.getTime()) > 100) {
IJ.showStatus("Processing peak " + c + "/" + nb + " " + V);
start = new Date();
}
c++;
}
Flood3D.flood3DNoise26(img, new IntCoord3D(V.getRoundX(), V.getRoundY(), V.getRoundZ()), (int) (Math.max(1, V.getValue() - noiseTolerance)), 0);
}
}
}
if (verbose) {
IJ.log(maxima.size() + " peaks found");
}
if (verbose) {
IJ.log("Creating final peaks");
}
imagePeaks.fill(0);
for (Voxel3D V : maxima) {
imagePeaks.setPixel(V, (float) V.getValue());
}
if (verbose) {
IJ.log("MaximaFinder3D finished.");
}
}
Aggregations