Search in sources :

Example 16 with ArrayUtil

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

the class IntImage3D method sobelFilter.

/**
 * Sobel-like filtering in 3D
 *
 * @return The 3D filtered image
 */
public IntImage3D sobelFilter() {
    IntImage3D res = new IntImage3D(sizex, sizey, sizez);
    ArrayUtil nei;
    double[] edgeX = { -1, 0, 1, -2, 0, 2, -1, 0, 1, -2, 0, 2, -4, 0, 4, -2, 0, 2, -1, 0, 1, -2, 0, 2, -1, 0, 1 };
    double[] edgeY = { -1, -2, -1, 0, 0, 0, 1, 2, 1, -2, -4, -2, 0, 0, 0, 2, 4, 2, -1, -2, -1, 0, 0, 0, 1, 2, 1 };
    double[] edgeZ = { -1, -2, -1, -2, -4, -2, -1, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 2, 4, 2, 1, 2, 1 };
    double ex;
    double ey;
    double ez;
    double edge;
    for (int k = 0; k < sizez; k++) {
        if (this.showStatus) {
            IJ.showStatus("3D Sobel : " + (int) (100 * k / sizez) + "%");
        }
        for (int j = 0; j < sizey; j++) {
            for (int i = 0; i < sizex; i++) {
                nei = getNeighborhood3x3x3(i, j, k);
                ex = nei.convolve(edgeX, 1.0f);
                ey = nei.convolve(edgeY, 1.0f);
                ez = nei.convolve(edgeZ, 1.0f);
                edge = Math.sqrt(ex * ex + ey * ey + ez * ez);
                if (edge > 65535) {
                    edge = 65535;
                }
                res.putPixel(i, j, k, (int) edge);
            }
        }
    }
    return res;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 17 with ArrayUtil

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

the class RegionGrowing method getBordersMerge.

public ArrayList<Voxel3D> getBordersMerge(int[] oldLabels, boolean outsideBorders) {
    ArrayList<Voxel3D> drawBorders = new ArrayList();
    int nb = oldLabels.length;
    ArrayList allowedValues = new ArrayList();
    allowedValues.add(BORDER);
    if (outsideBorders) {
        allowedValues.add(NO_LABEL);
    }
    for (int o : oldLabels) {
        allowedValues.add(o);
    }
    int maxLabel = 0;
    for (int z = 0; z < watershedImage.sizeZ; z++) {
        for (int y = 0; y < watershedImage.sizeY; y++) {
            for (int x = 0; x < watershedImage.sizeX; x++) {
                int pix = watershedImage.getPixelInt(x, y, z);
                if (pix > maxLabel) {
                    maxLabel = pix;
                }
                if (pix == BORDER) {
                    ArrayUtil neigh = watershedImage.getNeighborhood3x3x3(x, y, z);
                    // IJ.log("" + neigh + " " + neigh.hasOnlyValuesInt(allowedValues));
                    if (neigh.hasOnlyValuesInt(allowedValues)) {
                        drawBorders.add(new Voxel3D(x, y, z, pix));
                    // IJ.log("border " + x + " " + y + " " + z);
                    }
                }
            }
        }
    }
    return drawBorders;
}
Also used : ArrayList(java.util.ArrayList) Voxel3D(mcib3d.geom.Voxel3D) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 18 with ArrayUtil

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

the class Watershed3D_old method assignWatershedAccurate.

private boolean assignWatershedAccurate(int threshold) {
    Voxel3DComparable voxel;
    int px, py, pz;
    ArrayUtil neigh;
    int max, max2;
    boolean loop = false;
    ArrayList<Voxel3DComparable> voxelsNextRound = new ArrayList();
    ArrayList<Voxel3DComparable> voxelsToProcess = new ArrayList();
    for (Iterator it = voxels.iterator(); it.hasNext(); ) {
        voxel = (Voxel3DComparable) it.next();
        if (voxel.getValue() < threshold) {
            // voxelsNextRound.addAll(voxels.subList(voxels.indexOf(voxel), voxels.size()));
            break;
        // voxelsNextRound.add(voxel);
        // continue;
        }
        px = voxel.getRoundX();
        py = voxel.getRoundY();
        pz = voxel.getRoundZ();
        if (watershedImage.getPixel(px, py, pz) == NO_LABEL) {
            // 6-neighbor
            // neigh = watershedImage.getNeighborhoodCross3D(px, py, pz);
            // 26-neighbor
            neigh = watershedImage.getNeighborhood3x3x3(px, py, pz);
            max = (int) neigh.getMaximum();
            if ((max == NO_LABEL) || (max == BORDER)) {
                voxelsNextRound.add(voxel);
            } else {
                // has a neighbor already labeled // test if two differents labels around
                voxelsToProcess.add(voxel);
            }
        }
    }
    // process voxels
    for (Voxel3DComparable vox : voxelsToProcess) {
        px = vox.getRoundX();
        py = vox.getRoundY();
        pz = vox.getRoundZ();
        neigh = watershedImage.getNeighborhood3x3x3(px, py, pz);
        max = (int) neigh.getMaximum();
        max2 = (int) neigh.getMaximumBelow(max);
        if ((max2 == NO_LABEL) || (max2 == BORDER)) {
            watershedImage.setPixel(px, py, pz, max);
            loop = true;
            // compute volumes
            if (computeVolumes) {
                // volumeLabels.get(max)[1]++;
                volumeLabels.set(max, volumeLabels.get(max) + 1);
            }
            // get active label
            if (computeUpdatedLabels) {
                String la = "" + max;
                // test if exists already
                boolean ok = true;
                for (String S : updatedLabels) {
                    if ((S.compareTo(la)) == 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    updatedLabels.add(la);
                }
            }
            // add the new labels sharing a border
            if ((max2 == BORDER) && (computeAssociation)) {
                updateAssociationBorder(px, py, pz, max);
            }
        // two or more labels around
        } else {
            watershedImage.setPixel(px, py, pz, BORDER);
            // get association
            if (computeAssociation) {
                String asso = max + "_" + max2;
                AssociationRegion assoR = new AssociationRegion();
                assoR.addRegion(max);
                assoR.addRegion(max2);
                max2 = (int) neigh.getMaximumBelow(max2);
                while ((max2 != NO_LABEL) && (max2 != BORDER)) {
                    asso = asso.concat("_" + max2);
                    assoR.addRegion(max2);
                    max2 = (int) neigh.getMaximumBelow(max2);
                }
                // if next to border update
                if ((max2 == BORDER) && (computeAssociation)) {
                    for (String S : asso.split("_")) {
                        updateAssociationBorder(px, py, pz, Integer.parseInt(S));
                    }
                }
                // test if association exists already
                boolean ok = true;
                for (String S : associations) {
                    if ((S.compareTo(asso)) == 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    associations.add(asso);
                }
                assoRegions.addAssoRegion(assoR);
            }
        }
    }
    voxels = voxelsNextRound;
    System.gc();
    return loop;
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Voxel3DComparable(mcib3d.geom.Voxel3DComparable) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 19 with ArrayUtil

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

the class Objects3DPopulation method distancesAllClosestCenter.

/**
 * @return
 */
public ArrayUtil distancesAllClosestCenter() {
    int nb = this.getNbObjects();
    ArrayUtil tab = new ArrayUtil(nb);
    Object3D cl;
    for (int i = 0; i < nb; i++) {
        cl = closestCenter(this.getObject(i), true);
        if (cl != null) {
            double d = cl.distCenterUnit(this.getObject(i));
            tab.putValue(i, d);
        }
    }
    return tab;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 20 with ArrayUtil

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

the class Objects3DPopulation method distancesAllClosestBorder.

public ArrayUtil distancesAllClosestBorder() {
    int nb = this.getNbObjects();
    ArrayUtil tab = new ArrayUtil(nb);
    Object3D cl;
    for (int i = 0; i < nb; i++) {
        cl = closestBorder(this.getObject(i));
        if (cl != null) {
            double d = cl.distBorderUnit(this.getObject(i));
            tab.putValue(i, d);
        }
    }
    return tab;
}
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