Search in sources :

Example 16 with ImageByte

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

the class BinaryMorpho method binaryErode.

public static ImageByte binaryErode(ImageInt in, float radius, float radiusZ, int nbCPUs) {
    try {
        if (nbCPUs == 0) {
            nbCPUs = ThreadUtil.getNbCpus();
        }
        // test rad <=1
        /*if ((radius <= 1) && (radiusZ <= 1)) {
             return binaryErodeRad1(in, 1, nbCPUs);
             }*/
        ImageFloat edm = EDT.run(in, 0, 1, radius / radiusZ, false, nbCPUs);
        ImageByte temp = edm.threshold(radius, false, true);
        edm.flush();
        edm = null;
        temp.setOffset(in);
        temp.setScale(in);
        return temp;
    } catch (Exception e) {
        exceptionPrinter.print(e, null, true);
    }
    return null;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageFloat(mcib3d.image3d.ImageFloat)

Example 17 with ImageByte

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

the class BinaryMorpho method binaryDilateMultilabel.

public static ImageInt binaryDilateMultilabel(ImageInt in, float radiusXY, float radiusZ, int nbCPUs) {
    // IJ.log("Binary multi dilate");
    ImageByte[] ihs = in.crop3DBinary();
    if (ihs != null) {
        // ij.IJ.log("BinaryClose multilabel nb :"+ihs.length);
        // ihs[0].show("crop binary 0");
        int end = ihs.length;
        for (int idx = 0; idx < end; idx++) {
            if (radiusXY < 1 && radiusZ < 1) {
                ihs[idx] = binaryDilateRad1(ihs[idx], 1, nbCPUs);
            } else if (radiusXY < 2 && radiusZ < 2) {
                ihs[idx] = binaryDilateRad1diag(ihs[idx], 1, nbCPUs);
            } else {
                ihs[idx] = binaryDilate(ihs[idx], radiusXY, 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 18 with ImageByte

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

the class BinaryMorpho method binaryOpen.

public static ImageByte binaryOpen(ImageInt in, float radius, float radiusZ, int nbCPUs) {
    try {
        if (nbCPUs == 0) {
            nbCPUs = ThreadUtil.getNbCpus();
        }
        // test rad <=1
        /*if ((radius <= 1) && (radiusZ <= 1)) {
             return binaryOpenRad1(in, 1, nbCPUs);
             }*/
        ImageFloat edm = EDT.run(in, 0, 1, radius / radiusZ, false, nbCPUs);
        ImageByte temp = edm.threshold(radius, false, true);
        edm.closeImagePlus();
        edm = EDT.run(temp, 0, 1, radius / radiusZ, true, nbCPUs);
        temp.closeImagePlus();
        temp = edm.threshold(radius, true, false);
        edm.closeImagePlus();
        edm = null;
        System.gc();
        temp.setOffset(in);
        temp.setScale(in);
        return temp;
    } catch (Exception e) {
        exceptionPrinter.print(e, null, true);
    }
    return null;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageFloat(mcib3d.image3d.ImageFloat)

Example 19 with ImageByte

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

the class BinaryMorpho method binaryOpenRad1.

private static ImageByte binaryOpenRad1(final ImageInt in, final float thld, int nbCPUs) {
    if (nbCPUs == 0) {
        nbCPUs = ThreadUtil.getNbCpus();
    }
    final ImageByte min = new ImageByte("min", in.sizeX, in.sizeY, in.sizeZ);
    final ThreadRunner tr = new ThreadRunner(0, in.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 < in.sizeY; y++) {
                        for (int x = 0; x < in.sizeX; x++) {
                            if (minRad1(in, thld, x, y, z)) {
                                min.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr.startAndJoin();
    final ImageByte open = new ImageByte(in.getTitle() + "::open", in.sizeX, in.sizeY, in.sizeZ);
    final ThreadRunner tr2 = new ThreadRunner(0, in.sizeZ, nbCPUs);
    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 (maxRad1(min, 1, x, y, z)) {
                                open.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr2.startAndJoin();
    min.closeImagePlus();
    open.setScale(in);
    open.setOffset(in);
    return open;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ThreadRunner(mcib3d.utils.ThreadRunner)

Example 20 with ImageByte

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

the class BinaryMorpho method binaryDilateRad1.

private static ImageByte binaryDilateRad1(final ImageInt in_, final float thld, int nbCPUs) {
    if (nbCPUs == 0) {
        nbCPUs = ThreadUtil.getNbCpus();
    }
    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, in.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 < in.sizeY; y++) {
                        for (int x = 0; x < in.sizeX; x++) {
                            if (maxRad1(in, thld, x, y, z)) {
                                max.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr.startAndJoin();
    max.setScale(in);
    max.setOffset(in);
    return max;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ThreadRunner(mcib3d.utils.ThreadRunner) ImageInt(mcib3d.image3d.ImageInt)

Aggregations

ImageByte (mcib3d.image3d.ImageByte)22 ImageInt (mcib3d.image3d.ImageInt)13 ThreadRunner (mcib3d.utils.ThreadRunner)6 ImageFloat (mcib3d.image3d.ImageFloat)3 ImagePlus (ij.ImagePlus)1 Volume (ij3d.Volume)1 List (java.util.List)1 ImageShort (mcib3d.image3d.ImageShort)1