use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryDilate.
// if no resize of the image, object at the border may be truncated
public static ImageByte binaryDilate(ImageInt in, float radius, float radiusZ, int nbCPUs, boolean enlarge) {
try {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
ImageInt resize = in;
// resize
int reX = (int) (radius + 1);
int reY = (int) (radius + 1);
int reZ = (int) (radiusZ + 1);
if (enlarge)
resize = (ImageInt) in.enlarge(reX, reY, reZ);
ImageFloat edm = EDT.run(resize, 0, 1, radius / radiusZ, true, nbCPUs);
// edm.duplicate().show("edm");
ImageByte temp = edm.threshold(radius, true, false);
// temp.show("thres");
edm.flush();
edm = null;
if (enlarge)
temp.setOffset(in.offsetX - reX, in.offsetY - reY, in.offsetZ - reZ);
else
temp.setOffset(in);
temp.setScale(in);
return temp;
} catch (Exception e) {
exceptionPrinter.print(e, null, true);
}
return null;
}
use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryCloseMultilabel.
public static ImageInt binaryCloseMultilabel(ImageInt in, float[] radiusXY, float[] radiusZ, int nbCPUs) {
ImageByte[] ihs = in.crop3DBinary();
if ((radiusXY.length != ihs.length) || (radiusZ.length != ihs.length)) {
return null;
}
if (ihs != null) {
// ij.IJ.log("BinaryClose multilabel nb :"+ihs.length);
for (int idx = 0; idx < ihs.length; idx++) {
if (radiusXY[idx] <= 1 && radiusZ[idx] <= 1) {
ihs[idx] = BinaryMorpho.binaryCloseRad1(ihs[idx], 1, nbCPUs);
} else {
ihs[idx] = binaryClose(ihs[idx], radiusXY[idx], radiusZ[idx], nbCPUs);
}
ihs[idx] = binaryClose(ihs[idx], radiusXY[idx], radiusZ[idx], nbCPUs);
}
ImageInt temp = ImageShort.merge3DBinary(ihs, in.sizeX, in.sizeY, in.sizeZ);
temp.setScale(in);
temp.setOffset(in);
return temp;
}
return in;
}
use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryDilate2D.
public static ImageByte binaryDilate2D(ImageByte in, float radius, boolean enlarge) {
ImageInt resize = in;
// resize
int reX = (int) (radius + 1);
int reY = (int) (radius + 1);
int reZ = 0;
if (enlarge)
resize = (ImageInt) in.enlarge(reX, reY, reZ);
ImageByte temp = (ImageByte) FastFilters3D.filterIntImage(resize, FastFilters3D.MAX, radius, radius, 0, 1, false);
temp.setScale(in);
if (enlarge)
temp.setOffset(in.offsetX - reX, in.offsetY - reY, in.offsetZ - reZ);
else
temp.setOffset(in);
return temp;
}
use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryCloseRad1diag.
private static ImageByte binaryCloseRad1diag(final ImageInt in_, final float thld, int nbCPUs) {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
// TODO: faire sans resize avec un simple décalage des indices
final ImageInt in = (ImageInt) in_.resize(1, 1, 1);
final ImageByte max = new ImageByte("max", in.sizeX, in.sizeY, in.sizeZ);
final ThreadRunner tr = new ThreadRunner(0, max.sizeZ, nbCPUs);
for (int i = 0; i < tr.threads.length; i++) {
tr.threads[i] = new Thread(new Runnable() {
@Override
public void run() {
for (int z = tr.ai.getAndIncrement(); z < tr.end; z = tr.ai.getAndIncrement()) {
for (int y = 0; y < max.sizeY; y++) {
for (int x = 0; x < max.sizeX; x++) {
if (maxRad15(in, thld, x, y, z)) {
max.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr.startAndJoin();
final ThreadRunner tr2 = new ThreadRunner(0, in.sizeZ, nbCPUs);
final ImageByte close = new ImageByte(in.getTitle() + "::close", in.sizeX, in.sizeY, in.sizeZ);
for (int i = 0; i < tr2.threads.length; i++) {
tr2.threads[i] = new Thread(new Runnable() {
@Override
public void run() {
for (int z = tr2.ai.getAndIncrement(); z < tr2.end; z = tr2.ai.getAndIncrement()) {
for (int y = 0; y < in.sizeY; y++) {
for (int x = 0; x < in.sizeX; x++) {
if (minRad15(max, 1, x, y, z)) {
close.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr2.startAndJoin();
max.closeImagePlus();
close.setOffset(in);
close.setScale(in);
return close;
}
use of mcib3d.image3d.ImageInt in project mcib3d-core by mcib3d.
the class SpatialRandom method getSample.
@Override
public Objects3DPopulation getSample() {
Point3D[] points = new Point3D[nbObjects];
Objects3DPopulation pop = new Objects3DPopulation();
pop.setMask(mask);
ImageInt maskimgTmp = maskimg.duplicate();
Random ra = new Random();
for (int i = 0; i < nbObjects; i++) {
Voxel3D vox = maskVox.getRandomvoxel(ra);
while (maskimgTmp.getPixel(vox) == 0) {
vox = maskVox.getRandomvoxel(ra);
}
points[i] = vox;
maskimgTmp.setPixel(vox, 0);
}
pop.addPoints(points);
return pop;
}
Aggregations