Search in sources :

Example 6 with ThreadRunner

use of mcib3d.utils.ThreadRunner in project mcib3d-core by mcib3d.

the class BinaryMorpho method binaryDilateRad1diag.

private static ImageByte binaryDilateRad1diag(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 (maxRad15(in, thld, x, y, z)) {
                                max.pixels[z][x + y * in.sizeX] = (byte) 255;
                            }
                        }
                    }
                }
            }
        });
    }
    tr.startAndJoin();
    max.setScale(in);
    max.setOffset(in);
    return max;
}
Also used : ImageByte(mcib3d.image3d.ImageByte) ThreadRunner(mcib3d.utils.ThreadRunner) ImageInt(mcib3d.image3d.ImageInt)

Aggregations

ImageByte (mcib3d.image3d.ImageByte)6 ThreadRunner (mcib3d.utils.ThreadRunner)6 ImageInt (mcib3d.image3d.ImageInt)4