Search in sources :

Example 11 with ImageInt

use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.

the class BinaryMorpho method binaryOpenMultilabel.

public static ImageInt binaryOpenMultilabel(ImageInt in, float radius, float radiusZ, int nbCPUs) {
    ImageByte[] ihs = in.crop3DBinary();
    if (ihs != null) {
        for (int idx = 0; idx < ihs.length; idx++) {
            /*if (radius <= 1 && radiusZ <= 1) {
                 ihs[idx] = BinaryMorpho.binaryOpenRad1(ihs[idx], 1, nbCPUs);
                 } else {
                 ihs[idx] = binaryOpen(ihs[idx], radius, radiusZ, nbCPUs);
                 }*/
            ihs[idx] = binaryOpen(ihs[idx], radius, radiusZ, nbCPUs);
        }
        ImageInt temp = ImageShort.merge3DBinary(ihs, in.sizeX, in.sizeY, in.sizeZ);
        temp.setScale(in);
        temp.setOffset(in);
        return temp;
    }
    return in;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageInt(mcib3d.image3d.ImageInt)

Example 12 with ImageInt

use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.

the class BinaryMorpho method binaryDilateMultilabel.

public static ImageInt binaryDilateMultilabel(ImageInt in, float[] radiusXY, float[] radiusZ, int nbCPUs) {
    ImageByte[] ihs = in.crop3DBinary();
    if ((radiusXY.length != ihs.length) || (radiusZ.length != ihs.length)) {
        return null;
    }
    if (ihs != null) {
        // ij.IJ.log("BinaryClose multilabel nb :"+ihs.length);
        for (int idx = 0; idx < ihs.length; idx++) {
            ihs[idx] = binaryDilate(ihs[idx], radiusXY[idx], radiusZ[idx], nbCPUs);
        }
        ImageInt temp = ImageShort.merge3DBinary(ihs, in.sizeX, in.sizeY, in.sizeZ);
        temp.setScale(in);
        temp.setOffset(in);
        return temp;
    }
    return in;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageInt(mcib3d.image3d.ImageInt)

Example 13 with ImageInt

use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.

the class BinaryMorpho method binaryCloseRad1.

private static ImageByte binaryCloseRad1(final ImageInt in_, final float thld, int nbCPUs) {
    if (nbCPUs == 0) {
        nbCPUs = ThreadUtil.getNbCpus();
    }
    // TODO: faire sans resize avec un simple décalage des indices
    final ImageInt in = (ImageInt) in_.resize(1, 1, 1);
    final ImageByte max = new ImageByte("max", in.sizeX, in.sizeY, in.sizeZ);
    final ThreadRunner tr = new ThreadRunner(0, max.sizeZ, nbCPUs);
    for (int i = 0; i < tr.threads.length; i++) {
        tr.threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                for (int z = tr.ai.getAndIncrement(); z < tr.end; z = tr.ai.getAndIncrement()) {
                    for (int y = 0; y < max.sizeY; y++) {
                        for (int x = 0; x < max.sizeX; x++) {
                            if (maxRad1(in, thld, x, y, z)) {
                                max.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr.startAndJoin();
    final ThreadRunner tr2 = new ThreadRunner(0, in.sizeZ, nbCPUs);
    final ImageByte close = new ImageByte(in.getTitle() + "::close", in.sizeX, in.sizeY, in.sizeZ);
    for (int i = 0; i < tr2.threads.length; i++) {
        tr2.threads[i] = new Thread(new Runnable() {

            public void run() {
                for (int z = tr2.ai.getAndIncrement(); z < tr2.end; z = tr2.ai.getAndIncrement()) {
                    for (int y = 0; y < in.sizeY; y++) {
                        for (int x = 0; x < in.sizeX; x++) {
                            if (minRad1(max, 1, x, y, z)) {
                                close.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr2.startAndJoin();
    max.closeImagePlus();
    close.setOffset(in);
    close.setScale(in);
    return close;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ThreadRunner(mcib3d.utils.ThreadRunner) ImageInt(mcib3d.image3d.ImageInt)

Example 14 with ImageInt

use of mcib3d.image3d.ImageInt 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)

Example 15 with ImageInt

use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.

the class IntImage3D method binaryReconstructByObjects.

public ImageInt binaryReconstructByObjects(ImageInt base) {
    // System.out.println("max "+this.getMaximum());
    Segment3DImage seg = new Segment3DImage(new ImageShort(this.getStack()), 1, 65535);
    seg.segment();
    ImageInt label = seg.getLabelledObjectsImage3D();
    boolean[] ok = new boolean[(int) label.getMax() + 1];
    for (int i = 0; i < ok.length; i++) {
        ok[i] = false;
    }
    if (label.getMax() > 0) {
        for (int k = 0; k < sizez; k++) {
            for (int j = 0; j < sizey; j++) {
                for (int i = 0; i < sizex; i++) {
                    if (base.getPixel(i, j, k) != 0) {
                        ok[label.getPixelInt(i, j, k)] = true;
                    }
                }
            }
        }
        for (int k = 0; k < sizez; k++) {
            for (int j = 0; j < sizey; j++) {
                for (int i = 0; i < sizex; i++) {
                    int pix = label.getPixelInt(i, j, k);
                    if (pix > 0) {
                        if (ok[pix]) {
                            label.setPixel(i, j, k, 255);
                        } else {
                            label.setPixel(i, j, k, 0);
                        }
                    }
                }
            }
        }
    }
    return label;
}
Also used : ImageShort(mcib3d.image3d.ImageShort) ImageInt(mcib3d.image3d.ImageInt) Segment3DImage(mcib3d.image3d.Segment3DImage)

Aggregations

ImageInt (mcib3d.image3d.ImageInt)24 ImageByte (mcib3d.image3d.ImageByte)13 ImageShort (mcib3d.image3d.ImageShort)4 ThreadRunner (mcib3d.utils.ThreadRunner)4 Random (java.util.Random)3 ArrayList (java.util.ArrayList)2 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)2 Point3D (mcib3d.geom.Point3D)2 Voxel3D (mcib3d.geom.Voxel3D)2 ImagePlus (ij.ImagePlus)1 Calibration (ij.measure.Calibration)1 ImageProcessor (ij.process.ImageProcessor)1 Volume (ij3d.Volume)1 List (java.util.List)1 ObjectCreator3D (mcib3d.geom.ObjectCreator3D)1 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)1 ImageFloat (mcib3d.image3d.ImageFloat)1 ImageHandler (mcib3d.image3d.ImageHandler)1 ImageLabeller (mcib3d.image3d.ImageLabeller)1 Segment3DImage (mcib3d.image3d.Segment3DImage)1