Search in sources :

Example 16 with ImageFloat

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

the class CannyEdge3D method computeGradY.

private void computeGradY() {
    double[] line;
    double[] res;
    CannyDeriche1D canny;
    // TODO MULTITHREAD
    grads[1] = new ImageFloat("EdgeY", input.sizeX, input.sizeY, input.sizeZ);
    for (int z = 0; z < input.sizeZ; z++) {
        IJ.showStatus("Edge Y " + z + "/" + input.sizeZ);
        for (int x = 0; x < input.sizeX; x++) {
            line = input.getLineY(x, 0, z, input.sizeY);
            canny = new CannyDeriche1D(line, alpha);
            res = canny.getCannyDeriche();
            grads[1].setLineY(x, 0, z, res);
        }
    }
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 17 with ImageFloat

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

the class CannyEdge3D method computeGradZ.

private void computeGradZ() {
    double[] line;
    double[] res;
    CannyDeriche1D canny;
    // TODO MULTITHREAD
    grads[2] = new ImageFloat("EdgeZ", input.sizeX, input.sizeY, input.sizeZ);
    for (int x = 0; x < input.sizeX; x++) {
        IJ.showStatus("Edge Z " + x + "/" + input.sizeX);
        for (int y = 0; y < input.sizeY; y++) {
            line = input.getLineZ(x, y, 0, input.sizeZ);
            canny = new CannyDeriche1D(line, alpha);
            res = canny.getCannyDeriche();
            grads[2].setLineZ(x, y, 0, res);
        }
    }
}
Also used : ImageFloat(mcib3d.image3d.ImageFloat)

Example 18 with ImageFloat

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

the class FastArithmetic3D method mathFloatImage.

public static ImageFloat mathFloatImage(ImageFloat stackorig, final ImageFloat stackother, int operation, final float par1, final float par2, int nbcpus, boolean showstatus, final AbstractLog log) {
    int nbToProcess = stackorig.sizeZ;
    // Timer
    final Chrono time = new Chrono(nbToProcess);
    time.start();
    final AbstractLog show = log;
    // get stack info
    final ImageFloat ima = stackorig;
    final ImageFloat res = (ImageFloat) ima.createSameDimensions();
    final ImageFloat out = res;
    final AtomicInteger ai = new AtomicInteger(0);
    final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
    final int fi = operation;
    final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
    Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
    show.log("Starting");
    for (int ithread = 0; ithread < threads.length; ithread++) {
        threads[ithread] = new Thread() {

            @Override
            public void run() {
                for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
                    ima.mathGeneric(stackother, res, dec * k, dec * (k + 1), fi, par1, par2, time, log);
                }
            }
        };
    }
    ThreadUtil.startAndJoin(threads);
    show.log("Finished");
    return res;
}
Also used : Chrono(mcib3d.utils.Chrono) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractLog(mcib3d.utils.Logger.AbstractLog) ImageFloat(mcib3d.image3d.ImageFloat)

Example 19 with ImageFloat

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

the class FastOperation3D method operationFloatImage.

public static ImageFloat operationFloatImage(ImageFloat stackorig, int operation, final float par1, final float par2, int nbcpus, boolean showstatus, final AbstractLog log) {
    int nbToProcess = stackorig.sizeZ;
    // Timer
    final Chrono time = new Chrono(nbToProcess);
    time.start();
    final AbstractLog show = log;
    // get stack info
    final ImageFloat ima = stackorig;
    final ImageFloat res = (ImageFloat) ima.createSameDimensions();
    final ImageFloat out = res;
    final AtomicInteger ai = new AtomicInteger(0);
    final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
    final int fi = operation;
    final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
    Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
    show.log("Starting");
    for (int ithread = 0; ithread < threads.length; ithread++) {
        threads[ithread] = new Thread(() -> {
            for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
                ima.operationGeneric(out, dec * k, dec * (k + 1), fi, par1, par2, time, log);
            }
        });
    }
    ThreadUtil.startAndJoin(threads);
    show.log("Finished");
    return out;
}
Also used : Chrono(mcib3d.utils.Chrono) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractLog(mcib3d.utils.Logger.AbstractLog) ImageFloat(mcib3d.image3d.ImageFloat)

Example 20 with ImageFloat

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

the class EdtByteInv method run.

/**
 * @param imp
 * @param thresh
 * @param scaleXY
 * @param scaleZ
 * @return
 * @throws Exception
 */
public ImageFloat run(ImageByte 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;
    byte[][] 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] & 255) > 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)

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