Search in sources :

Example 1 with Vector3D

use of mcib3d.geom.Vector3D in project mcib3d-core by mcib3d.

the class RealImage3D method projectionInterpolated.

/**
 * Projection by interpolation
 *
 * @param W Direction of the projection
 * @param moy Mean projection or sum
 * @return Projected image
 */
public FloatProcessor projectionInterpolated(Vector3D W, boolean moy) {
    FloatProcessor[] res = new FloatProcessor[2];
    res[0] = new FloatProcessor(sizex, sizey);
    res[1] = new FloatProcessor(sizex, sizey);
    FloatProcessor resfinal = new FloatProcessor(sizex, sizey);
    Vector3D Y = new Vector3D(0, 1, 0);
    Vector3D U = Y.crossProduct(W);
    Vector3D V = U.crossProduct(W);
    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 pix;
    double alpha;
    double beta;
    double lambda;
    double px;
    double py;
    double pz;
    double ox = sizex / 2;
    double oy = sizey / 2;
    double oz = sizez / 2;
    double wx = W.getX();
    double wy = W.getY();
    double wz = W.getZ();
    double ww = wx * wx + wy * wy + wz * wz;
    double defaultValue = 0;
    int x0;
    int y0;
    double dx;
    double dy;
    double pix01;
    double pix02;
    double pix03;
    double pix04;
    double pix11;
    double pix12;
    double pix13;
    double pix14;
    for (int x = 0; x < sizex; x++) {
        for (int y = 0; y < sizey; y++) {
            for (int z = 0; z < sizez; z++) {
                // resolution directe
                lambda = (wx * (ox - x) + wy * (oy - y) + wz * (oz - z)) / ww;
                px = x + lambda * wx;
                py = y + lambda * wy;
                pz = z + lambda * wz;
                alpha = (px - ox) * ux + (py - oy) * uy + (pz - oz) * uz;
                beta = (px - ox) * vx + (py - oy) * vy + (pz - oz) * vz;
                double xx = ox + (alpha);
                double yy = oy - (beta);
                // interpolation inverse
                x0 = (int) (xx);
                y0 = (int) (yy);
                dx = xx - x0;
                dy = yy - y0;
                pix = this.getPixel(x, y, z);
                // recuperer les valeurs
                pix01 = res[0].getPixelValue(x0, y0);
                pix02 = res[0].getPixelValue(x0 + 1, y0);
                pix03 = res[0].getPixelValue(x0, y0 + 1);
                pix04 = res[0].getPixelValue(x0 + 1, y0 + 1);
                pix11 = res[1].getPixelValue(x0, y0);
                pix12 = res[1].getPixelValue(x0 + 1, y0);
                pix13 = res[1].getPixelValue(x0, y0 + 1);
                pix14 = res[1].getPixelValue(x0 + 1, y0 + 1);
                // coeff interpolation image 0
                res[0].putPixelValue(x0, y0, pix01 + (1 - dy) * (1 - dx));
                res[0].putPixelValue(x0 + 1, y0, pix02 + (1 - dy) * dx);
                res[0].putPixelValue(x0, y0 + 1, pix03 + dy * (1 - dx));
                res[0].putPixelValue(x0 + 1, y0 + 1, pix04 + dy * dx);
                // pix * coeff image 1
                res[1].putPixelValue(x0, y0, pix11 + (1 - dy) * (1 - dx) * pix);
                res[1].putPixelValue(x0 + 1, y0, pix12 + (1 - dy) * dx * pix);
                res[1].putPixelValue(x0, y0 + 1, pix13 + dy * (1 - dx) * pix);
                res[1].putPixelValue(x0 + 1, y0 + 1, pix14 + dy * dx * pix);
            }
        }
    }
    double res0;
    for (int x = 0; x < sizex; x++) {
        for (int y = 0; y < sizey; y++) {
            res0 = res[0].getPixelValue(x, y);
            if (res0 == 0) {
                resfinal.putPixelValue(x, y, 0);
            } else {
                if (moy) {
                    resfinal.putPixelValue(x, y, (double) (res[1].getPixelValue(x, y) / res0));
                } else {
                    resfinal.putPixelValue(x, y, (double) (res[1].getPixelValue(x, y)));
                }
            }
        }
    }
    return resfinal;
}
Also used : Vector3D(mcib3d.geom.Vector3D)

Example 2 with Vector3D

use of mcib3d.geom.Vector3D in project mcib3d-core by mcib3d.

the class RealImage3D method project.

/**
 * Description of the Method
 *
 * @param V Description of the Parameter
 * @param C Description of the Parameter
 * @param moy Description of the Parameter
 * @return Description of the Return Value
 */
public RealImage3D project(Vector3D V, Vector3D C, boolean moy) {
    int s = Math.max(sizex, Math.max(sizey, sizez));
    RealImage3D I = new RealImage3D(s, s, 1);
    Vector3D X = new Vector3D(0, 0, 1);
    Vector3D Y = new Vector3D(0, 1, 0);
    Vector3D XX = Y.crossProduct(V);
    Vector3D YY = XX.crossProduct(V);
    XX.normalize();
    YY.normalize();
    float xx = (float) XX.getX();
    float xy = (float) XX.getY();
    float xz = (float) XX.getZ();
    float yx = (float) YY.getX();
    float yy = (float) YY.getY();
    float yz = (float) YY.getZ();
    int sx = I.getSizex();
    int sy = I.getSizey();
    float cx = (float) C.getX();
    float cy = (float) C.getY();
    float cz = (float) C.getZ();
    float vx = (float) V.getX();
    float vy = (float) V.getY();
    float vz = (float) V.getZ();
    int vsx = this.getSizex();
    int vsy = this.getSizey();
    int vsz = this.getSizez();
    float ii;
    float jj;
    // increment de boucle sur l'image
    float k;
    int nb;
    float pix;
    float pixI;
    float vvx;
    float vvy;
    float vvz;
    boolean d1;
    boolean d2;
    for (int i = 0; i < sx; i++) {
        for (int j = 0; j < sy; j++) {
            ii = i - sx / 2;
            jj = -j + sy / 2;
            k = 0;
            nb = 0;
            pix = 0;
            d1 = true;
            d2 = true;
            while (d1 || d2) {
                vvx = (cx + ii * xx + jj * yx + k * vx);
                vvy = (cy + ii * xy + jj * yy + k * vy);
                vvz = (cz + ii * xz + jj * yz + k * vz);
                if (d1) {
                    if ((vvx < 0) || (vvx >= vsx) || (vvy < 0) || (vvy >= vsy) || (vvz < 0) || (vvz >= vsz)) {
                        d1 = false;
                    } else {
                        pix += this.getPixel(vvx, vvy, vvz);
                        nb++;
                    }
                }
                vvx = (cx + ii * xx + jj * yx - k * vx);
                vvy = (cy + ii * xy + jj * yy - k * vy);
                vvz = (cz + ii * xz + jj * yz - k * vz);
                if (d2) {
                    if ((vvx < 0) || (vvx >= vsx) || (vvy < 0) || (vvy >= vsy) || (vvz < 0) || (vvz >= vsz)) {
                        d2 = false;
                    } else {
                        pix += this.getPixel(vvx, vvy, vvz);
                        nb++;
                    }
                }
                k += 0.5;
            }
            if (moy) {
                if (nb > 0) {
                    I.putPixel(i, j, 0, pix / nb);
                } else {
                    I.putPixel(i, j, 0, 0);
                }
            } else {
                I.putPixel(i, j, 0, pix);
            }
        }
    }
    return I;
}
Also used : Vector3D(mcib3d.geom.Vector3D)

Example 3 with Vector3D

use of mcib3d.geom.Vector3D in project mcib3d-core by mcib3d.

the class RealImage3D method projection.

/**
 * Description of the Method
 *
 * @param V Description of the Parameter
 * @param C Description of the Parameter
 * @param moy Description of the Parameter
 * @return Description of the Return Value
 */
public FloatProcessor projection(Vector3D V, Vector3D C, boolean moy) {
    int s = Math.max(sizex, Math.max(sizey, sizez));
    FloatProcessor I = new FloatProcessor(s, s);
    int sx = I.getWidth();
    int sy = I.getHeight();
    Vector3D X = new Vector3D(0, 0, 1);
    Vector3D Y = new Vector3D(0, 1, 0);
    Vector3D XX = Y.crossProduct(V);
    Vector3D YY = XX.crossProduct(V);
    XX.normalize();
    YY.normalize();
    float xx = (float) XX.getX();
    float xy = (float) XX.getY();
    float xz = (float) XX.getZ();
    float yx = (float) YY.getX();
    float yy = (float) YY.getY();
    float yz = (float) YY.getZ();
    float cx = (float) C.getX();
    float cy = (float) C.getY();
    float cz = (float) C.getZ();
    float vx = (float) V.getX();
    float vy = (float) V.getY();
    float vz = (float) V.getZ();
    int vsx = this.getSizex();
    int vsy = this.getSizey();
    int vsz = this.getSizez();
    float ii;
    float jj;
    // increment de boucle sur l'image
    float k;
    int nb;
    float pix;
    float pixI;
    float vvx;
    float vvy;
    float vvz;
    boolean d1;
    boolean d2;
    for (int i = 0; i < sx; i++) {
        for (int j = 0; j < sy; j++) {
            ii = i - sx / 2;
            jj = -j + sy / 2;
            k = 0;
            nb = 0;
            pix = 0;
            d1 = true;
            d2 = true;
            while (d1 || d2) {
                vvx = (cx + ii * xx + jj * yx + k * vx);
                vvy = (cy + ii * xy + jj * yy + k * vy);
                vvz = (cz + ii * xz + jj * yz + k * vz);
                if (d1) {
                    if ((vvx < 0) || (vvx >= vsx) || (vvy < 0) || (vvy >= vsy) || (vvz < 0) || (vvz >= vsz)) {
                        d1 = false;
                    } else {
                        pix += this.getPixel(vvx, vvy, vvz);
                        nb++;
                    }
                }
                vvx = (cx + ii * xx + jj * yx - k * vx);
                vvy = (cy + ii * xy + jj * yy - k * vy);
                vvz = (cz + ii * xz + jj * yz - k * vz);
                if (d2) {
                    if ((vvx < 0) || (vvx >= vsx) || (vvy < 0) || (vvy >= vsy) || (vvz < 0) || (vvz >= vsz)) {
                        d2 = false;
                    } else {
                        pix += this.getPixel(vvx, vvy, vvz);
                        nb++;
                    }
                }
                k += 0.5;
            }
            if (moy) {
                if (nb > 0) {
                    I.putPixelValue(i, j, pix / nb);
                } else {
                    I.putPixelValue(i, j, 0);
                }
            } else {
                I.putPixelValue(i, j, pix);
            }
        }
    }
    return I;
}
Also used : Vector3D(mcib3d.geom.Vector3D)

Example 4 with Vector3D

use of mcib3d.geom.Vector3D in project mcib3d-core by mcib3d.

the class Mitosis method getCenterDaughters.

private Vector3D getCenterDaughters() {
    Vector3D cen1 = this.daughter1.getCenterAsVector();
    Vector3D cen2 = this.daughter2.getCenterAsVector();
    Vector3D middle = cen1.add(cen2).multiply(0.5D);
    return middle;
}
Also used : Vector3D(mcib3d.geom.Vector3D)

Example 5 with Vector3D

use of mcib3d.geom.Vector3D in project mcib3d-core by mcib3d.

the class Mitosis method getPotentialMother.

public void getPotentialMother(ImageHandler image1) {
    Objects3DPopulation population = new Objects3DPopulation(image1);
    Object3D convex = createConvexDaughters();
    ArrayUtil values = convex.listValues(image1).distinctValues();
    int bestMother = 0;
    double maxColoc = 0.0D;
    Vector3D cen1 = this.daughter1.getCenterAsVector();
    Vector3D cen2 = this.daughter2.getCenterAsVector();
    Vector3D mid = getCenterDaughters();
    this.daughter1.setNewCenter(mid);
    this.daughter2.setNewCenter(mid);
    IJ.log("Middle " + mid);
    for (int i = 0; i < values.size(); i++) {
        int val = values.getValueInt(i);
        if (val != 0) {
            Object3D object3D = population.getObjectByValue(val);
            double pc1 = object3D.pcColoc(this.daughter1);
            double pc2 = object3D.pcColoc(this.daughter2);
            if (Math.min(pc1, pc2) > maxColoc) {
                maxColoc = Math.min(pc1, pc2);
                bestMother = val;
            }
        }
    }
    this.daughter1.setNewCenter(cen1);
    this.daughter2.setNewCenter(cen2);
    IJ.log("Values mitosis : " + values.toString() + " Best : " + bestMother + " " + maxColoc);
}
Also used : Vector3D(mcib3d.geom.Vector3D) Objects3DPopulation(mcib3d.geom.Objects3DPopulation) Object3D(mcib3d.geom.Object3D) ArrayUtil(mcib3d.utils.ArrayUtil)

Aggregations

Vector3D (mcib3d.geom.Vector3D)18 Point3D (mcib3d.geom.Point3D)4 EigenvalueDecomposition (mcib3d.Jama.EigenvalueDecomposition)1 Matrix (mcib3d.Jama.Matrix)1 Object3D (mcib3d.geom.Object3D)1 Objects3DPopulation (mcib3d.geom.Objects3DPopulation)1 ImageFloat (mcib3d.image3d.ImageFloat)1 ImageHandler (mcib3d.image3d.ImageHandler)1 ArrayUtil (mcib3d.utils.ArrayUtil)1 Chrono (mcib3d.utils.Chrono)1 Point3f (org.scijava.vecmath.Point3f)1