Search in sources :

Example 51 with ArrayUtil

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

the class Object3DVoxels method listValues.

@Override
public ArrayUtil listValues(ImageHandler ima) {
    ArrayUtil list = new ArrayUtil(this.getVolumePixels());
    Voxel3D voxel;
    Iterator<Voxel3D> it = voxels.iterator();
    int idx = 0;
    while (it.hasNext()) {
        voxel = it.next();
        if (ima.contains(voxel.getX(), voxel.getY(), voxel.getZ())) {
            list.putValue(idx, ima.getPixel(voxel));
            idx++;
        }
    }
    list.setSize(idx);
    return list;
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 52 with ArrayUtil

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

the class Objects3DPopulation method shuffle.

public ArrayList<Object3D> shuffle() {
    ArrayList<Object3D> shuObj = new ArrayList<Object3D>();
    Random ra = new Random();
    ImageInt maskImage = mask.getMaxLabelImage(1);
    Object3DVoxels maskVox = mask.getObject3DVoxels();
    // shuffle indices
    ArrayUtil shuffleIndex = new ArrayUtil(getNbObjects());
    shuffleIndex.fillRange(0, getNbObjects(), 1);
    shuffleIndex.shuffle();
    for (int i = 0; i < getNbObjects(); i++) {
        Object3DVoxels obj = (Object3DVoxels) getObject(shuffleIndex.getValueInt(i));
        Point3D center = obj.getCenterAsPoint();
        boolean ok = false;
        int it = 0;
        int maxIt = 1000000;
        while (!ok) {
            // log.log("Shuffling " + getObject3D(i).getValue());
            Voxel3D vox = maskVox.getRandomvoxel(ra);
            obj.setNewCenter(vox.getX(), vox.getY(), vox.getZ());
            ok = true;
            it++;
            obj.resetQuantifImage();
            if (maskVox.includesBox(obj)) {
                if (obj.getPixMinValue(maskImage) < 1) {
                    ok = false;
                }
            } else {
                ok = false;
            }
            if (it >= maxIt) {
                ok = true;
            }
        }
        if (it == maxIt) {
            if (log != null)
                log.log("Could not shuffle " + obj);
            obj.setNewCenter(center.x, center.y, center.z);
        }
        shuObj.add(obj);
        // update mask
        obj.draw(maskImage, 0);
    }
    return shuObj;
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) ImageInt(mcib3d.image3d.ImageInt) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 53 with ArrayUtil

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

the class Objects3DPopulationColocalisation method initColocalisation.

private void initColocalisation() {
    // indices 1
    ArrayUtil arrayUtil = population1.getAllIndices();
    indices1.put(0, 0);
    for (int i = 0; i < arrayUtil.size(); i++) {
        indices1.put(arrayUtil.getValueInt(i), i + 1);
    }
    // indices 2
    arrayUtil = population2.getAllIndices();
    indices2.put(0, 0);
    for (int i = 0; i < arrayUtil.size(); i++) {
        indices2.put(arrayUtil.getValueInt(i), i + 1);
    }
    // zeroes the matrix of coloc
    for (int ia = 0; ia < population1.getNbObjects(); ia++) {
        for (int ib = 0; ib < population2.getNbObjects(); ib++) {
            colocs[ia][ib] = 0;
        }
    }
}
Also used : ArrayUtil(mcib3d.utils.ArrayUtil)

Example 54 with ArrayUtil

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

the class DeformableMesh method getClosestEdge.

private Point3D getClosestEdge(int i, boolean forward) {
    int border = 1;
    ArrayUtil der = new ArrayUtil(computeEdgeDeriche(i, border, forward));
    int pos = der.getFirstLocalExtrema(thresholdMax, thresholdMin);
    if (pos < border) {
        return null;
    }
    double ratio = (pos - border) / (der.getSize() - 2.0 * border);
    Point3D P = new Point3D(vertices.get(i));
    int dir = forward ? 1 : -1;
    P.translate(verticesNormals.get(i).multiply(dir * ratio * maxDistance));
    return P;
}
Also used : Point3D(mcib3d.geom.Point3D) ArrayUtil(mcib3d.utils.ArrayUtil)

Example 55 with ArrayUtil

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

the class ImageFloat method sobelFilter.

/**
 * Sobel-like filtering in 3D
 *
 * @return The 3D filtered image
 */
public ImageFloat sobelFilter() {
    ImageFloat res = (ImageFloat) this.createSameDimensions();
    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++) {
        // }
        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);
                res.setPixel(i, j, k, (float) edge);
            }
        }
    }
    return res;
}
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