Search in sources :

Example 1 with ImageFloat

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

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

the class EDT_1D method process1D.

public ImageFloat process1D() {
    ImageFloat res = new ImageFloat("EDT_1D", input.sizeX, input.sizeY, input.sizeZ);
    for (int z = 0; z < input.sizeZ; z++) {
        for (int y = 0; y < input.sizeY; y++) {
            EDTAxisXPos(res, y, z);
            EDTAxisXNeg(res, y, z);
        }
    }
    return res;
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 3 with ImageFloat

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

the class EdtByte method run.

public ImageFloat run(ImageByte imp, int thresh, float scaleXY, float scaleZ, int nbCPUs) throws Exception {
    int sizeX = imp.sizeX;
    int sizeY = imp.sizeY;
    int sizeZ = imp.sizeZ;
    float scale = scaleZ / scaleXY;
    byte[][] data = imp.pixels;
    // Create 32 bit floating point stack for output, s.  Will also use it for g in Transformation 1.
    ImageStack sStack = new ImageStack(sizeX, sizeY);
    float[][] res = new float[sizeZ][];
    for (int k = 0; k < sizeZ; k++) {
        ImageProcessor ipk = new FloatProcessor(sizeX, sizeY);
        sStack.addSlice(null, ipk);
        res[k] = (float[]) ipk.getPixels();
    }
    float[] sk;
    // Transformation 1.  Use s to store g.
    Step1Thread[] s1t = new Step1Thread[nbCPUs];
    for (int thread = 0; thread < nbCPUs; thread++) {
        s1t[thread] = new Step1Thread(thread, nbCPUs, sizeX, sizeY, sizeZ, thresh, res, data, scale);
        s1t[thread].start();
    }
    try {
        for (int thread = 0; thread < nbCPUs; thread++) {
            s1t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 1 .");
    }
    // Transformation 2.  g (in s) -> h (in s)
    Step2Thread[] s2t = new Step2Thread[nbCPUs];
    for (int thread = 0; thread < nbCPUs; thread++) {
        s2t[thread] = new Step2Thread(thread, nbCPUs, sizeX, sizeY, sizeZ, res);
        s2t[thread].start();
    }
    try {
        for (int thread = 0; thread < nbCPUs; thread++) {
            s2t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 2 .");
    }
    // Transformation 3. h (in s) -> s
    if (imp.sizeZ > 1) {
        Step3Thread[] s3t = new Step3Thread[nbCPUs];
        for (int thread = 0; thread < nbCPUs; thread++) {
            s3t[thread] = new Step3Thread(thread, nbCPUs, sizeX, sizeY, sizeZ, res, data, thresh, scale);
            s3t[thread].start();
        }
        try {
            for (int thread = 0; thread < nbCPUs; thread++) {
                s3t[thread].join();
            }
        } catch (InterruptedException ie) {
            IJ.error("A thread was interrupted in step 3 .");
        }
    }
    // Find the largest distance for scaling
    // Also fill in the background values.
    float distMax = 0;
    int wh = sizeX * sizeY;
    float dist;
    for (int k = 0; k < sizeZ; k++) {
        sk = res[k];
        for (int ind = 0; ind < wh; ind++) {
            if (((data[k][ind] & 255) <= thresh)) {
                sk[ind] = 0;
            } else {
                dist = (float) Math.sqrt(sk[ind]) * scaleXY;
                sk[ind] = dist;
                distMax = (dist > distMax) ? dist : distMax;
            }
        }
    }
    ImageFloat map = (ImageFloat) ImageFloat.wrap(sStack);
    map.setScale(imp);
    map.setOffset(imp);
    map.setMinAndMax(0, distMax);
    return map;
}
Also used : ImageStack(ij.ImageStack) FloatProcessor(ij.process.FloatProcessor) ImageFloat(mcib3d.image3d.ImageFloat) ImageProcessor(ij.process.ImageProcessor)

Example 4 with ImageFloat

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

the class EdtFloat method run.

/**
 * @param imp
 * @param thresh
 * @param scaleXY
 * @param scaleZ
 * @return
 * @throws Exception
 */
public ImageFloat run(ImageFloat imp, float thresh, float scaleXY, float scaleZ, int nbCPUs) throws Exception {
    int w = imp.sizeX;
    int h = imp.sizeY;
    int d = imp.sizeZ;
    float scale = scaleZ / scaleXY;
    float[][] data = imp.pixels;
    // Create 32 bit floating point stack for output, s.  Will also use it for g in Transormation 1.
    ImageStack sStack = new ImageStack(w, h);
    float[][] s = new float[d][];
    for (int k = 0; k < d; k++) {
        ImageProcessor ipk = new FloatProcessor(w, h);
        sStack.addSlice(null, ipk);
        s[k] = (float[]) ipk.getPixels();
    }
    float[] sk;
    // Transformation 1.  Use s to store g.
    Step1Thread[] s1t = new Step1Thread[nbCPUs];
    for (int thread = 0; thread < nbCPUs; thread++) {
        s1t[thread] = new Step1Thread(thread, nbCPUs, w, h, d, thresh, s, data, scale);
        s1t[thread].start();
    }
    try {
        for (int thread = 0; thread < nbCPUs; thread++) {
            s1t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 1 .");
    }
    // Transformation 2.  g (in s) -> h (in s)
    Step2Thread[] s2t = new Step2Thread[nbCPUs];
    for (int thread = 0; thread < nbCPUs; thread++) {
        s2t[thread] = new Step2Thread(thread, nbCPUs, w, h, d, s);
        s2t[thread].start();
    }
    try {
        for (int thread = 0; thread < nbCPUs; thread++) {
            s2t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 2 .");
    }
    // Transformation 3. h (in s) -> s
    if (imp.sizeZ > 1) {
        Step3Thread[] s3t = new Step3Thread[nbCPUs];
        for (int thread = 0; thread < nbCPUs; thread++) {
            s3t[thread] = new Step3Thread(thread, nbCPUs, w, h, d, s, data, thresh, scale);
            s3t[thread].start();
        }
        try {
            for (int thread = 0; thread < nbCPUs; thread++) {
                s3t[thread].join();
            }
        } catch (InterruptedException ie) {
            IJ.error("A thread was interrupted in step 3 .");
        }
    }
    // Find the largest distance for scaling
    // Also fill in the background values.
    float distMax = 0;
    int wh = w * h;
    float dist;
    for (int k = 0; k < d; k++) {
        sk = s[k];
        for (int ind = 0; ind < wh; ind++) {
            if ((data[k][ind] <= thresh)) {
                sk[ind] = 0;
            } else {
                dist = (float) Math.sqrt(sk[ind]) * scaleXY;
                sk[ind] = dist;
                distMax = (dist > distMax) ? dist : distMax;
            }
        }
    }
    ImageFloat res = (ImageFloat) ImageFloat.wrap(sStack);
    res.setScale(imp);
    res.setOffset(imp);
    res.setMinAndMax(0, distMax);
    return res;
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 5 with ImageFloat

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

the class EdtShortLabel method run.

/**
 * @param imp
 * @param scaleXY
 * @param scaleZ
 * @return
 * @throws Exception
 */
public ImageFloat run(ImageShort imp, float scaleXY, float scaleZ, int nCPUs) throws Exception {
    int w = imp.sizeX;
    int h = imp.sizeY;
    int d = imp.sizeZ;
    float scale = scaleZ / scaleXY;
    short[][] data = imp.pixels;
    int nThreads = Math.max(nCPUs, 1);
    // Create 32 bit floating point stack for output, s.  Will also use it for g in Transormation 1.
    ImageFloat res = new ImageFloat("EDT Label", w, h, d);
    res.setScale(imp);
    float[][] s = res.pixels;
    float[] sk;
    // Transformation 1.  Use s to store g.
    Step1Thread[] s1t = new Step1Thread[nThreads];
    for (int thread = 0; thread < nThreads; thread++) {
        s1t[thread] = new Step1Thread(thread, nThreads, w, h, d, s, data, scale);
        s1t[thread].start();
    }
    try {
        for (int thread = 0; thread < nThreads; thread++) {
            s1t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 1 .");
    }
    // Transformation 2.  g (in s) -> h (in s)
    Step2Thread[] s2t = new Step2Thread[nThreads];
    for (int thread = 0; thread < nThreads; thread++) {
        s2t[thread] = new Step2Thread(thread, nThreads, w, h, d, s, data);
        s2t[thread].start();
    }
    try {
        for (int thread = 0; thread < nThreads; thread++) {
            s2t[thread].join();
        }
    } catch (InterruptedException ie) {
        IJ.error("A thread was interrupted in step 2 .");
    }
    // Transformation 3. h (in s) -> s
    if (imp.sizeZ > 1) {
        Step3Thread[] s3t = new Step3Thread[nThreads];
        for (int thread = 0; thread < nThreads; thread++) {
            s3t[thread] = new Step3Thread(thread, nThreads, w, h, d, s, data, scale);
            s3t[thread].start();
        }
        try {
            for (int thread = 0; thread < nThreads; thread++) {
                s3t[thread].join();
            }
        } catch (InterruptedException ie) {
            IJ.error("A thread was interrupted in step 3 .");
        }
    }
    // Find the largest distance for scaling
    // Also fill in the background values.
    float distMax = 0;
    int wh = w * h;
    float dist;
    for (int k = 0; k < d; k++) {
        sk = s[k];
        for (int ind = 0; ind < wh; ind++) {
            if (data[k][ind] == 0) {
                sk[ind] = 0;
            } else {
                dist = (float) Math.sqrt(sk[ind]) * scaleXY;
                sk[ind] = dist;
                distMax = (dist > distMax) ? dist : distMax;
            }
        }
    }
    return res;
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Aggregations

ImageFloat (mcib3d.image3d.ImageFloat)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ImageByte (mcib3d.image3d.ImageByte)3 ImageHandler (mcib3d.image3d.ImageHandler)3 Chrono (mcib3d.utils.Chrono)2 AbstractLog (mcib3d.utils.Logger.AbstractLog)2 ImageStack (ij.ImageStack)1 FloatProcessor (ij.process.FloatProcessor)1 ImageProcessor (ij.process.ImageProcessor)1 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)1 Point3D (mcib3d.geom.Point3D)1 Vector3D (mcib3d.geom.Vector3D)1 ImageInt (mcib3d.image3d.ImageInt)1 ImageShort (mcib3d.image3d.ImageShort)1