Search in sources :

Example 6 with ImageFloat

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

the class CannyEdge3D method computeGradX.

private void computeGradX() {
    double[] line;
    double[] res;
    CannyDeriche1D canny;
    // TODO MULTITHREAD
    grads[0] = new ImageFloat("EdgeX", input.sizeX, input.sizeY, input.sizeZ);
    for (int z = 0; z < input.sizeZ; z++) {
        IJ.showStatus("Edge X " + z + "/" + input.sizeZ);
        for (int y = 0; y < input.sizeY; y++) {
            line = input.getLineX(0, y, z, input.sizeX);
            canny = new CannyDeriche1D(line, alpha);
            res = canny.getCannyDeriche();
            grads[0].setLineX(0, y, z, res);
        }
    }
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 7 with ImageFloat

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

the class CannyEdge3D method computeEdge.

private void computeEdge() {
    if (grads == null) {
        computeGradient();
    }
    edge = new ImageFloat("Edge", input.sizeX, input.sizeY, input.sizeZ);
    for (int z = 0; z < input.sizeZ; z++) {
        IJ.showStatus("Edge " + z + "/" + input.sizeZ);
        for (int x = 0; x < input.sizeX; x++) {
            for (int y = 0; y < input.sizeY; y++) {
                float ex = grads[0].getPixel(x, y, z);
                float ey = grads[1].getPixel(x, y, z);
                float ez = grads[2].getPixel(x, y, z);
                float ee = (float) sqrt(ex * ex + ey * ey + ez * ez);
                edge.setPixel(x, y, z, ee);
            }
        }
    }
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 8 with ImageFloat

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

the class EdtFloatInv 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);
        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 9 with ImageFloat

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

the class EdtShortInv method run.

/**
 * @param imp
 * @param thresh
 * @param scaleXY
 * @param scaleZ
 * @return
 * @throws Exception
 */
public ImageFloat run(ImageShort imp, int 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;
    short[][] 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);
        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] & 0xffff) > 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 10 with ImageFloat

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

the class Watershed3DVoronoi method computeWatershed.

private void computeWatershed(boolean show) {
    if (EDTImage == null)
        computeEDT(show);
    log.log("Computing Watershed");
    ImageFloat EDTcopy = EDTImage.duplicate();
    double max = EDTcopy.getMax();
    EDTcopy.invert();
    EDTcopy.addValue((float) max + 1);
    Watershed3D water = new Watershed3D(EDTcopy, seeds, 0, 0);
    water.setLog(log);
    water.setLabelSeeds(labelSeeds);
    watershed = water.getWatershedImage3D();
    lines = water.getDamImage();
}
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