Search in sources :

Example 1 with ArrayUtil

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

the class ImageFloat method filterGeneric.

public void filterGeneric(ImageFloat 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;
    }
    float value;
    int[] ker = FastFilters3D.createKernelFromObject(obj);
    int nb = FastFilters3D.getNbFromKernel(ker);
    float[] rad = FastFilters3D.getRadiiFromObject(obj);
    ArrayUtil tab;
    for (int k = zmin; k < zmax; k++) {
        for (int j = 0; j < sizeY; j++) {
            for (int i = 0; i < sizeX; i++) {
                // tab = obj.listVoxels(this, i, j, k);
                tab = this.getNeighborhoodKernel(ker, nb, i, j, k, rad[0], rad[1], rad[2]);
                if (filter == FastFilters3D.MEAN) {
                    out.setPixel(i, j, k, (float) (tab.getMean() + 0.5));
                } else if (filter == FastFilters3D.MEDIAN) {
                    out.setPixel(i, j, k, (float) tab.medianSort());
                }
                if (filter == FastFilters3D.MIN) {
                    out.setPixel(i, j, k, (float) tab.getMinimum());
                }
                if (filter == FastFilters3D.MAX) {
                    out.setPixel(i, j, k, (float) tab.getMaximum());
                }
                if (filter == FastFilters3D.VARIANCE) {
                    out.setPixel(i, j, k, (float) (tab.getVariance2() + 0.5));
                }
                if (filter == FastFilters3D.MAXLOCAL) {
                    value = this.getPixel(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);
        }
    }
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 2 with ArrayUtil

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

the class ImageFloat method filterGeneric.

/**
 * 3D filter using threads
 *
 * @param out
 * @param radx   Radius of mean filter in x
 * @param rady   Radius of mean filter in y
 * @param radz   Radius of mean filter in z
 * @param zmin
 * @param zmax
 * @param filter
 */
public void filterGeneric(ImageFloat out, float radx, float rady, float radz, int zmin, int zmax, int filter, Chrono timer, AbstractLog log) {
    int[] ker = FastFilters3D.createKernelEllipsoid(radx, rady, radz);
    int nb = 0;
    for (int aKer : ker) {
        nb += aKer;
    }
    if (zmin < 0) {
        zmin = 0;
    }
    if (zmax > this.sizeZ) {
        zmax = this.sizeZ;
    }
    float value;
    for (int k = zmin; k < zmax; k++) {
        for (int j = 0; j < sizeY; j++) {
            for (int i = 0; i < sizeX; i++) {
                ArrayUtil tab = this.getNeighborhoodKernel(ker, nb, i, j, k, radx, rady, radz);
                if (filter == FastFilters3D.MEAN) {
                    out.setPixel(i, j, k, (float) tab.getMean());
                } else if (filter == FastFilters3D.MEDIAN) {
                    out.setPixel(i, j, k, (float) tab.medianSort());
                }
                if (filter == FastFilters3D.MIN) {
                    out.setPixel(i, j, k, (float) tab.getMinimum());
                }
                if (filter == FastFilters3D.MAX) {
                    out.setPixel(i, j, k, (float) tab.getMaximum());
                }
                if (filter == FastFilters3D.VARIANCE) {
                    out.setPixel(i, j, k, (float) tab.getVariance2());
                }
                if (filter == FastFilters3D.MAXLOCAL) {
                    value = this.getPixel(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);
        }
    }
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 3 with ArrayUtil

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

the class ImageHandler method getNeighborhood3x3x3.

/**
 * Gets the 3D neighborhood of the pixel in 8 connexion --> 27 pixels
 *
 * @param x x coordinate
 * @param y y coordinate
 * @param z z coordinate
 * @return The array with the neighborhood values
 */
public ArrayUtil getNeighborhood3x3x3(int x, int y, int z) {
    ArrayUtil res = new ArrayUtil(27);
    int idx = 0;
    for (int k = z - 1; k <= z + 1; k++) {
        for (int j = y - 1; j <= y + 1; j++) {
            for (int i = x - 1; i <= x + 1; i++) {
                if ((i >= 0) && (j >= 0) && (k >= 0) && (i < sizeX) && (j < sizeY) && (k < sizeZ)) {
                    res.putValue(idx, getPixel(i, j, k));
                    idx++;
                }
            }
        }
    }
    res.setSize(idx);
    return res;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 4 with ArrayUtil

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

the class ImageHandler method getNeighborhoodKernelAdd.

public ArrayUtil getNeighborhoodKernelAdd(Object3D obj, ImageHandler img, int x, int y, int z) {
    int nbval = obj.getVolumePixels();
    ArrayUtil pix = new ArrayUtil(nbval);
    ImageHandler seg = obj.getLabelImage();
    int[] bb = obj.getBoundingBox();
    float radx = (float) (0.5 * (bb[1] - bb[0]));
    float rady = (float) (0.5 * (bb[3] - bb[2]));
    float radz = (float) (0.5 * (bb[5] - bb[4]));
    int vx = (int) Math.ceil(radx);
    int vy = (int) Math.ceil(rady);
    int vz = (int) Math.ceil(radz);
    int index = 0;
    int zmin = z - vz;
    if (zmin < 0) {
        zmin = 0;
    }
    int zmax = z + vz;
    if (zmax >= this.sizeZ) {
        zmax = this.sizeZ - 1;
    }
    int ymin = y - vy;
    if (ymin < 0) {
        ymin = 0;
    }
    int ymax = y + vy;
    if (ymax >= this.sizeY) {
        ymax = this.sizeY - 1;
    }
    int xmin = x - vx;
    if (xmin < 0) {
        xmin = 0;
    }
    int xmax = x + vx;
    if (xmax >= this.sizeX) {
        xmax = this.sizeX - 1;
    }
    int tx = xmin - bb[0];
    int ty = ymin - bb[2];
    int tz = zmin - bb[4];
    for (int k = zmin; k <= zmax; k++) {
        for (int j = ymin; j <= ymax; j++) {
            for (int i = xmin; i <= xmax; i++) {
                if ((seg.contains(i - tx, j - ty, k - tz)) && (seg.getPixel(i - tx, j - ty, k - tz) > 0)) {
                    pix.putValue(index, this.getPixel(i, j, k) + img.getPixel(i - tx, j - ty, k - tz));
                    index++;
                }
            }
        }
    }
    pix.setSize(index);
    return pix;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 5 with ArrayUtil

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

the class ImageHandler method getNeighborhoodLayer.

/**
 * 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    Minimu radius value
 * @param r1    Maximum radius value
 * @param water
 * @return
 */
public ArrayUtil getNeighborhoodLayer(int x, int y, int z, float r0, float r1, ImageInt water) {
    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)];
    int wat = 0;
    if (water != null) {
        wat = water.getPixelInt(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) {
                    if (((water != null) && (water.getPixel(i, j, k) == wat)) || (water == null)) {
                        dist = ((x - i) * (x - i)) + ((y - j) * (y - j)) + ((z - k) * (z - k) * ratio2);
                        if ((dist >= r02) && (dist < r12)) {
                            // t.putValue(index, );
                            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 : 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