use of mcib3d.utils.ThreadRunner 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.utils.ThreadRunner in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryErodeRad1.
private static ImageByte binaryErodeRad1(final ImageInt in, final float thld, int nbCPUs) {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
final ImageByte min = new ImageByte("min", in.sizeX, in.sizeY, in.sizeZ);
final ThreadRunner tr = new ThreadRunner(0, in.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 < in.sizeY; y++) {
for (int x = 0; x < in.sizeX; x++) {
if (minRad1(in, thld, x, y, z)) {
min.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr.startAndJoin();
min.setScale(in);
min.setOffset(in);
return min;
}
use of mcib3d.utils.ThreadRunner in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryCloseRad1.
private static ImageByte binaryCloseRad1(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 (maxRad1(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() {
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 (minRad1(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.utils.ThreadRunner in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryOpenRad1.
private static ImageByte binaryOpenRad1(final ImageInt in, final float thld, int nbCPUs) {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
final ImageByte min = new ImageByte("min", in.sizeX, in.sizeY, in.sizeZ);
final ThreadRunner tr = new ThreadRunner(0, in.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 < in.sizeY; y++) {
for (int x = 0; x < in.sizeX; x++) {
if (minRad1(in, thld, x, y, z)) {
min.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr.startAndJoin();
final ImageByte open = new ImageByte(in.getTitle() + "::open", in.sizeX, in.sizeY, in.sizeZ);
final ThreadRunner tr2 = new ThreadRunner(0, in.sizeZ, nbCPUs);
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 (maxRad1(min, 1, x, y, z)) {
open.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr2.startAndJoin();
min.closeImagePlus();
open.setScale(in);
open.setOffset(in);
return open;
}
use of mcib3d.utils.ThreadRunner in project mcib3d-core by mcib3d.
the class BinaryMorpho method binaryDilateRad1.
private static ImageByte binaryDilateRad1(final ImageInt in_, final float thld, int nbCPUs) {
if (nbCPUs == 0) {
nbCPUs = ThreadUtil.getNbCpus();
}
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, in.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 < in.sizeY; y++) {
for (int x = 0; x < in.sizeX; x++) {
if (maxRad1(in, thld, x, y, z)) {
max.pixels[z][x + y * in.sizeX] = (byte) 255;
}
}
}
}
}
});
}
tr.startAndJoin();
max.setScale(in);
max.setOffset(in);
return max;
}
Aggregations