use of mcib3d.image3d.ImageFloat in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryErode.
public static ImageByte binaryErode(ImageInt in, float radius, float radiusZ, int nbCPUs) {
try {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
// test rad <=1
/*if ((radius <= 1) && (radiusZ <= 1)) {
return binaryErodeRad1(in, 1, nbCPUs);
}*/
ImageFloat edm = EDT.run(in, 0, 1, radius / radiusZ, false, nbCPUs);
ImageByte temp = edm.threshold(radius, false, true);
edm.flush();
edm = null;
temp.setOffset(in);
temp.setScale(in);
return temp;
} catch (Exception e) {
exceptionPrinter.print(e, null, true);
}
return null;
}
use of mcib3d.image3d.ImageFloat in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryOpen.
public static ImageByte binaryOpen(ImageInt in, float radius, float radiusZ, int nbCPUs) {
try {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
// test rad <=1
/*if ((radius <= 1) && (radiusZ <= 1)) {
return binaryOpenRad1(in, 1, nbCPUs);
}*/
ImageFloat edm = EDT.run(in, 0, 1, radius / radiusZ, false, nbCPUs);
ImageByte temp = edm.threshold(radius, false, true);
edm.closeImagePlus();
edm = EDT.run(temp, 0, 1, radius / radiusZ, true, nbCPUs);
temp.closeImagePlus();
temp = edm.threshold(radius, true, false);
edm.closeImagePlus();
edm = null;
System.gc();
temp.setOffset(in);
temp.setScale(in);
return temp;
} catch (Exception e) {
exceptionPrinter.print(e, null, true);
}
return null;
}
use of mcib3d.image3d.ImageFloat in project mcib3d-core by mcib3d.
the class SymmetryFilter method computeBins.
private void computeBins() {
ImageHandler img = edges[0];
bin1 = new ImageFloat("bin1", img.sizeX, img.sizeY, img.sizeZ);
bin2 = new ImageFloat("bin2", img.sizeX, img.sizeY, img.sizeZ);
for (int z = 0; z < img.sizeZ; z++) {
IJ.showStatus("Symmetry " + z + "/" + img.sizeZ);
for (int x = 0; x < img.sizeX; x++) {
for (int y = 0; y < img.sizeY; y++) {
double ex = edges[0].getPixel(x, y, z);
double ey = edges[1].getPixel(x, y, z);
double ez = edges[2].getPixel(x, y, z);
double ee = Math.sqrt(ex * ex + ey * ey + ez * ez);
// bin
Vector3D grad = new Vector3D(ex, ey, ez);
grad.normalize();
if (grad.getLength() == 0) {
continue;
}
Point3D pos = new Vector3D(x, y, z);
for (int d = 0; d < radius; d++) {
pos.translate(grad);
if ((d > 0) && (img.contains(pos.getRoundX(), pos.getRoundY(), pos.getRoundZ()))) {
bin1.setPixelIncrement(pos, 1);
if (improved) {
bin2.setPixelIncrement(pos, (float) (d * ee));
} else {
bin2.setPixelIncrement(pos, (float) (ee));
}
}
}
}
}
}
}
use of mcib3d.image3d.ImageFloat in project mcib3d-core by mcib3d.
the class Density3D method computeDensity.
public ImageHandler computeDensity(ImageHandler handler, boolean multi) {
final ImageHandler img = handler;
ImageHandler res = new ImageFloat("density", img.sizeX, img.sizeY, img.sizeZ);
Objects3DPopulation population = new Objects3DPopulation(img);
population.createKDTreeCenters();
// non parallel version
if (!multi) {
densityProcess(img, population, res, 0, handler.sizeZ, neighbours, sigma);
} else {
// parallel version
// PARALLEL, need to duplicate populations
int neighbours2 = Math.min(neighbours, population.getNbObjects());
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = ThreadUtil.getNbCpus();
final int dec = (int) Math.ceil((double) handler.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
int bound = threads.length;
for (int iThread = 0; iThread < bound; iThread++) {
threads[iThread] = new Thread(() -> {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
Objects3DPopulation pop = new Objects3DPopulation(img);
densityProcess(img, pop, res, dec * k, dec * (k + 1), neighbours2, sigma);
}
});
}
ThreadUtil.startAndJoin(threads);
}
res.setScale(img);
return res;
}
use of mcib3d.image3d.ImageFloat in project mcib3d-core by mcib3d.
the class EdtShort method run.
/**
* @param imp
* @param thresh
* @param scaleXY
* @param scaleZ
* @return
* @throws Exception
*/
public ImageFloat run(ImageShort imp, int thresh, float scaleXY, float scaleZ, int nbCPUs) throws Exception {
int w = imp.sizeX;
int h = imp.sizeY;
int d = imp.sizeZ;
float scale = scaleZ / scaleXY;
short[][] data = imp.pixels;
// Create 32 bit floating point stack for output, s. Will also use it for g in Transformation 1.
ImageStack sStack = new ImageStack(w, h);
float[][] s = new float[d][];
for (int k = 0; k < d; k++) {
ImageProcessor ipk = new FloatProcessor(w, h);
sStack.addSlice(null, ipk);
s[k] = (float[]) ipk.getPixels();
}
float[] sk;
// Transformation 1. Use s to store g.
Step1Thread[] s1t = new Step1Thread[nbCPUs];
for (int thread = 0; thread < nbCPUs; thread++) {
s1t[thread] = new Step1Thread(thread, nbCPUs, w, h, d, thresh, s, data, scale);
s1t[thread].start();
}
try {
for (int thread = 0; thread < nbCPUs; thread++) {
s1t[thread].join();
}
} catch (InterruptedException ie) {
IJ.error("A thread was interrupted in step 1 .");
}
// Transformation 2. g (in s) -> h (in s)
Step2Thread[] s2t = new Step2Thread[nbCPUs];
for (int thread = 0; thread < nbCPUs; thread++) {
s2t[thread] = new Step2Thread(thread, nbCPUs, w, h, d, s);
s2t[thread].start();
}
try {
for (int thread = 0; thread < nbCPUs; thread++) {
s2t[thread].join();
}
} catch (InterruptedException ie) {
IJ.error("A thread was interrupted in step 2 .");
}
// check image size, if sizeZ==1 do not perform Z distance processing
if (imp.sizeZ > 1) {
Step3Thread[] s3t = new Step3Thread[nbCPUs];
for (int thread = 0; thread < nbCPUs; thread++) {
s3t[thread] = new Step3Thread(thread, nbCPUs, w, h, d, s, data, thresh, scale);
s3t[thread].start();
}
try {
for (int thread = 0; thread < nbCPUs; thread++) {
s3t[thread].join();
}
} catch (InterruptedException ie) {
IJ.error("A thread was interrupted in step 3 .");
}
}
// Find the largest distance for scaling
// Also fill in the background values.
float distMax = 0;
int wh = w * h;
float dist;
for (int k = 0; k < d; k++) {
sk = s[k];
for (int ind = 0; ind < wh; ind++) {
if (((data[k][ind] & 0xffff) <= thresh)) {
sk[ind] = 0;
} else {
dist = (float) Math.sqrt(sk[ind]) * scaleXY;
sk[ind] = dist;
distMax = (dist > distMax) ? dist : distMax;
}
}
}
ImageFloat res = (ImageFloat) ImageFloat.wrap(sStack);
res.setScale(imp);
res.setOffset(imp);
res.setMinAndMax(0, distMax);
return res;
}
Aggregations