Search in sources :

Example 11 with ArrayUtil

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

the class Image3D method getNeighborhoodKernel.

/**
 * Gets the neighboring attribute of the Image3D with a kernel as a array
 *
 * @param ker The kernel array (>0 ok)
 * @param nbval The number of non-zero values
 * @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 radz Radius y of the neighboring
 * @param rady Radius z of the neighboring
 * @return The values of the nieghbor pixels inside an array
 */
public ArrayUtil getNeighborhoodKernel(int[] ker, int nbval, int x, int y, int z, float radx, float rady, float radz) {
    ArrayUtil pix = new ArrayUtil(nbval);
    int vx = (int) Math.ceil(radx);
    int vy = (int) Math.ceil(rady);
    int vz = (int) Math.ceil(radz);
    int index = 0;
    int c = 0;
    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 (ker[c] > 0) {
                    if ((i >= 0) && (j >= 0) && (k >= 0) && (i < sizex) && (j < sizey) && (k < sizez)) {
                        pix.putValue(index, (float) getPix(i, j, k));
                        index++;
                    }
                }
                c++;
            }
        }
    }
    pix.setSize(index);
    return pix;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 12 with ArrayUtil

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

the class Image3D method getNeighborhood.

/**
 * Gets the neighboring of a pixel, with a kernel as an image
 *
 * @param x Coordinate x of the pixel
 * @param y Coordinate y of the pixel
 * @param z Coordinate z of the pixel
 * @param ker The kernel (0 = outside kernel, else inside)
 * @return The neigbor values in a array
 */
public ArrayUtil getNeighborhood(Image3D ker, int x, int y, int z) {
    int voisx = ker.getSizex();
    int voisy = ker.getSizey();
    int voisz = ker.getSizez();
    int cx = (int) ker.getCenterX();
    int cy = (int) ker.getCenterY();
    int cz = (int) ker.getCenterZ();
    ArrayUtil t = new ArrayUtil((voisx * 2 + 1) * (voisy * 2 + 1) * (voisz * 2 + 1));
    int index = 0;
    for (int k = z - cz; k < z + voisz - cz; k++) {
        for (int j = y - cy; j < y + voisy - cy; j++) {
            for (int i = x - cx; i < x + voisx - cx; i++) {
                if (i >= 0 && j >= 0 && k >= 0 && i < sizex && j < sizey && k < sizez) {
                    if (ker.getPix(cx + i - x, cy + j - y, cz + k - z) > 0) {
                        t.putValue(index, (float) getPix(i, j, k));
                        index++;
                    }
                }
            }
        }
    }
    t.setSize(index);
    return t;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 13 with ArrayUtil

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

the class Image3D 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, getPix(i, j, k));
                }
                idx++;
            }
        }
    }
    res.setSize(idx);
    return res;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 14 with ArrayUtil

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

the class Image3D 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, IntImage3D water) {
    int index = 0;
    double r02 = r0 * r0;
    double r12 = r1 * r1;
    double dist;
    int vx = (int) Math.ceil(r1);
    int vy = (int) Math.ceil(r1);
    int vz = 0;
    double[] pix = new double[(2 * vx + 1) * (2 * vy + 1) * (2 * vz + 1)];
    int wat = 0;
    if (water != null) {
        wat = water.getPixel(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));
                        if ((dist >= r02) && (dist < r12)) {
                            // t.putValue(index, );
                            pix[index] = getPix(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)

Example 15 with ArrayUtil

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

the class IntImage3D method watershed.

/**
 * Watershed algorithm starting with a seed image where seed > 0
 *
 * @return The segmented image
 */
public IntImage3D watershed() {
    IntImage3D label = new IntImage3D(this);
    IntImage3D tmp;
    int go = 1;
    int i;
    int j;
    int k;
    int rx = 1;
    int ry = 1;
    int rz = 1;
    ArrayUtil tab;
    ArrayUtil tab2;
    int count = 1;
    int pix;
    for (k = 0; k < sizez; k++) {
        for (i = 0; i < sizex; i++) {
            for (j = 0; j < sizey; j++) {
                pix = label.getPixel(i, j, k);
                if ((pix > 0)) {
                    label.putPixel(i, j, k, count);
                    label.propagation27(i, j, k, pix, count);
                    count++;
                }
                IJ.showStatus("Watershed 3D Labels : " + count);
            }
        }
    }
    // tmp = new IntImage3D(label);
    // int taille = getSizex() * getSizey() * getSizez();
    // go = taille;
    // ImagePlus test = new ImagePlus("labels", tmp.getStack());
    // test.show();
    // maxPixel depth of the image
    int ite = getMaximum();
    while (ite > 0) {
        for (k = 0; k < sizez; k++) {
            if (this.showStatus) {
                IJ.showStatus("Watershed 3D Segmentation (" + ite + ") : " + k + " / " + sizez + "   ");
            }
            for (i = 0; i < sizex; i++) {
                for (j = 0; j < sizey; j++) {
                    // if pix not been labelled
                    if (label.getPixel(i, j, k) == 0) {
                        tab2 = getNeighborhood3x3x3(i, j, k);
                        if (tab2.hasValue(ite)) {
                            tab = label.getNeighborhood3x3x3(i, j, k);
                            // only distinct values
                            tab = tab.distinctValues();
                            if ((tab.getMaximum() > 0) && (tab.getSize() == 2)) {
                                this.putPixel(i, j, k, ite - 1);
                                label.putPixel(i, j, k, (int) tab.getMaximum());
                            }
                        }
                    }
                }
            }
        }
        // label.insert(tmp, 0, 0, 0, false);
        ite--;
    // test.setStack("water", tmp.getStack());
    // test.updateAndDraw();
    }
    return label;
}
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