Search in sources :

Example 6 with ImageByte

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

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

the class Watershed3DVoronoi method computeVoronoi.

private void computeVoronoi(boolean show) {
    if (watershed == null)
        computeWatershed(show);
    log.log("Computing Voronoi");
    ImageByte mask = EDTImage.threshold(radiusMax, true, true);
    voronoi = watershed.duplicate();
    voronoi.intersectMask(mask);
}
Also used : ImageByte(mcib3d.image3d.ImageByte)

Example 8 with ImageByte

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

the class Watershed3DVoronoi method getVoronoiLines.

public ImageInt getVoronoiLines(boolean show) {
    if (voronoi == null)
        computeVoronoi(show);
    log.log("Computing voronoi lines");
    ImageByte mask = EDTImage.threshold(radiusMax, true, true);
    voronoi = lines.duplicate();
    voronoi.intersectMask(mask);
    return voronoi;
}
Also used : ImageByte(mcib3d.image3d.ImageByte)

Example 9 with ImageByte

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

the class Viewer3D_Utils method computeMeshSurface.

public static List computeMeshSurface(Object3D object3D, boolean calibrated) {
    // IJ.showStatus("computing mesh");
    // use miniseg
    ImageInt miniseg = object3D.getLabelImage();
    ImageByte miniseg8 = ((ImageShort) (miniseg)).convertToByte(false);
    ImagePlus objectImage = miniseg8.getImagePlus();
    if (calibrated) {
        objectImage.setCalibration(getCalibration(object3D));
    }
    boolean[] bl = { true, true, true };
    Volume vol = new Volume(objectImage, bl);
    vol.setAverage(true);
    List l = MCCube.getTriangles(vol, 0);
    // needs to invert surface
    l = Object3DSurface.invertNormals(l);
    // translate object with units coordinates
    float tx, ty, tz;
    if (calibrated) {
        tx = (float) (miniseg.offsetX * object3D.getResXY());
        ty = (float) (miniseg.offsetY * object3D.getResXY());
        tz = (float) (miniseg.offsetZ * object3D.getResZ());
    } else {
        tx = (float) (miniseg.offsetX);
        ty = (float) (miniseg.offsetY);
        tz = (float) (miniseg.offsetZ);
    }
    l = Object3DSurface.translateTool(l, tx, ty, tz);
    return l;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ImageShort(mcib3d.image3d.ImageShort) Volume(ij3d.Volume) ImageInt(mcib3d.image3d.ImageInt) List(java.util.List) ImagePlus(ij.ImagePlus)

Example 10 with ImageByte

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

the class BinaryMorpho method binaryClose.

public static ImageByte binaryClose(ImageInt in, float radius, float radiusZ, int nbCPUs) {
    // use binary dilate
    ImageByte dilated = binaryDilate(in, radius, radiusZ, nbCPUs, true);
    ImageByte close = binaryErode(dilated, radius, radiusZ, nbCPUs);
    // crop image
    int ox = in.offsetX - dilated.offsetX;
    int oy = in.offsetY - dilated.offsetY;
    int oz = in.offsetZ - dilated.offsetZ;
    return close.crop3D("binaryClose", ox, ox + in.sizeX - 1, oy, oy + in.sizeY - 1, oz, oz + in.sizeZ - 1);
/*
        try {
            if (nbCPUs == 0) {
                nbCPUs = ThreadUtil.getNbCpus();
            }
            // test rad <=1
            /*if ((radius <= 1) && (radiusZ <= 1)) {
             return binaryCloseRad1(in, 1, nbCPUs);
             }*/
/*
            // FIXME thresholdings > strict
            int rad = (int) (radius + 1);
            int radZ = (int) (radiusZ + 1);
            int resize = 0; // FIXME useful ??
            ImageInt inResized = (ImageInt) in.resize(rad + resize, rad + resize, radZ + resize);
            //inResized.show("resize");
            ImageFloat edm = EDT.run(inResized, 0, 1, radius / radiusZ, true, nbCPUs);
            inResized.closeImagePlus();
            ImageByte inThresholded = edm.threshold(radius, true, false);
            edm.closeImagePlus();
            edm = EDT.run(inThresholded, 0, 1, radius / radiusZ, false, nbCPUs);
            //edm.show("edm");
            inThresholded.closeImagePlus();
            //ImageFloat edm2 = (ImageFloat) edm.resize(-rad+resize, -rad+resize, -radZ+resize);
            //edm.closeImagePlus();
            //edm = null;
            //System.gc();
            inThresholded = edm.threshold(radius, false, false);
            // inThresholded.show("bin");
            edm.closeImagePlus();
            edm = null;
            System.gc();
            inThresholded.offsetX = inResized.offsetX;
            inThresholded.offsetY = inResized.offsetY;
            inThresholded.offsetZ = inResized.offsetZ;
            inThresholded.setScale(in);
            return inThresholded;
        } catch (Exception e) {
            exceptionPrinter.print(e, null, true);
        }
        return null;
        */
}
Also used : ImageByte(mcib3d.image3d.ImageByte)

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