Search in sources :

Example 11 with ImageByte

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

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

the class BinaryMorpho method binaryErodeRad1.

private static ImageByte binaryErodeRad1(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();
    min.setScale(in);
    min.setOffset(in);
    return min;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ThreadRunner(mcib3d.utils.ThreadRunner)

Example 13 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) {
    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 14 with ImageByte

use of mcib3d.image3d.ImageByte 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 15 with ImageByte

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

the class IntImage3D method binaryReconstruct.

/**
 * Separate objects from an EDM image
 *
 * @return The segmented image with separated obects
 */
// public IntImage3D separateWatershed() {
// int val = this.getMaximum();
// IntImage3D seg = new IntImage3D(sizex, sizey, sizez);
// IntImage3D sep = new IntImage3D(sizex, sizey, sizez);
// IntImage3D neigh;
// int pix;
// int minVal;
// ArrayUtil tab;
// double val1;
// double val2;
// int c = 1;
// while (val >= 1) {
// // Find seeds
// for (int z = 0; z < sizez; z++) {
// for (int y = 0; y < sizey; y++) {
// for (int x = 0; x < sizex; x++) {
// pix = getPixel(x, y, z);
// if (pix == val) {
// tab = seg.getNeighborhood3x3x3(x, y, z);
// minVal = (int) tab.getMinimumAbove(0);
// if ((minVal == 0) && (isLocalMaximum(x, y, z, 2, 2, 2))) {
// seg.putPixel(x, y, z, c);
// seg.propagation(this, x, y, z, val, c);
// c++;
// }
// }
// }
// }
// }
// 
// //new ImagePlus("seg " + val, seg.getStack()).show();
// // Neighbor image
// int nb = 2;
// while (nb <= 2) {
// nb++;
// neigh = new IntImage3D(sizex, sizey, sizez);
// for (int z = 0; z < sizez; z++) {
// for (int y = 0; y < sizey; y++) {
// for (int x = 0; x < sizex; x++) {
// if (this.getPixel(x, y, z) > 0) {
// tab = seg.getNeighborhood3x3x3(x, y, z);
// if (!tab.hasOnlyValue(0)) {
// val1 = tab.getMinimumAbove(0);
// val2 = tab.getMinimumAbove(val1);
// if (val1 == val2) {
// neigh.putPixel(x, y, z, (int) val1);
// } else {
// sep.putPixel(x, y, z, 255);
// }
// }
// }
// }
// }
// }
// //new ImagePlus("neigh " + val, neigh.getStack()).show();
// seg = neigh;
// }
// val--;
// }
// return seg;
// }
/**
 * Description of the Method
 *
 * @param base Description of the Parameter
 * @return Description of the Return Value
 */
public ImageInt binaryReconstruct(ImageInt base) {
    int i;
    int j;
    int k;
    int val = 255;
    ImageInt res = new ImageByte("", sizex, sizey, sizez);
    // }
    return res;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) 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