Search in sources :

Example 1 with ImageInt

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

the class BinaryMorpho method binaryDilate.

// if no resize of the image, object at the border may be truncated
public static ImageByte binaryDilate(ImageInt in, float radius, float radiusZ, int nbCPUs, boolean enlarge) {
    try {
        if (nbCPUs == 0) {
            nbCPUs = ThreadUtil.getNbCpus();
        }
        ImageInt resize = in;
        // resize
        int reX = (int) (radius + 1);
        int reY = (int) (radius + 1);
        int reZ = (int) (radiusZ + 1);
        if (enlarge)
            resize = (ImageInt) in.enlarge(reX, reY, reZ);
        ImageFloat edm = EDT.run(resize, 0, 1, radius / radiusZ, true, nbCPUs);
        // edm.duplicate().show("edm");
        ImageByte temp = edm.threshold(radius, true, false);
        // temp.show("thres");
        edm.flush();
        edm = null;
        if (enlarge)
            temp.setOffset(in.offsetX - reX, in.offsetY - reY, in.offsetZ - reZ);
        else
            temp.setOffset(in);
        temp.setScale(in);
        return temp;
    } catch (Exception e) {
        exceptionPrinter.print(e, null, true);
    }
    return null;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageInt(mcib3d.image3d.ImageInt) ImageFloat(mcib3d.image3d.ImageFloat)

Example 2 with ImageInt

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

the class BinaryMorpho method binaryCloseMultilabel.

public static ImageInt binaryCloseMultilabel(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++) {
            if (radiusXY[idx] <= 1 && radiusZ[idx] <= 1) {
                ihs[idx] = BinaryMorpho.binaryCloseRad1(ihs[idx], 1, nbCPUs);
            } else {
                ihs[idx] = binaryClose(ihs[idx], radiusXY[idx], radiusZ[idx], nbCPUs);
            }
            ihs[idx] = binaryClose(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 3 with ImageInt

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

the class BinaryMorpho method binaryDilate2D.

public static ImageByte binaryDilate2D(ImageByte in, float radius, boolean enlarge) {
    ImageInt resize = in;
    // resize
    int reX = (int) (radius + 1);
    int reY = (int) (radius + 1);
    int reZ = 0;
    if (enlarge)
        resize = (ImageInt) in.enlarge(reX, reY, reZ);
    ImageByte temp = (ImageByte) FastFilters3D.filterIntImage(resize, FastFilters3D.MAX, radius, radius, 0, 1, false);
    temp.setScale(in);
    if (enlarge)
        temp.setOffset(in.offsetX - reX, in.offsetY - reY, in.offsetZ - reZ);
    else
        temp.setOffset(in);
    return temp;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageInt(mcib3d.image3d.ImageInt)

Example 4 with ImageInt

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

the class BinaryMorpho method binaryCloseRad1diag.

private static ImageByte binaryCloseRad1diag(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 (maxRad15(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() {

            @Override
            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 (minRad15(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 5 with ImageInt

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

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