use of mcib3d.utils.Logger.AbstractLog in project mcib3d-core by mcib3d.
the class ImageInt method adaptiveFilter.
/**
* Adaptive Filter in 3D (expermimental) Take 7 neighborhood, compute mean
* and std dev Assign mean of neighborhood with lowest std dev
*
* @param radx
* @param radz
* @param rady
* @return 3D filtered image
*/
@Deprecated
public ImageInt adaptiveFilter(float radx, float rady, float radz, int nbcpus) {
final ImageInt adaptimg2 = (ImageInt) this.createSameDimensions();
int nbToProcess = this.sizeZ;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// create kernel
final int[] ker = FastFilters3D.createKernelEllipsoid(radx, rady, radz);
int nb = 0;
for (int i = 0; i < ker.length; i++) {
nb += ker[i];
}
final int nb2 = nb;
final float radX2 = radx;
final float radY2 = rady;
final float radZ2 = radz;
// PARALLEL (Thomas Boudier)
final AtomicInteger ai = new AtomicInteger(0);
Thread[] threads = ThreadUtil.createThreadArray(nbcpus);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
ArrayUtil[] tab = new ArrayUtil[7];
// displacement to take neighborhoods
int dep = 1;
double mes;
double mins;
double si;
double me;
for (int k = ai.getAndIncrement(); k < sizeZ; k = ai.getAndIncrement()) {
for (int j = 0; j < sizeY; j++) {
for (int i = 0; i < sizeX; i++) {
tab[0] = getNeighborhoodKernel(ker, nb2, i, j, k, radX2, radY2, radZ2);
tab[1] = getNeighborhoodKernel(ker, nb2, i + dep, j, k, radX2, radY2, radZ2);
tab[2] = getNeighborhoodKernel(ker, nb2, i - dep, j, k, radX2, radY2, radZ2);
tab[3] = getNeighborhoodKernel(ker, nb2, i, j + dep, k, radX2, radY2, radZ2);
tab[4] = getNeighborhoodKernel(ker, nb2, i, j - dep, k, radX2, radY2, radZ2);
tab[5] = getNeighborhoodKernel(ker, nb2, i, j, k + dep, radX2, radY2, radZ2);
tab[6] = getNeighborhoodKernel(ker, nb2, i, j, k - dep, radX2, radY2, radZ2);
mes = 0;
mins = Float.MAX_VALUE;
for (int c = 0; c < 7; c++) {
// me = tab[c].median();
me = tab[c].getMean();
si = tab[c].getStdDev();
if (si < mins) {
mins = si;
mes = me;
}
}
adaptimg2.setPixel(i, j, k, (int) mes);
}
}
if (time != null) {
String ti = time.getFullInfo(1);
if (ti != null)
show.log("3D adaptive : " + ti);
}
}
}
};
}
ThreadUtil.startAndJoin(threads);
return adaptimg2;
}
use of mcib3d.utils.Logger.AbstractLog in project mcib3d-core by mcib3d.
the class FastFilters3D method getListMaximaFloat.
public static ArrayList<Voxel3DComparable> getListMaximaFloat(ImageFloat stackorig, float vx, float vy, float vz, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// get stack info
final float voisx = vx;
final float voisy = vy;
final float voisz = vz;
final ImageFloat ima = stackorig;
// PARALLEL
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
final ArrayList<Voxel3DComparable>[] listes = new ArrayList[n_cpus];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
listes[k] = ima.getListMaxima(voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
final ArrayList<Voxel3DComparable> liste = new ArrayList<Voxel3DComparable>();
for (ArrayList<Voxel3DComparable> li : listes) {
liste.addAll(li);
}
return liste;
}
use of mcib3d.utils.Logger.AbstractLog in project mcib3d-core by mcib3d.
the class FastFilters3D method filterFloatImage.
public static ImageFloat filterFloatImage(ImageFloat stackorig, int filter, Object3DVoxels obj, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
if ((filter == TOPHAT) || (filter == CLOSEGRAY) || (filter == OPENGRAY))
nbToProcess *= 2;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
final Object3DVoxels object = obj;
// IJ.log("Using java filtering " + voisx + " " + voisy + " " + voisz + " " + filter + " " + nbcpus);
final ImageFloat ima = stackorig;
ImageFloat res = (ImageFloat) ima.createSameDimensions();
if ((filter == MEAN) || (filter == MEDIAN) || (filter == MIN) || (filter == MAX) || (filter == MAXLOCAL) || (filter == TOPHAT) || (filter == VARIANCE) || (filter == CLOSEGRAY) || (filter == OPENGRAY)) {
// PARALLEL
final ImageFloat out = res;
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
int fi = filter;
if ((fi == TOPHAT) || (fi == OPENGRAY)) {
fi = MIN;
}
if (fi == CLOSEGRAY) {
fi = MAX;
}
final int f = fi;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
ima.filterGeneric(out, object, dec * k, dec * (k + 1), f, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
// TOPHAT MAX
if ((filter == TOPHAT) || (filter == OPENGRAY)) {
final int f2 = MAX;
final ImageFloat res2 = (ImageFloat) ima.createSameDimensions();
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
out.filterGeneric(res2, object, dec * k, dec * (k + 1), f2, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
// TOPHAT DIFFERENCE
if (filter == TOPHAT) {
res = ima.subtractImage(res2);
} else {
res = res2;
}
}
// CLOSING 2nd Step
if (filter == CLOSEGRAY) {
final int f2 = MIN;
final ImageFloat res2 = (ImageFloat) ima.createSameDimensions();
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
out.filterGeneric(res2, object, dec * k, dec * (k + 1), f2, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
res = res2;
}
} else if (filter == SOBEL) {
res = ima.sobelFilter();
} else if (filter == ADAPTIVE) {
// res = ima.adaptiveFilter(voisx, voisy, voisz, nbcpus);
}
return res;
}
use of mcib3d.utils.Logger.AbstractLog in project mcib3d-core by mcib3d.
the class FastFilters3D method filterFloatImage.
public static ImageFloat filterFloatImage(ImageFloat stackorig, int filter, float vx, float vy, float vz, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
if ((filter == TOPHAT) || (filter == CLOSEGRAY) || (filter == OPENGRAY))
nbToProcess *= 2;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// get stack info
final float voisx = vx;
final float voisy = vy;
final float voisz = vz;
final ImageFloat ima = stackorig;
ImageFloat res = (ImageFloat) ima.createSameDimensions();
if ((filter == MEAN) || (filter == MEDIAN) || (filter == MIN) || (filter == MAX) || (filter == MAXLOCAL) || (filter == TOPHAT) || (filter == VARIANCE) || (filter == CLOSEGRAY) || (filter == OPENGRAY)) {
// PARALLEL
final ImageFloat out = res;
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
int fi = filter;
if ((fi == TOPHAT) || (fi == OPENGRAY)) {
fi = MIN;
}
if (fi == CLOSEGRAY) {
fi = MAX;
}
final int f = fi;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
ima.filterGeneric(out, voisx, voisy, voisz, dec * k, dec * (k + 1), f, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
// TOPHAT MAX
if ((filter == TOPHAT) || (filter == OPENGRAY)) {
final int f2 = MAX;
final ImageFloat res2 = (ImageFloat) ima.createSameDimensions();
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
out.filterGeneric(res2, voisx, voisy, voisz, dec * k, dec * (k + 1), f2, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
// TOPHAT DIFFERENCE
if (filter == TOPHAT) {
res = ima.subtractImage(res2);
} else {
res = res2;
}
}
// CLOSING 2nd Step
if (filter == CLOSEGRAY) {
final int f2 = MIN;
final ImageFloat res2 = (ImageFloat) ima.createSameDimensions();
ai.set(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
out.filterGeneric(res2, voisx, voisy, voisz, dec * k, dec * (k + 1), f2, time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
res = res2;
}
} else if (filter == SOBEL) {
res = ima.sobelFilter();
} else if (filter == ADAPTIVE) {
// res = ima.adaptiveFilter(voisx, voisy, voisz, nbcpus);
// PARALLEL
final ImageFloat out = res;
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
show.log("Starting");
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
ima.adaptiveFilter(out, voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
show.log("Finished");
}
return res;
}
use of mcib3d.utils.Logger.AbstractLog in project mcib3d-core by mcib3d.
the class FastFilters3D method getListMaximaInt.
public static ArrayList<Voxel3DComparable> getListMaximaInt(ImageInt stackorig, float vx, float vy, float vz, int nbcpus, boolean showstatus) {
int nbToProcess = stackorig.sizeZ;
// Timer
final Chrono time = new Chrono(nbToProcess);
time.start();
final AbstractLog show = new IJStatus();
// get stack info
final float voisx = vx;
final float voisy = vy;
final float voisz = vz;
final ImageInt ima = stackorig;
// PARALLEL
final AtomicInteger ai = new AtomicInteger(0);
final int n_cpus = nbcpus == 0 ? ThreadUtil.getNbCpus() : nbcpus;
final int dec = (int) Math.ceil((double) ima.sizeZ / (double) n_cpus);
Thread[] threads = ThreadUtil.createThreadArray(n_cpus);
final ArrayList<Voxel3DComparable>[] listes = new ArrayList[n_cpus];
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
for (int k = ai.getAndIncrement(); k < n_cpus; k = ai.getAndIncrement()) {
listes[k] = ima.getListMaxima(voisx, voisy, voisz, dec * k, dec * (k + 1), time, show);
}
}
};
}
ThreadUtil.startAndJoin(threads);
final ArrayList<Voxel3DComparable> liste = new ArrayList<Voxel3DComparable>();
for (ArrayList<Voxel3DComparable> li : listes) {
liste.addAll(li);
}
return liste;
}
Aggregations