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;
}
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;
}
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;
}
}
}
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;
}
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;
}
Aggregations