diff --git a/pom.xml b/pom.xml index f9f936a..fa5986b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -108,6 +108,10 @@ <groupId>net.imglib2</groupId> <artifactId>imglib2-roi</artifactId> </dependency> + <dependency> + <groupId>net.imglib2</groupId> + <artifactId>imglib2-ij</artifactId> + </dependency> <dependency> <groupId>sc.fiji</groupId> <artifactId>AnalyzeSkeleton_</artifactId> diff --git a/src/test/java/ch/fmi/TrackMateWrapperTest.java b/src/test/java/ch/fmi/TrackMateWrapperTest.java new file mode 100644 index 0000000..84f0f9d --- /dev/null +++ b/src/test/java/ch/fmi/TrackMateWrapperTest.java @@ -0,0 +1,100 @@ + +package ch.fmi; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +import net.imglib2.RandomAccessibleInterval; +import net.imglib2.img.array.ArrayImgs; +import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.type.numeric.integer.UnsignedByteType; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.scijava.Context; +import org.scijava.command.CommandModule; +import org.scijava.command.CommandService; + +import ij.ImagePlus; + +public class TrackMateWrapperTest { + + private Context context; + + @Before + public void initialize() { + context = new Context(); + } + + @After + public void disposeContext() { + if (context != null) { + context.dispose(); + context = null; + } + } + + @Test + public void testTrackMate() throws InterruptedException, ExecutionException { + CommandService commandService = context.getService(CommandService.class); + + // Prepare + RandomAccessibleInterval<UnsignedByteType> img = ArrayImgs.unsignedBytes(16, + 16, 1, 1, 5); + img.getAt(5, 7, 0, 0, 0).setReal(192); + img.getAt(5, 6, 0, 0, 1).setReal(186); + img.getAt(6, 6, 0, 0, 2).setReal(180); + img.getAt(6, 7, 0, 0, 3).setReal(174); + img.getAt(5, 7, 0, 0, 4).setReal(168); + ImagePlus imp = ImageJFunctions.wrapUnsignedByte(img, "Test Image"); + assertNotNull(imp); + Map<String, Object> inputMap = new HashMap<>(); + inputMap.put("imp", imp); + inputMap.put("frameInterval", 0.5); + + // Run TrackMateWrapper + CommandModule module = commandService.run(TrackMateWrapper.class, false, + inputMap).get(); + + // Compare + int nSpotsFound = (int) module.getOutput("nSpotsFound"); + int nTracksFound = (int) module.getOutput("nTracksFound"); + double[] x = (double[]) module.getOutput("x"); + double[] y = (double[]) module.getOutput("y"); + double[] z = (double[]) module.getOutput("z"); + double[] t = (double[]) module.getOutput("t"); + double[] frame = (double[]) module.getOutput("frame"); + + assertEquals(5, nSpotsFound); + assertEquals(1, nTracksFound); + + System.out.println(Arrays.toString(x)); + System.out.println(Arrays.toString(y)); + System.out.println(Arrays.toString(z)); + System.out.println(Arrays.toString(t)); + + Arrays.sort(x); + Arrays.sort(y); + Arrays.sort(t); + Arrays.sort(frame); + + double[] x1 = { 5, 5, 5, 6, 6 }; + double[] y1 = { 6, 6, 7, 7, 7 }; + double[] z1 = { 0, 0, 0, 0, 0 }; + double[] t1 = { 0, 0.5, 1.0, 1.5, 2.0 }; + double[] frame1 = { 0, 1, 2, 3, 4 }; + + assertArrayEquals(x1, x, 0.2); + assertArrayEquals(y1, y, 0.2); + assertArrayEquals(z1, z, 0.0001); + assertArrayEquals(t1, t, 0.01); + assertArrayEquals(frame1, frame, 0.01); + } +}