Search in sources :

Example 61 with ArrayUtil

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

the class ImageHandler method getNeighborhoodLayerAngle.

/**
 * Get the neighborhood as a layer of pixels
 *
 * @param x  Coordinate x of the pixel
 * @param y  Coordinate y of the pixel
 * @param z  Coordinate z of the pixel
 * @param r0 Minimun radius value
 * @param r1 Maximum radius value
 * @return
 */
public ArrayUtil getNeighborhoodLayerAngle(int x, int y, int z, float r0, float r1, double angRef, Vector3D ref) {
    int index = 0;
    double r02 = r0 * r0;
    double r12 = r1 * r1;
    double dist;
    double ratio = getScaleZ() / getScaleXY();
    double ratio2 = ratio * ratio;
    int vx = (int) Math.ceil(r1);
    int vy = (int) Math.ceil(r1);
    int vz = (int) (Math.ceil(r1 / ratio));
    double[] pix = new double[(2 * vx + 1) * (2 * vy + 1) * (2 * vz + 1)];
    Vector3D cen = new Vector3D(x, y, z);
    for (int k = z - vz; k <= z + vz; k++) {
        for (int j = y - vy; j <= y + vy; j++) {
            for (int i = x - vx; i <= x + vx; i++) {
                if (i >= 0 && j >= 0 && k >= 0 && i < sizeX && j < sizeY && k < sizeZ) {
                    dist = ((x - i) * (x - i)) + ((y - j) * (y - j)) + ((z - k) * (z - k) * ratio2);
                    if ((dist >= r02) && (dist < r12)) {
                        // check angle
                        double angle = ref.angleDegrees(new Vector3D(i - x, j - y, k - z));
                        if (angle < angRef) {
                            pix[index] = getPixel(i, j, k);
                            index++;
                        }
                    }
                }
            }
        }
    }
    // check if some values are set
    if (index > 0) {
        ArrayUtil t = new ArrayUtil(pix);
        t.setSize(index);
        return t;
    } else {
        return null;
    }
}
Also used : Vector3D(mcib3d.geom.Vector3D) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 62 with ArrayUtil

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

the class ImageHandler method getNeighborhoodSphere.

/**
 * Gets the neighboring of a pixel (sphere)
 *
 * @param x    Coordinate x of the pixel
 * @param y    Coordinate y of the pixel
 * @param z    Coordinate z of the pixel
 * @param radx Radius x of the neighboring
 * @param rady Radius y of the neighboring
 * @param radz Radius z of the neighboring
 * @return The neigbor values in a array
 */
public ArrayUtil getNeighborhoodSphere(int x, int y, int z, float radx, float rady, float radz) {
    int index = 0;
    double rx2;
    if (radx != 0) {
        rx2 = radx * radx;
    } else {
        rx2 = 1;
    }
    double ry2;
    if (rady != 0) {
        ry2 = rady * rady;
    } else {
        ry2 = 1;
    }
    double rz2;
    if (radz != 0) {
        rz2 = radz * radz;
    } else {
        rz2 = 1;
    }
    double dist;
    int vx = (int) Math.ceil(radx);
    int vy = (int) Math.ceil(rady);
    int vz = (int) Math.ceil(radz);
    double[] pix = new double[(2 * vx + 1) * (2 * vy + 1) * (2 * vz + 1)];
    for (int k = z - vz; k <= z + vz; k++) {
        for (int j = y - vy; j <= y + vy; j++) {
            for (int i = x - vx; i <= x + vx; i++) {
                if (i >= 0 && j >= 0 && k >= 0 && i < sizeX && j < sizeY && k < sizeZ) {
                    dist = ((x - i) * (x - i)) / rx2 + ((y - j) * (y - j)) / ry2 + ((z - k) * (z - k)) / rz2;
                    if (dist <= 1.0) {
                        // t.putValue(index, );
                        pix[index] = getPixel(i, j, k);
                        index++;
                    }
                }
            }
        }
    }
    ArrayUtil t = new ArrayUtil(pix);
    t.setSize(index);
    return t;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 63 with ArrayUtil

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

the class ImageHandler method radialDistribution.

/**
 * Radial distribution of pixels mean values in layers
 *
 * @param x0    Coordinate x of the pixel
 * @param y0    Coordinate y of the pixel
 * @param z0    Coordinate z of the pixel
 * @param maxR  maximu radius
 * @param water
 * @return arry with mean radial values
 */
public double[] radialDistribution(int x0, int y0, int z0, int maxR, int measure, ImageInt water) {
    // int maxR = 10;
    double[] radPlot = new double[2 * maxR + 1];
    ArrayUtil raddist;
    int c = 0;
    int r;
    // compute radial means // FIXME optimise since symmetric ;)
    for (int i = -maxR; i <= 0; i++) {
        r = -i;
        raddist = getNeighborhoodLayer(x0, y0, z0, r, r + 1, water);
        if (raddist != null) {
            if (measure == Object3D.MEASURE_INTENSITY_AVG) {
                radPlot[c] = raddist.getMean();
            } else if (measure == Object3D.MEASURE_INTENSITY_MAX) {
                radPlot[c] = raddist.getMaximum();
            }
            if (measure == Object3D.MEASURE_INTENSITY_MEDIAN) {
                radPlot[c] = raddist.median();
            }
            if (measure == Object3D.MEASURE_INTENSITY_MIN) {
                radPlot[c] = raddist.getMinimum();
            }
            if (measure == Object3D.MEASURE_INTENSITY_SD) {
                radPlot[c] = raddist.getStdDev();
            }
        } else {
            radPlot[c] = Double.NaN;
        }
        c++;
    }
    for (int i = 1; i <= maxR; i++) {
        r = i;
        raddist = getNeighborhoodLayer(x0, y0, z0, r, r + 1, water);
        if (raddist != null) {
            if (measure == Object3D.MEASURE_INTENSITY_AVG) {
                radPlot[c] = raddist.getMean();
            } else if (measure == Object3D.MEASURE_INTENSITY_MAX) {
                radPlot[c] = raddist.getMaximum();
            }
            if (measure == Object3D.MEASURE_INTENSITY_MEDIAN) {
                radPlot[c] = raddist.median();
            }
            if (measure == Object3D.MEASURE_INTENSITY_MIN) {
                radPlot[c] = raddist.getMinimum();
            }
            if (measure == Object3D.MEASURE_INTENSITY_SD) {
                radPlot[c] = raddist.getStdDev();
            }
        } else {
            radPlot[c] = Double.NaN;
        }
        c++;
    }
    return radPlot;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 64 with ArrayUtil

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

the class ImageHandler method getNeighborhoodCross3D.

/**
 * 6-neighborhood in 3D cross of a given voxel
 *
 * @param x x-coordinate of the voxel
 * @param y y-coordinate of the voxel
 * @param z z-coordinate of the voxel
 * @return the ArrayUtil list of neighborhood voxels
 */
public ArrayUtil getNeighborhoodCross3D(int x, int y, int z) {
    ArrayUtil res = new ArrayUtil(7);
    res.putValue(0, getPixel(x, y, z));
    int idx = 1;
    if ((x + 1) < sizeX) {
        res.putValue(idx, getPixel(x + 1, y, z));
        idx++;
    }
    if ((x - 1) >= 0) {
        res.putValue(idx, getPixel(x - 1, y, z));
        idx++;
    }
    if ((y + 1) < sizeY) {
        res.putValue(idx, getPixel(x, y + 1, z));
        idx++;
    }
    if ((y - 1) >= 0) {
        res.putValue(idx, getPixel(x, y - 1, z));
        idx++;
    }
    if ((z + 1) < sizeZ) {
        res.putValue(idx, getPixel(x, y, z + 1));
        idx++;
    }
    if ((z - 1) >= 0) {
        res.putValue(idx, getPixel(x, y, z - 1));
        idx++;
    }
    res.setSize(idx);
    return res;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 65 with ArrayUtil

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

the class ImageInt method filterGeneric.

public void filterGeneric(ImageInt out, Object3DVoxels obj, int zmin, int zmax, int filter, Chrono timer, AbstractLog log) {
    if (zmin < 0) {
        zmin = 0;
    }
    if (zmax > this.sizeZ) {
        zmax = this.sizeZ;
    }
    int value;
    // convert the object to neighborhood
    int[] ker = FastFilters3D.createKernelFromObject(obj);
    int nb = FastFilters3D.getNbFromKernel(ker);
    float[] rad = FastFilters3D.getRadiiFromObject(obj);
    ArrayUtil tab;
    for (int k = zmin; k < zmax; k++) {
        IJ.showStatus("3D filter : " + (k + 1) + "/" + zmax);
        for (int j = 0; j < sizeY; j++) {
            for (int i = 0; i < sizeX; i++) {
                tab = this.getNeighborhoodKernel(ker, nb, i, j, k, rad[0], rad[1], rad[2]);
                // tab = ker.listVoxels(this, i, j, k);
                if (filter == FastFilters3D.MEAN) {
                    out.setPixel(i, j, k, (int) (tab.getMean() + 0.5));
                } else if (filter == FastFilters3D.MEDIAN) {
                    out.setPixel(i, j, k, (int) tab.medianSort());
                }
                if (filter == FastFilters3D.MIN) {
                    out.setPixel(i, j, k, (int) tab.getMinimum());
                }
                if (filter == FastFilters3D.MAX) {
                    out.setPixel(i, j, k, (int) tab.getMaximum());
                }
                if (filter == FastFilters3D.VARIANCE) {
                    out.setPixel(i, j, k, (int) (tab.getVariance2() + 0.5));
                }
                if (filter == FastFilters3D.MAXLOCAL) {
                    value = this.getPixelInt(i, j, k);
                    if (tab.isMaximum(value)) {
                        out.setPixel(i, j, k, value);
                    } else {
                        out.setPixel(i, j, k, 0);
                    }
                }
            }
        }
        if (timer != null) {
            String ti = timer.getFullInfo(1);
            if (ti != null)
                log.log("3D filtering : " + ti);
        }
    }
    resetStats();
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Aggregations

ArrayUtil (mcib3d.utils.ArrayUtil)66 ArrayList (java.util.ArrayList)9 Iterator (java.util.Iterator)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Voxel3D (mcib3d.geom.Voxel3D)2 Voxel3DComparable (mcib3d.geom.Voxel3DComparable)2 RoiManager (ij.plugin.frame.RoiManager)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Point3D (mcib3d.geom.Point3D)1 Vector3D (mcib3d.geom.Vector3D)1 ImageInt (mcib3d.image3d.ImageInt)1