Search in sources :

Example 11 with Chrono

use of mcib3d.utils.Chrono in project mcib3d-core by mcib3d.

the class FastArithmetic3D method mathIntImage.

public static ImageInt mathIntImage(ImageInt stackorig, final ImageInt 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 ImageInt ima = stackorig;
    final ImageInt res = (ImageInt) ima.createSameDimensions();
    final ImageInt 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)

Example 12 with Chrono

use of mcib3d.utils.Chrono in project mcib3d-core by mcib3d.

the class FastFilters3D method filterIntImage.

public static ImageInt filterIntImage(ImageInt stackorig, int filter, float vx, float vy, float vz, int nbcpus, boolean showstatus, AbstractLog log) {
    int nbToProcess = stackorig.sizeZ;
    if ((filter == TOPHAT) || (filter == CLOSEGRAY) || (filter == OPENGRAY))
        nbToProcess *= 2;
    // Timer
    final Chrono time = new Chrono(nbToProcess);
    time.start();
    final AbstractLog show = log;
    // get stack info
    final float voisx = vx;
    final float voisy = vy;
    final float voisz = vz;
    final ImageInt ima = stackorig;
    ImageInt res = (ImageInt) ima.createSameDimensions();
    if ((filter == MEAN) || (filter == MEDIAN) || (filter == MIN) || (filter == MAX) || (filter == MAXLOCAL) || (filter == TOPHAT) || (filter == VARIANCE) || (filter == CLOSEGRAY) || (filter == OPENGRAY)) {
        // PARALLEL
        final ImageInt out = res;
        final AtomicInteger ai = new AtomicInteger(0);
        final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
        int fi = filter;
        if ((fi == TOPHAT) || (fi == OPENGRAY)) {
            fi = MIN;
        }
        if (fi == CLOSEGRAY) {
            fi = MAX;
        }
        final int f = fi;
        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.filterGeneric(out, voisx, voisy, voisz, dec * k, dec * (k + 1), f, time, show);
                    }
                }
            };
        }
        ThreadUtil.startAndJoin(threads);
        show.log("Finished");
        // TOPHAT MAX
        if ((filter == TOPHAT) || (filter == OPENGRAY)) {
            final int f2 = MAX;
            final ImageInt res2 = (ImageInt) ima.createSameDimensions();
            ai.set(0);
            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()) {
                            out.filterGeneric(res2, voisx, voisy, voisz, dec * k, dec * (k + 1), f2, time, show);
                        }
                    }
                };
            }
            ThreadUtil.startAndJoin(threads);
            // TOPHAT DIFFERENCE
            if (filter == TOPHAT) {
                res = ima.subtractImageInt(res2);
            } else {
                res = res2;
            }
        }
        // CLOSING 2nd Step
        if (filter == CLOSEGRAY) {
            final int f2 = MIN;
            final ImageInt res2 = (ImageInt) ima.createSameDimensions();
            ai.set(0);
            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()) {
                            out.filterGeneric(res2, voisx, voisy, voisz, dec * k, dec * (k + 1), f2, time, show);
                        }
                    }
                };
            }
            ThreadUtil.startAndJoin(threads);
            res = res2;
        }
    } else if (filter == SOBEL) {
        res = ima.sobelFilter();
    } else if (filter == ADAPTIVE) {
        // res = ima.adaptiveFilter(voisx, voisy, voisz, nbcpus);
        // PARALLEL
        final ImageInt out = res;
        final AtomicInteger ai = new AtomicInteger(0);
        final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
        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.adaptiveFilter(out, voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
                    }
                }
            };
        }
        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)

Example 13 with Chrono

use of mcib3d.utils.Chrono in project mcib3d-core by mcib3d.

the class FastFilters3D method filterIntImage.

public static ImageInt filterIntImage(ImageInt stackorig, int filter, Object3DVoxels obj, int nbcpus, boolean showstatus) {
    int nbToProcess = stackorig.sizeZ;
    if ((filter == TOPHAT) || (filter == CLOSEGRAY) || (filter == OPENGRAY))
        nbToProcess *= 2;
    // Timer
    final Chrono time = new Chrono(nbToProcess);
    time.start();
    final AbstractLog show = new IJStatus();
    final Object3DVoxels object = obj;
    // IJ.log("Using java filtering " + voisx + " " + voisy + " " + voisz + " " + filter + " " + nbcpus);
    final ImageInt ima = stackorig;
    ImageInt res = (ImageInt) ima.createSameDimensions();
    if ((filter == MEAN) || (filter == MEDIAN) || (filter == MIN) || (filter == MAX) || (filter == MAXLOCAL) || (filter == TOPHAT) || (filter == VARIANCE) || (filter == CLOSEGRAY) || (filter == OPENGRAY)) {
        // PARALLEL
        final ImageInt out = res;
        final AtomicInteger ai = new AtomicInteger(0);
        final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
        int fi = filter;
        if ((fi == TOPHAT) || (fi == OPENGRAY)) {
            fi = MIN;
        }
        if (fi == CLOSEGRAY) {
            fi = MAX;
        }
        final int f = fi;
        final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
        Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
        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.filterGeneric(out, object, dec * k, dec * (k + 1), f, time, show);
                    }
                }
            };
        }
        ThreadUtil.startAndJoin(threads);
        // TOPHAT MAX
        if ((filter == TOPHAT) || (filter == OPENGRAY)) {
            final int f2 = MAX;
            final ImageInt res2 = (ImageInt) ima.createSameDimensions();
            ai.set(0);
            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()) {
                            out.filterGeneric(res2, object, dec * k, dec * (k + 1), f2, time, show);
                        }
                    }
                };
            }
            ThreadUtil.startAndJoin(threads);
            // TOPHAT DIFFERENCE
            if (filter == TOPHAT) {
                res = ima.substractImage(res2);
            } else {
                res = res2;
            }
        }
        // CLOSING 2nd Step
        if (filter == CLOSEGRAY) {
            final int f2 = MIN;
            final ImageInt res2 = (ImageInt) ima.createSameDimensions();
            ai.set(0);
            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()) {
                            out.filterGeneric(res2, object, dec * k, dec * (k + 1), f2, time, show);
                        }
                    }
                };
            }
            ThreadUtil.startAndJoin(threads);
            res = res2;
        }
    } else if (filter == SOBEL) {
        res = ima.sobelFilter();
    } else if (filter == ADAPTIVE) {
    // res = ima.adaptiveFilter(voisx, voisy, voisz, nbcpus);
    }
    return res;
}
Also used : Chrono(mcib3d.utils.Chrono) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IJStatus(mcib3d.utils.Logger.IJStatus) AbstractLog(mcib3d.utils.Logger.AbstractLog) Object3DVoxels(mcib3d.geom.Object3DVoxels)

Example 14 with Chrono

use of mcib3d.utils.Chrono in project mcib3d-core by mcib3d.

the class FHTImage3D method fill3D.

/**
 * Fill 3D Reconstruction using central section theorem
 *
 * @param proj Array of FFT of the projections
 * @param W    Orientations of the images
 */
public void fill3D(FHTImage3D[] proj, Vector3D[] W) {
    if (!frequencyDomain) {
        return;
    }
    Vector3D Y = new Vector3D(0, 1, 0);
    int sizexy = sizex * sizey;
    double ox = sizex / 2;
    double oy = sizey / 2;
    double oz = sizez / 2;
    double x0;
    double y0;
    double z0;
    double xc0;
    double yc0;
    double zc0;
    int xx0;
    int yy0;
    int nbproj = proj.length;
    double[] a11 = new double[nbproj];
    double[] a12 = new double[nbproj];
    double[] a21 = new double[nbproj];
    double[] a22 = new double[nbproj];
    double[] a31 = new double[nbproj];
    double[] a32 = new double[nbproj];
    double[] at11 = new double[nbproj];
    double[] at12 = new double[nbproj];
    double[] at13 = new double[nbproj];
    double[] at21 = new double[nbproj];
    double[] at22 = new double[nbproj];
    double[] at23 = new double[nbproj];
    Vector3D U;
    Vector3D V;
    double RP0;
    double XX0;
    double XX1;
    double XX2;
    double RP1;
    for (int p = 0; p < nbproj; p++) {
        U = Y.crossProduct(W[p]);
        V = W[p].crossProduct(U);
        U.normalize();
        V.normalize();
        double ux = U.getX();
        double uy = U.getY();
        double uz = U.getZ();
        double vx = V.getX();
        double vy = V.getY();
        double vz = V.getZ();
        double wx = W[p].getX();
        double wy = W[p].getY();
        double wz = W[p].getZ();
        // A = new Matrix(3, 3);
        // A.set(0, 0, ux);
        // A.set(0, 1, vx);
        // A.set(0, 2, wx);
        // A.set(1, 0, uy);
        // A.set(1, 1, vy);
        // A.set(1, 2, wy);
        // A.set(2, 0, uz);
        // A.set(2, 1, vz);
        // A.set(2, 2, wz);
        a11[p] = ux;
        a12[p] = vx;
        a21[p] = uy;
        a22[p] = vy;
        a31[p] = uz;
        a32[p] = vz;
        // AT = A.inverse();
        // at11[p] = AT.get(0, 0);
        // at12[p] = AT.get(0, 1);
        // at13[p] = AT.get(0, 2);
        // at21[p] = AT.get(1, 0);
        // at22[p] = AT.get(1, 1);
        // at23[p] = AT.get(1, 2);
        at11[p] = ux;
        at12[p] = uy;
        at13[p] = uz;
        at21[p] = vx;
        at22[p] = vy;
        at23[p] = vz;
    }
    double dist;
    double distmin;
    int projmin;
    Chrono time = new Chrono(sizex);
    time.start();
    for (int x = 0; x < sizex; x++) {
        for (int y = 0; y < sizey; y++) {
            for (int z = 0; z < sizez; z++) {
                x0 = x - ox;
                y0 = y - oy;
                z0 = z - oz;
                distmin = 1.0;
                projmin = -1;
                for (int p = 0; p < nbproj; p++) {
                    RP0 = at11[p] * x0 + at12[p] * y0 + at13[p] * z0;
                    RP1 = at21[p] * x0 + at22[p] * y0 + at23[p] * z0;
                    xx0 = (int) Math.round(RP0);
                    yy0 = (int) Math.round(RP1);
                    XX0 = a11[p] * xx0 + a12[p] * yy0;
                    XX1 = a21[p] * xx0 + a22[p] * yy0;
                    XX2 = a31[p] * xx0 + a32[p] * yy0;
                    xc0 = XX0 + ox;
                    yc0 = XX1 + oy;
                    zc0 = XX2 + oz;
                    dist = (x - xc0) * (x - xc0) + (y - yc0) * (y - yc0) + (z - zc0) * (z - zc0);
                    if (dist <= distmin) {
                        distmin = dist;
                        projmin = p;
                    }
                }
                // index = 0;
                if (projmin != -1) {
                    for (int k = -1; k <= 1; k++) {
                        for (int l = -1; l <= 1; l++) {
                            RP0 = at11[projmin] * x0 + at12[projmin] * y0 + at13[projmin] * z0;
                            RP1 = at21[projmin] * x0 + at22[projmin] * y0 + at23[projmin] * z0;
                            xx0 = (int) Math.round(RP0 + k);
                            yy0 = (int) Math.round(RP1 + l);
                            XX0 = a11[projmin] * xx0 + a12[projmin] * yy0;
                            XX1 = a21[projmin] * xx0 + a22[projmin] * yy0;
                            XX2 = a31[projmin] * xx0 + a32[projmin] * yy0;
                            xc0 = XX0 + ox;
                            yc0 = XX1 + oy;
                            zc0 = XX2 + oz;
                            // ll[index] = W[projmin].intersection_unit_cube(x, y, z, xc0, yc0, zc0);
                            // real = proj[projmin].getPixelReal((int) (xx0 + ox), (int) (yy0 + oy), 0);
                            // imag = proj[projmin].getPixelImag((int) (xx0 + ox), (int) (yy0 + oy), 0);
                            // this.putPixel(x, y, z, getPixelReal(x, y, z) + (float) real, getPixelImag(x, y, z) + (float) imag);
                            xx0 += ox;
                            yy0 += oy;
                            // }
                            if (xx0 > 0 && xx0 < sizex && yy0 > 0 && yy0 < sizey) {
                                int fhtcoord = (int) (xx0 + yy0 * sizex);
                                putPixel(x, y, z, getPixel(x, y, z) + proj[projmin].getPixel(xx0, yy0, 0));
                            }
                        // index++;
                        }
                    }
                }
            }
        }
        time.stop();
        System.out.print("\r                                                                 \r" + (100 * (x + 1) / sizex) + "% \t" + time.delayString() + "\t (" + time.remainString(x + 1) + ")           ");
    }
/*
         *  /////////////////////////////////////////////////////
         *  int nbproj = proj.length;
         *  Matrix[] M = new Matrix[nbproj];
         *  Matrix MM;
         *  Vector3D U;
         *  Vector3D V;
         *  /Vector3D X = new Vector3D(0, 0, 1);
         *  Vector3D Y = new Vector3D(0, 1, 0);
         *  Matrix B;
         *  Matrix res;
         *  double[] b = new double[6];
         *  double dist;
         *  int projmin;
         *  double amin;
         *  double bmin;
         *  double distmin;
         *  float real;
         *  float imag;
         *  float coeff;
         *  double alpha;
         *  double beta;
         *  double ux[] = new double[nbproj];
         *  double uy[] = new double[nbproj];
         *  double uz[] = new double[nbproj];
         *  double vx[] = new double[nbproj];
         *  double vy[] = new double[nbproj];
         *  double vz[] = new double[nbproj];
         *  double ox = 0;
         *  double oy = 0;
         *  double oz = 0;
         *  double wx[] = new double[nbproj];
         *  double wy[] = new double[nbproj];
         *  double wz[] = new double[nbproj];
         *  double ww[] = new double[nbproj];
         *  for (int p = 0; p < nbproj; p++) {
         *  U = Y.crossProduct(W[p]);
         *  V = U.crossProduct(W[p]);
         *  U.normalize();
         *  V.normalize();
         *  ux[p] = U.getX();
         *  uy[p] = U.getY();
         *  uz[p] = U.getZ();
         *  vx[p] = V.getX();
         *  vy[p] = V.getY();
         *  vz[p] = V.getZ();
         *  ox = getSizex() / 2;
         *  oy = getSizey() / 2;
         *  oz = getSizez() / 2;
         *  wx[p] = W[p].getX();
         *  wy[p] = W[p].getY();
         *  wz[p] = W[p].getZ();
         *  ww[p] = wx[p] * wx[p] + wy[p] * wy[p] + wz[p] * wz[p];
         *  }
         *  int sx = getSizex();
         *  int sy = getSizey();
         *  int sz = getSizez();
         *  double px;
         *  double py;
         *  double pz;
         *  double lambda;
         *  for (int x = 0; x < sx; x++) {
         *  for (int y = 0; y < sy; y++) {
         *  for (int z = 0; z < sz; z++) {
         *  / parcours des projections
         *  distmin = 1.0;
         *  projmin = -1;
         *  coeff = 0;
         *  amin = 0;
         *  bmin = 0;
         *  real = 0;
         *  imag = 0;
         *  double xxmin = 0;
         *  double yymin = 0;
         *  for (int p = 0; p < nbproj; p++) {
         *  / resolution directe
         *  lambda = (wx[p] * (ox - x) + wy[p] * (oy - y) + wz[p] * (oz - z)) / ww[p];
         *  px = x + lambda * wx[p];
         *  py = y + lambda * wy[p];
         *  pz = z + lambda * wz[p];
         *  alpha = (px - ox) * ux[p] + (py - oy) * uy[p] + (pz - oz) * uz[p];
         *  beta = (px - ox) * vx[p] + (py - oy) * vy[p] + (pz - oz) * vz[p];
         *  double xx = (alpha + sx / 2);
         *  double yy = (sy / 2 - beta);
         *  dist = Math.abs(lambda);
         *  if (dist < distmin) {
         *  distmin = dist;
         *  projmin = p;
         *  xxmin = xx;
         *  yymin = yy;
         *  }
         *  }
         *  if (projmin != -1) {
         *  real = proj[projmin].getInterpolatedPixelReal((float) xxmin, (float) yymin, 0);
         *  imag = proj[projmin].getInterpolatedPixelImag((float) xxmin, (float) yymin, 0);
         *  this.putPixel(x, y, z, real, imag);
         *  }
         *  }
         *  }
         *  }
         */
}
Also used : Chrono(mcib3d.utils.Chrono) Vector3D(mcib3d.geom.Vector3D)

Aggregations

Chrono (mcib3d.utils.Chrono)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 AbstractLog (mcib3d.utils.Logger.AbstractLog)9 IJStatus (mcib3d.utils.Logger.IJStatus)7 ImageProcessor (ij.process.ImageProcessor)3 ArrayList (java.util.ArrayList)3 Object3DVoxels (mcib3d.geom.Object3DVoxels)2 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)2 Vector3D (mcib3d.geom.Vector3D)1 Voxel3D (mcib3d.geom.Voxel3D)1 FHTImage3D (mcib3d.image3d.legacy.FHTImage3D)1 IJLog (mcib3d.utils.Logger.IJLog)1