Search in sources :

Example 16 with Voxel3D

use of mcib3d.geom.Voxel3D 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));
    }
}
Also used : IJLog(mcib3d.utils.Logger.IJLog) ComparatorVoxel(mcib3d.geom.ComparatorVoxel) Voxel3D(mcib3d.geom.Voxel3D) Voxel3DComparable(mcib3d.geom.Voxel3DComparable)

Example 17 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class SpatialRandom method getSample.

@Override
public Objects3DPopulation getSample() {
    Point3D[] points = new Point3D[nbObjects];
    Objects3DPopulation pop = new Objects3DPopulation();
    pop.setMask(mask);
    ImageInt maskimgTmp = maskimg.duplicate();
    Random ra = new Random();
    for (int i = 0; i < nbObjects; i++) {
        Voxel3D vox = maskVox.getRandomvoxel(ra);
        while (maskimgTmp.getPixel(vox) == 0) {
            vox = maskVox.getRandomvoxel(ra);
        }
        points[i] = vox;
        maskimgTmp.setPixel(vox, 0);
    }
    pop.addPoints(points);
    return pop;
}
Also used : Random(java.util.Random) Point3D(mcib3d.geom.Point3D) ImageInt(mcib3d.image3d.ImageInt) Voxel3D(mcib3d.geom.Voxel3D) Objects3DPopulation(mcib3d.geom.Objects3DPopulation)

Example 18 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class SpatialRandomHardCore method getSample.

@Override
public Objects3DPopulation getSample() {
    Point3D[] points = new Point3D[nbObjects];
    Objects3DPopulation pop = new Objects3DPopulation();
    pop.setMask(mask);
    Random ra = new Random();
    ImageInt maskImgTmp = maskimg.duplicate();
    ObjectCreator3D create = new ObjectCreator3D(maskImgTmp);
    for (int i = 0; i < nbObjects; i++) {
        Voxel3D vox = maskVox.getRandomvoxel(ra);
        while (maskImgTmp.getPixel(vox) == 0) {
            vox = maskVox.getRandomvoxel(ra);
        }
        points[i] = vox;
        create.createSphere(vox.getRoundX(), vox.getRoundY(), vox.getRoundZ(), distHardCore, 0, false);
    }
    pop.addPoints(points);
    return pop;
}
Also used : ObjectCreator3D(mcib3d.geom.ObjectCreator3D) Random(java.util.Random) Point3D(mcib3d.geom.Point3D) ImageInt(mcib3d.image3d.ImageInt) Voxel3D(mcib3d.geom.Voxel3D) Objects3DPopulation(mcib3d.geom.Objects3DPopulation)

Example 19 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class Deriche method voxelsCounter.

// Pourcentage de voxels noirs/blancs dans une surface
public float voxelsCounter(ArrayList<Voxel3D> voxels, ImageStack s, boolean b) {
    float percent = 0.f;
    int c1, c2;
    double val;
    for (Voxel3D voxel : voxels) {
        val = s.getVoxel(voxel.getRoundX(), voxel.getRoundY(), voxel.getRoundZ());
    }
    return percent;
}
Also used : Voxel3D(mcib3d.geom.Voxel3D)

Example 20 with Voxel3D

use of mcib3d.geom.Voxel3D in project mcib3d-core by mcib3d.

the class Align2DData method XCorr.

/**
 *  crosscorrelation of all images
 */
public void XCorr() {
    int rayon = sizex < sizey ? sizex / 2 : sizey / 2;
    // ImageProcessor tmp = insert2(serie[0].getImage(true), rayon, true);
    int oldtx = serie[0].getTx();
    int oldty = serie[0].getTy();
    ImageProcessor ip = serie[0].getImage(true);
    ip.setRoi(selection);
    FHTImage3D fht1 = new FHTImage3D(ip.crop());
    FHTImage3D fht2;
    int totx = 0;
    int toty = 0;
    System.out.println("Xcorr...");
    Chrono time = new Chrono(sizez - 1);
    time.start();
    for (int i = 1; i < sizez; i++) {
        // if (show) {
        // IJ.showStatus("" + i + "/" + (sizez - 1));
        // }
        // tmp = insert2(serie[i].getImage(true), rayon, true);
        ip = serie[i].getImage(true);
        ip.setRoi(selection);
        fht2 = new FHTImage3D(ip.crop());
        Voxel3D max = FHTImage3D.getMaxCorrelation(fht1, fht2);
        fht1 = fht2;
        int tmpx = oldtx;
        int tmpy = oldty;
        oldtx = serie[i].getTx();
        oldty = serie[i].getTy();
        serie[i].addTranslation(serie[i - 1].getTx() + max.getX() - tmpx, serie[i - 1].getTy() + max.getY() - tmpy);
        totx += serie[i].getTx();
        toty += serie[i].getTy();
        time.stop();
        String strtime = "Xcorr : " + 100 * (i + 1) / sizez + "% remaining " + time.remainString(i);
        System.out.print("\r                                                                 \r" + strtime + " total :" + time.totalTimeEstimateString(i) + "           ");
        if (show) {
            IJ.showStatus(strtime);
        }
    // System.out.print("\r" + 100 * (i + 1) / sizez + "% \t" + time.delayString() + "\t (" + time.remainString(i) + ")                ");
    }
    totx /= sizez;
    toty /= sizez;
    for (int i = 0; i < sizez; i++) {
        serie[i].addTranslation(-totx, -toty);
        IJ.log(" final image " + i + " : tx =" + serie[i].getTx() + ", ty=" + serie[i].getTy());
    }
    System.out.print("\n");
    IJ.freeMemory();
}
Also used : Chrono(mcib3d.utils.Chrono) ImageProcessor(ij.process.ImageProcessor) Voxel3D(mcib3d.geom.Voxel3D) FHTImage3D(mcib3d.image3d.legacy.FHTImage3D)

Aggregations

Voxel3D (mcib3d.geom.Voxel3D)28 ArrayList (java.util.ArrayList)11 Object3DVoxels (mcib3d.geom.Object3DVoxels)6 Iterator (java.util.Iterator)3 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)3 ImagePlus (ij.ImagePlus)2 ImageProcessor (ij.process.ImageProcessor)2 Random (java.util.Random)2 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)2 Point3D (mcib3d.geom.Point3D)2 ImageInt (mcib3d.image3d.ImageInt)2 ImageShort (mcib3d.image3d.ImageShort)2 FHTImage3D (mcib3d.image3d.legacy.FHTImage3D)2 ArrayUtil (mcib3d.utils.ArrayUtil)2 Point3d (com.github.quickhull3d.Point3d)1 QuickHull3D (com.github.quickhull3d.QuickHull3D)1 Roi (ij.gui.Roi)1 RoiManager (ij.plugin.frame.RoiManager)1 Rectangle (java.awt.Rectangle)1 Date (java.util.Date)1