Skip to content
Snippets Groups Projects
Commit aa34621b authored by Krzysztof Gonciarz's avatar Krzysztof Gonciarz
Browse files

CLIJ2 installation check

parent 983a99bc
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ import mosaic.core.imageUtils.convolution.Kernel1D;
import mosaic.core.imageUtils.convolution.Kernel2D;
import mosaic.core.imageUtils.convolution.Kernel3D;
import mosaic.core.utils.DilateImage;
import mosaic.core.utils.DilateImageClij;
/**
* FeaturePointDetector detects the "real" particles in provided frames.
......@@ -35,6 +35,7 @@ public class FeaturePointDetector {
private float iAbsIntensityThreshold;
private Mode iThresholdMode = Mode.PERCENTILE_MODE;
private boolean iUseCLIJ = false;
private boolean iIsCLIJavailable = false;
// Internal stuff
private Vector<Particle> iParticles;
......@@ -194,8 +195,13 @@ public class FeaturePointDetector {
private void pointLocationsEstimation(ImageStack ips) {
float threshold = findThreshold(ips, iPercentile, iAbsIntensityThreshold);
/* do a grayscale dilation */
final ImageStack dilated_ips = DilateImage.dilate(ips, iRadius, 4, iUseCLIJ);
final ImageStack dilated_ips = (iIsCLIJavailable && iUseCLIJ) ?
DilateImageClij.dilate(ips, iRadius) :
DilateImage.dilate(ips, iRadius, 4);
// new StackWindow(new ImagePlus("dilated ", dilated_ips));
iParticles = new Vector<Particle>();
/* loop over all pixels */
final int height = ips.getHeight();
......@@ -634,7 +640,16 @@ public class FeaturePointDetector {
iUseCLIJ = aUseCLIJ;
logger.info("Detection options: radius=" + iRadius + " cutoff=" + iCutoff + " percentile=" + iPercentile + " threshold=" + iAbsIntensityThreshold + " mode=" + (absolute ? "THRESHOLD" : "PERCENTILE") + " useCLIJ=" + iUseCLIJ);
try {
net.haesleinhuepf.clij2.CLIJ2.getInstance();
iIsCLIJavailable = true;
}
catch (final NoClassDefFoundError err) {
iIsCLIJavailable = false;
}
logger.info("Detection options: radius=" + iRadius + " cutoff=" + iCutoff + " percentile=" + iPercentile + " threshold=" + iAbsIntensityThreshold + " mode=" + (absolute ? "THRESHOLD" : "PERCENTILE") + " useCLIJ=" + iUseCLIJ + " clijAvailabe=" + iIsCLIJavailable);
System.out.println("Detection options: radius=" + iRadius + " cutoff=" + iCutoff + " percentile=" + iPercentile + " threshold=" + iAbsIntensityThreshold + " mode=" + (absolute ? "THRESHOLD" : "PERCENTILE") + " useCLIJ=" + iUseCLIJ + " clijAvailabe=" + iIsCLIJavailable);
// create Mask for Dilation with the user defined radius
generateDilationMasks(iRadius);
......
......@@ -70,7 +70,7 @@ public class GUIhelper {
gd.addNumericField("Per/Abs", fpd.getPercentile() * 100, 3, 7, null);
gd.addCheckbox("Absolute", fpd.getThresholdMode() == FeaturePointDetector.Mode.ABS_THRESHOLD_MODE);
gd.addCheckbox("Accelerate_with_CLIJ2 (experimental)", false);
gd.addCheckbox("Accelerate_with_CLIJ2 (experimental 2D only)", false);
}
......
......@@ -2,12 +2,9 @@ package mosaic.core.utils;
import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.process.FloatProcessor;
import ij.process.ImageProcessor;
import net.haesleinhuepf.clij2.CLIJ2;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import org.apache.log4j.Logger;
import java.util.Vector;
......@@ -25,52 +22,33 @@ public class DilateImage {
* @param ips ImageProcessor to do the dilation with
* @return the dilated copy of the given <code>ImageProcessor</code>
*/
public static ImageStack dilate(ImageStack ips, int radius, int number_of_threads, boolean aUseCLIJ) {
if (!aUseCLIJ) {
logger.debug("dilate start");
final FloatProcessor[] dilated_procs = new FloatProcessor[ips.getSize()];
final AtomicInteger z = new AtomicInteger(-1);
final Vector<Thread> threadsVector = new Vector<Thread>(number_of_threads);
for (int thread_counter = 0; thread_counter < number_of_threads; thread_counter++) {
threadsVector.add(new DilateThread(ips, radius, dilated_procs, z));
}
for (final Thread t : threadsVector) {
t.start();
}
logger.debug("Threads started");
for (final Thread t : threadsVector) {
try {
t.join();
} catch (final InterruptedException ie) {
IJ.showMessage("Calculation interrupted. An error occured in parallel dilation:\n" + ie.getMessage());
}
}
logger.debug("dilate threads done");
final ImageStack dilated_ips = new ImageStack(ips.getWidth(), ips.getHeight());
for (int s = 0; s < ips.getSize(); s++) {
dilated_ips.addSlice(null, dilated_procs[s]);
public static ImageStack dilate(ImageStack ips, int radius, int number_of_threads) {
logger.debug("dilate start");
final FloatProcessor[] dilated_procs = new FloatProcessor[ips.getSize()];
final AtomicInteger z = new AtomicInteger(-1);
final Vector<Thread> threadsVector = new Vector<Thread>(number_of_threads);
for (int thread_counter = 0; thread_counter < number_of_threads; thread_counter++) {
threadsVector.add(new DilateThread(ips, radius, dilated_procs, z));
}
for (final Thread t : threadsVector) {
t.start();
}
logger.debug("Threads started");
for (final Thread t : threadsVector) {
try {
t.join();
} catch (final InterruptedException ie) {
IJ.showMessage("Calculation interrupted. An error occured in parallel dilation:\n" + ie.getMessage());
}
logger.debug("dilate stop");
return dilated_ips;
}
logger.debug("dilate threads done");
final ImageStack dilated_ips = new ImageStack(ips.getWidth(), ips.getHeight());
for (int s = 0; s < ips.getSize(); s++) {
dilated_ips.addSlice(null, dilated_procs[s]);
}
logger.debug("dilate stop");
// get CLIJ2 instance with default device
CLIJ2 clij2 = CLIJ2.getInstance();
// push image and create empty one for result (with same parameters as input image)
ClearCLBuffer imgBuffer = clij2.push(new ImagePlus("", ips));
ClearCLBuffer outBuffer = clij2.create(imgBuffer);
// Run kernel
logger.debug("maximum2dSphere before");
clij2.maximum2DSphere(imgBuffer, outBuffer, radius, radius);
logger.debug("maximum2dSphere after");
// Get output and clear CLIJ2 buffers
ImagePlus imgRes = clij2.pull(outBuffer);
clij2.clear();
return imgRes.getImageStack();
return dilated_ips;
}
/**
......
package mosaic.core.utils;
import ij.ImagePlus;
import ij.ImageStack;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clij2.CLIJ2;
import org.apache.log4j.Logger;
public class DilateImageClij {
private static final Logger logger = Logger.getLogger(DilateImageClij.class);
/**
* Dilates all values and returns a copy of the input image.
* A spherical structuring element of radius <code>radius</code> is used.
* Adapted as is from Ingo Oppermann implementation
*
* @param ips ImageProcessor to do the dilation with
* @return the dilated copy of the given <code>ImageProcessor</code>
*/
public static ImageStack dilate(ImageStack ips, int radius) {
// get CLIJ2 instance with default device
CLIJ2 clij2 = CLIJ2.getInstance();
// push image and create empty one for result (with same parameters as input image)
ClearCLBuffer imgBuffer = clij2.push(new ImagePlus("", ips));
ClearCLBuffer outBuffer = clij2.create(imgBuffer);
// Run kernel
logger.debug("maximum2dSphere before");
clij2.maximum2DSphere(imgBuffer, outBuffer, radius, radius);
logger.debug("maximum2dSphere after");
// Get output and clear CLIJ2 buffers
ImagePlus imgRes = clij2.pull(outBuffer);
clij2.clear();
return imgRes.getImageStack();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment