Commit ed021cae authored by gonciarz's avatar gonciarz
Browse files

Merge branch 'particleTrackerWithClij2' into develop

parents 648388f6 983a99bc
......@@ -87,7 +87,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version> 16.1.0</version>
<version>27.0.1</version>
<relativePath />
</parent>
......@@ -107,6 +107,11 @@
<name>repo</name>
<url>file://${project.basedir}/repo</url>
</repository>
<repository>
<id>clij</id>
<url>http://dl.bintray.com/haesleinhuepf/clij</url>
</repository>
</repositories>
<dependencies>
......@@ -125,7 +130,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!--<scope>compile</scope>-->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.scif</groupId>
......@@ -172,16 +177,17 @@
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</dependency>
<dependency>
<groupId>net.sf.jgrapht</groupId>
<artifactId>jgrapht</artifactId>
</dependency>
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>Skeletonize3D_</artifactId>
</dependency>
<!-- 3rd party stuff -->
<dependency>
<groupId>net.sf.jgrapht</groupId>
<artifactId>jgrapht</artifactId>
<version>0.8.3</version>
</dependency>
<dependency>
<groupId>com.googlecode.efficient-java-matrix-library</groupId>
<artifactId>ejml</artifactId>
......@@ -222,6 +228,20 @@
<version>2.4.0</version>
</dependency>
<!-- Exclude com.google.android.tools since it conflicts with same symbols from junit -->
<dependency>
<groupId>net.haesleinhuepf</groupId>
<artifactId>clij2_</artifactId>
<version>2.1.4.10</version>
<exclusions>
<exclusion>
<groupId>com.google.android.tools</groupId>
<artifactId>dx</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- These dependencies are temporarily kept in mosaic maven -->
<dependency>
<groupId>net.jgeom.nurbs</groupId>
......@@ -272,7 +292,7 @@
<resource>
<directory>target</directory>
<includes>
<include>${project.artifactId}-${project.version}_Full.jar</include>
<include>${project.artifactId}-${project.version}.jar</include>
</includes>
<filtering>false</filtering>
</resource>
......
......@@ -34,6 +34,7 @@ public class FeaturePointDetector {
private int iRadius;
private float iAbsIntensityThreshold;
private Mode iThresholdMode = Mode.PERCENTILE_MODE;
private boolean iUseCLIJ = false;
// Internal stuff
private Vector<Particle> iParticles;
......@@ -47,7 +48,7 @@ public class FeaturePointDetector {
public FeaturePointDetector(float aGlobalMax, float aGlobalMin) {
iGlobalMax = aGlobalMax;
iGlobalMin = aGlobalMin;
setDetectionParameters(0.001f, 0.005f, 3, 0.0f, false);
setDetectionParameters(0.001f, 0.005f, 3, 0.0f, false, false);
}
/**
......@@ -97,7 +98,7 @@ public class FeaturePointDetector {
* According to the pre determend global min and max pixel value in the movie. <br>
* All pixel intensity values I are normalized as (I-gMin)/(gMax-gMin)
*
* @param ip ImageProcessor to be normalized
* @param is ImageProcessor to be normalized
* @param global_min
* @param global_max
*/
......@@ -116,7 +117,7 @@ public class FeaturePointDetector {
* If not, the threshold is set to its absolute (normalized) value. There is only one parameter
* used, either percent or aIntensityThreshold depending on the threshold mode.
*
* @param ip ImageProcessor after conversion, normalization and restoration
* @param ips ImageProcessor after conversion, normalization and restoration
* @param percent the upper rth percentile to be considered as candidate Particles
* @param absIntensityThreshold2 a intensity value which defines a threshold.
* @return
......@@ -188,12 +189,12 @@ public class FeaturePointDetector {
* Adds each found <code>Particle</code> to the <code>particles</code> array. <br>
* Mostly adapted from Ingo Oppermann implementation
*
* @param ip ImageProcessor, should be after conversion, normalization and restoration
* @param ips ImageProcessor, should be after conversion, normalization and restoration
*/
private void pointLocationsEstimation(ImageStack ips) {
float threshold = findThreshold(ips, iPercentile, iAbsIntensityThreshold);
/* do a grayscale dilation */
final ImageStack dilated_ips = DilateImage.dilate(ips, iRadius, 4);
final ImageStack dilated_ips = DilateImage.dilate(ips, iRadius, 4, iUseCLIJ);
// new StackWindow(new ImagePlus("dilated ", dilated_ips));
iParticles = new Vector<Particle>();
/* loop over all pixels */
......@@ -617,7 +618,7 @@ public class FeaturePointDetector {
*
* @see #generateDilationMasks(int)
*/
public boolean setDetectionParameters(double cutoff, float percentile, int radius, float Threshold, boolean absolute) {
public boolean setDetectionParameters(double cutoff, float percentile, int radius, float Threshold, boolean absolute, boolean aUseCLIJ) {
final boolean changed = (radius != iRadius || cutoff != iCutoff || (percentile != iPercentile));// && intThreshold != absIntensityThreshold || mode != getThresholdMode() || thsmode != getThresholdMode();
iCutoff = cutoff;
......@@ -630,8 +631,10 @@ public class FeaturePointDetector {
else {
iThresholdMode = Mode.PERCENTILE_MODE;
}
logger.info("Detection options: radius=" + iRadius + " cutoff=" + iCutoff + " percentile=" + iPercentile + " threshold=" + iAbsIntensityThreshold + " mode=" + (absolute ? "THRESHOLD" : "PERCENTILE"));
iUseCLIJ = aUseCLIJ;
logger.info("Detection options: radius=" + iRadius + " cutoff=" + iCutoff + " percentile=" + iPercentile + " threshold=" + iAbsIntensityThreshold + " mode=" + (absolute ? "THRESHOLD" : "PERCENTILE") + " useCLIJ=" + iUseCLIJ);
// create Mask for Dilation with the user defined radius
generateDilationMasks(iRadius);
......
......@@ -36,8 +36,9 @@ public class GUIhelper {
final float per = ((float) gd.getNextNumber()) / 100;
final float intThreshold = per * 100;
final boolean absolute = gd.getNextBoolean();
final boolean useCLIJ = gd.getNextBoolean();
return fpd.setDetectionParameters(cut, per, rad, intThreshold, absolute);
return fpd.setDetectionParameters(cut, per, rad, intThreshold, absolute, useCLIJ);
}
/**
......@@ -56,8 +57,9 @@ public class GUIhelper {
final float per = (Float.parseFloat((vec.elementAt(2)).getText())) / 100;
final float intThreshold = per * 100;
final boolean absolute = vecb.elementAt(0).getState();
final boolean useCLIJ = vecb.elementAt(1).getState();
return fpd.setDetectionParameters(cut, per, rad, intThreshold, absolute);
return fpd.setDetectionParameters(cut, per, rad, intThreshold, absolute, useCLIJ);
}
public static void addUserDefinedParametersDialog(GenericDialog gd, FeaturePointDetector fpd) {
......@@ -68,6 +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);
}
......
......@@ -2,47 +2,75 @@ 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;
import java.util.concurrent.atomic.AtomicInteger;
public class DilateImage {
private static final Logger logger = Logger.getLogger(DilateImage.class);
/**
* Dilates all values larger than <code>threshold</code> and returns a copy of the input image.
* 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 ip ImageProcessor to do the dilation with
* @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) {
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();
}
for (final Thread t : threadsVector) {
try {
t.join();
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));
}
catch (final InterruptedException ie) {
IJ.showMessage("Calculation interrupted. An error occured in parallel dilation:\n" + ie.getMessage());
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]);
}
logger.debug("dilate stop");
return dilated_ips;
}
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]);
}
return dilated_ips;
// 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();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment