use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class IntImage3D method morpho3Dbin.
/**
* 3D binary morphology - dilatation of objects
*
* @param fond Value of background
* @param obj Value of objects
* @param rx Radius in x
* @param ry Radius in x
* @param rz Radius in x
* @return Dilated image
*/
private IntImage3D morpho3Dbin(int obj, int fond, float rx, float ry, float rz) {
int p;
IntImage3D morphoimg = new IntImage3D(sizex, sizey, sizez, type);
// create kernel
int[] ker = createKernelEllipsoid(rx, ry, rz);
int nb = 0;
for (int i = 0; i < ker.length; i++) {
nb += ker[i];
}
ArrayUtil tab;
for (int k = 0; k < sizez; k++) {
if (this.showStatus) {
IJ.showStatus("3D Binary Morphology : " + (int) (100 * k / sizez) + "%");
}
for (int j = 0; j < sizey; j++) {
for (int i = 0; i < sizex; i++) {
p = getPixel(i, j, k);
if (p == obj) {
morphoimg.putPixel(i, j, k, p);
} else {
tab = this.getNeighborhoodKernel(ker, nb, i, j, k, rx, ry, rz);
if (!tab.hasOnlyValue(fond)) {
morphoimg.putPixel(i, j, k, obj);
} else {
morphoimg.putPixel(i, j, k, fond);
}
}
}
}
}
return morphoimg;
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class IntImage3D method createLocalMaximaImage.
/**
* Création d'une image des maxima locaux dans un voisiange donne
*
* @param voisx taille voisinage en x
* @param voisy taille voisinage en y
* @param voisz taille voisinage en z
* @param th threshold image (255)
* @param keep
* @return Image des maxima locaux
*/
public IntImage3D createLocalMaximaImage(float voisx, float voisy, float voisz, int th, boolean keep) {
// create kernel
int[] ker = createKernelEllipsoid(voisx, voisy, voisz);
int nb = 0;
for (int i = 0; i < ker.length; i++) {
nb += ker[i];
}
int pix;
int vx = (int) Math.ceil(voisx);
int vy = (int) Math.ceil(voisy);
int vz = (int) Math.ceil(voisz);
IntImage3D maxima = new IntImage3D(sizex, sizey, sizez, type);
// parcours de l'image3D
ArrayUtil tab;
for (int k = vz; k < sizez - vz; k++) {
if (this.showStatus) {
IJ.showStatus("3D Max Local : " + (int) (100 * k / sizez) + "%");
}
for (int j = vy; j < sizey - vy; j++) {
for (int i = vx; i < sizex - vx; i++) {
pix = getPixel(i, j, k);
if (pix > th) {
tab = getNeighborhoodKernel(ker, nb, i, j, k, voisx, voisy, voisz);
if (tab.getMaximum() == pix) {
// IJ.log(""+i+" "+j+" "+k+" "+pix);
if (!keep) {
maxima.putPixel(i, j, k, 255);
} else {
maxima.putPixel(i, j, k, pix);
}
}
}
}
}
}
return maxima;
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class IntImage3D method grayErosion.
/**
* @param ker
* @return
*/
public IntImage3D grayErosion(final IntImage3D ker) {
final IntImage3D erode = new IntImage3D(sizex, sizey, sizez, type);
final IntImage3D ker2 = new IntImage3D(ker);
final int vx = ker.getSizex();
final int vy = ker.getSizey();
final int vz = ker.getSizez();
// PARALLEL
final AtomicInteger ai = new AtomicInteger(0);
Thread[] threads = ThreadUtil.createThreadArray(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
ArrayUtil tab;
int res = 0;
int val = 0;
int x0;
int x1;
int y0;
int y1;
int z0;
int z1;
for (int z = ai.getAndIncrement(); z < sizez; z = ai.getAndIncrement()) {
if (showStatus) {
IJ.showStatus("3D Gray Erosion : " + (int) (100 * z / sizez) + "%");
}
for (int y = 0; y < sizey; y++) {
for (int x = 0; x < sizex; x++) {
res = Integer.MAX_VALUE;
x0 = x - vx;
x1 = x + vx;
y0 = y - vy;
y1 = y + vy;
z0 = z - vz;
z1 = z + vz;
for (int k = z0; k <= z1; k++) {
for (int j = y0; j <= y1; j++) {
for (int i = x0; i <= x1; i++) {
if (i >= 0 && j >= 0 && k >= 0 && i < sizex && j < sizey && k < sizez) {
val = getPixel(i, j, k) - ker.getPixel(i - x0, j - y0, k - z0);
if (val < res) {
res = val;
}
}
}
}
}
erode.putPixel(x, y, z, res);
}
}
}
}
};
}
ThreadUtil.startAndJoin(threads);
return erode;
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class IntImage3D method gradient.
/**
* The gradient of the image in a given direction (sobel)
*
* @param axis x,y, or z
* @return the gradient image
*/
public IntImage3D gradient(int axis) {
IntImage3D res = new IntImage3D(sizex, sizey, sizez);
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++) {
if (this.showStatus) {
IJ.showStatus("3D Sobel : " + (int) (100 * k / sizez) + "%");
}
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);
if (axis == XAXIS) {
edge = ex;
} else if (axis == YAXIS) {
edge = ey;
} else if (axis == ZAXIS) {
edge = ez;
} else {
edge = 0;
}
if (edge > 65535) {
edge = 65535;
}
res.putPixel(i, j, k, (int) edge);
}
}
}
return res;
}
use of mcib3d.utils.ArrayUtil in project mcib3d-core by mcib3d.
the class IntImage3D method varianceFilter.
/**
* Variance Filter in 3D
*
* @param radx radius in x
* @param rady radius in y
* @param radz radius in z
* @return 3D variance image
*/
public RealImage3D varianceFilter(float radx, float rady, float radz) {
RealImage3D varimg = null;
varimg = new RealImage3D(sizex, sizey, sizez);
final RealImage3D varimg2 = varimg;
// create kernel
final int[] ker = 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
final AtomicInteger ai = new AtomicInteger(0);
Thread[] threads = ThreadUtil.createThreadArray(0);
for (int ithread = 0; ithread < threads.length; ithread++) {
threads[ithread] = new Thread() {
@Override
public void run() {
// median filter
ArrayUtil tab;
for (int k = ai.getAndIncrement(); k < sizez; k = ai.getAndIncrement()) {
if (showStatus) {
IJ.showStatus("3D Variance : " + (int) (100 * k / sizez) + "%");
}
for (int j = 0; j < sizey; j++) {
for (int i = 0; i < sizex; i++) {
tab = getNeighborhoodKernel(ker, nb2, i, j, k, radx2, rady2, radz2);
varimg2.putPixel(i, j, k, (int) tab.getVariance2());
}
}
}
}
};
}
ThreadUtil.startAndJoin(threads);
return varimg2;
}
Aggregations