2929
3030package org .scijava .ops .image .coloc .saca ;
3131
32+ import io .scif .img .ImgOpener ;
3233import net .imglib2 .RandomAccess ;
3334import net .imglib2 .img .Img ;
3435import net .imglib2 .type .logic .BitType ;
36+ import net .imglib2 .type .numeric .real .FloatType ;
3537import net .imglib2 .type .numeric .real .DoubleType ;
3638import net .imglib2 .type .numeric .integer .UnsignedByteType ;
3739
40+ import org .scijava .io .location .FileLocation ;
3841import org .scijava .types .Nil ;
3942import org .scijava .ops .image .AbstractColocalisationTest ;
4043
41- import org .junit .jupiter .api .BeforeAll ;
4244import org .junit .jupiter .api .Test ;
4345import static org .junit .jupiter .api .Assertions .assertEquals ;
4446
@@ -57,46 +59,24 @@ public class SACATest extends AbstractColocalisationTest {
5759 142 , 118 };
5860
5961 // green and red colocalization images
60- private Img <UnsignedByteType > green ;
61- private Img <UnsignedByteType > red ;
62-
63- // green and red data slices
64- private Img <UnsignedByteType > gs ;
65- private Img <UnsignedByteType > rs ;
66-
67- // SACA heatmap z score and sig mask image containers
68- private Img <DoubleType > zscore ;
69- private Img <BitType > sigMask ;
70-
71- @ BeforeAll
72- public void setUpTest () {
73- // load colocalization data (3D)
74- green = getPositiveCorrelationImageCh1 ();
75- red = getPositiveCorrelationImageCh2 ();
76-
77- // get slice 15 from colocalization data
78- gs = ops .op ("transform.hyperSliceView" ).input (green , 2 , 15 ).outType (
79- new Nil <Img <UnsignedByteType >>()
80- {}).apply ();
81- rs = ops .op ("transform.hyperSliceView" ).input (red , 2 , 15 ).outType (
82- new Nil <Img <UnsignedByteType >>()
83- {}).apply ();
84-
85- // create image containers
86- zscore = ops .op ("create.img" ).input (gs , new DoubleType ()).outType (
87- new Nil <Img <DoubleType >>()
88- {}).apply ();
89- sigMask = ops .op ("create.img" ).input (gs , new BitType ()).outType (
90- new Nil <Img <BitType >>()
91- {}).apply ();
92- }
62+ private Img <UnsignedByteType > green = getPositiveCorrelationImageCh1 ();
63+ private Img <UnsignedByteType > red = getPositiveCorrelationImageCh2 ();
9364
9465 @ Test
9566 public void testSACAHeatmapZScore () {
9667 final double [] zscoreExpected = { 0.0 , 6.117364936585281 , 0.0 ,
9768 -1.282447034877343 , 0.0 , 6.642396454955293 , 0.0 , -1.6567255788972388 , 0.0 ,
9869 3.5385003044434877 };
9970
71+ // get slice 15 from colocalization data
72+ var gs = ops .op ("transform.hyperSliceView" ).input (green , 2 , 15 ).apply ();
73+ var rs = ops .op ("transform.hyperSliceView" ).input (red , 2 , 15 ).apply ();
74+
75+ // create image container
76+ Img <DoubleType > zscore = ops .op ("create.img" ).input (gs , new DoubleType ())
77+ .outType (new Nil <Img <DoubleType >>()
78+ {}).apply ();
79+
10080 // run SACA heatmap Z score op
10181 ops .op ("coloc.saca.heatmapZScore" ).input (gs , rs ).output (zscore ).compute ();
10282
@@ -112,19 +92,32 @@ public void testSACAHeatmapZScore() {
11292 @ Test
11393 public void testSACASigMask () {
11494 final double [] sigExpected = { 0.0 , 1.0 , 0.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 , 0.0 ,
115- 0.0 };
95+ 1.0 };
96+
97+ Img <FloatType > zscore_ref = openFloatImg ("stats/zscore_test_data.tif" );
98+
99+ // create image container
100+ Img <BitType > sigMask = ops .op ("create.img" ).input (zscore_ref , new BitType ())
101+ .outType (new Nil <Img <BitType >>()
102+ {}).apply ();
116103
117104 // run SACA significant pixel mask op
118- ops .op ("coloc.saca.sigMask" ).input (zscore ).output (sigMask ).compute ();
105+ ops .op ("coloc.saca.sigMask" ).input (zscore_ref ).output (sigMask ).compute ();
119106
120107 // get random access and assert results are equal
121108 final RandomAccess <BitType > sRA = sigMask .randomAccess ();
122109 for (int i = 0 ; i < xPositions .length ; i ++) {
123110 sRA .setPosition (xPositions [i ], 0 );
124111 sRA .setPosition (yPositions [i ], 1 );
125112 assertEquals (sigExpected [i ], sRA .get ().getRealDouble ());
126-
127113 }
114+ }
128115
116+ @ SuppressWarnings ("unchecked" )
117+ public Img <FloatType > openFloatImg (final String relPath ) {
118+ final ImgOpener opener = new ImgOpener ();
119+ String source = "src/test/resources/org/scijava/ops/image/" + relPath ;
120+ FileLocation loc = new FileLocation (source );
121+ return (Img ) opener .openImgs (loc ).get (0 );
129122 }
130123}
0 commit comments