Search in sources :

Example 6 with Voxel3DComparable

use of mcib3d.geom.Voxel3DComparable 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...");
}
Also used : ImageHandler(mcib3d.image3d.ImageHandler) ImageShort(mcib3d.image3d.ImageShort) ImageLabeller(mcib3d.image3d.ImageLabeller) Voxel3D(mcib3d.geom.Voxel3D) Voxel3DComparable(mcib3d.geom.Voxel3DComparable)

Example 7 with Voxel3DComparable

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

the class Watershed3D_old method assignWatershedFastLessAccurate.

private boolean assignWatershedFastLessAccurate(int threshold) {
    Voxel3DComparable voxel;
    int px, py, pz;
    ArrayUtil neigh;
    int max, max2;
    boolean loop = false;
    ArrayList voxelsNextRound = 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
                max2 = (int) neigh.getMaximumBelow(max);
                // only one label around
                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;
    return loop;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Voxel3DComparable(mcib3d.geom.Voxel3DComparable) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 8 with Voxel3DComparable

use of mcib3d.geom.Voxel3DComparable 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);
                }
            }
        }
    }
}
Also used : ImageShort(mcib3d.image3d.ImageShort) ImageLabeller(mcib3d.image3d.ImageLabeller) ArrayList(java.util.ArrayList) ImageInt(mcib3d.image3d.ImageInt) Voxel3DComparable(mcib3d.geom.Voxel3DComparable)

Aggregations

Voxel3DComparable (mcib3d.geom.Voxel3DComparable)8 ArrayList (java.util.ArrayList)5 Voxel3D (mcib3d.geom.Voxel3D)3 ImageShort (mcib3d.image3d.ImageShort)3 Iterator (java.util.Iterator)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 ImageLabeller (mcib3d.image3d.ImageLabeller)2 ArrayUtil (mcib3d.utils.ArrayUtil)2 Chrono (mcib3d.utils.Chrono)2 AbstractLog (mcib3d.utils.Logger.AbstractLog)2 IJStatus (mcib3d.utils.Logger.IJStatus)2 Date (java.util.Date)1 ComparatorVoxel (mcib3d.geom.ComparatorVoxel)1 IntCoord3D (mcib3d.geom.IntCoord3D)1 ImageHandler (mcib3d.image3d.ImageHandler)1 ImageInt (mcib3d.image3d.ImageInt)1 IJLog (mcib3d.utils.Logger.IJLog)1