11package net .imglib2 .algorithm .math ;
22
3- import static net .imglib2 .algorithm .math .ImgMath .Add ;
4- import static net .imglib2 .algorithm .math .ImgMath .Sub ;
5- import static net .imglib2 .algorithm .math .ImgMath .Mul ;
6- import static net .imglib2 .algorithm .math .ImgMath .Div ;
7- import static net .imglib2 .algorithm .math .ImgMath .Max ;
8- import static net .imglib2 .algorithm .math .ImgMath .Min ;
9- import static net .imglib2 .algorithm .math .ImgMath .Neg ;
10- import static net .imglib2 .algorithm .math .ImgMath .Let ;
11- import static net .imglib2 .algorithm .math .ImgMath .Var ;
3+ import static net .imglib2 .algorithm .math .ImgMath .add ;
4+ import static net .imglib2 .algorithm .math .ImgMath .sub ;
5+ import static net .imglib2 .algorithm .math .ImgMath .mul ;
6+ import static net .imglib2 .algorithm .math .ImgMath .div ;
7+ import static net .imglib2 .algorithm .math .ImgMath .max ;
8+ import static net .imglib2 .algorithm .math .ImgMath .min ;
9+ import static net .imglib2 .algorithm .math .ImgMath .let ;
10+ import static net .imglib2 .algorithm .math .ImgMath .var ;
1211import static org .junit .Assert .assertTrue ;
1312
1413import org .junit .Test ;
@@ -51,7 +50,7 @@ protected static boolean testImgMath1( )
5150 final ArrayImg < FloatType , ? > brightness = new ArrayImgFactory < FloatType >( new FloatType () ).create ( dims );
5251
5352 try {
54- new ImgMath ( new Div ( new Max ( red , new Max ( green , blue ) ), 3.0 ) ).into ( brightness );
53+ new ImgMath ( div ( max ( red , max ( green , blue ) ), 3.0 ) ).into ( brightness );
5554 } catch (Exception e ) {
5655 e .printStackTrace ();
5756 }
@@ -87,7 +86,7 @@ protected static boolean testIterationOrder() {
8786 // Divide pixels from each other (better than subtract: zero sum would be the default in case of error)
8887 final ArrayImg < LongType , ? > img3 = new ArrayImgFactory <>( new LongType () ).create ( img1 );
8988 try {
90- new ImgMath ( new Div ( img1 , img2 ) ).into ( img3 );
89+ new ImgMath ( div ( img1 , img2 ) ).into ( img3 );
9190 } catch (Exception e ) {
9291 e .printStackTrace ();
9392 }
@@ -123,7 +122,7 @@ protected static boolean comparePerformance( final int n_iterations ) {
123122 for ( int i =0 ; i < n_iterations ; ++i ) {
124123 final long t0 = System .nanoTime ();
125124 try {
126- new ImgMath ( new Div ( new Max ( red , new Max ( green , blue ) ), 3.0 ) ).into ( brightness );
125+ new ImgMath ( div ( max ( red , max ( green , blue ) ), 3.0 ) ).into ( brightness );
127126 } catch (Exception e ) {
128127 e .printStackTrace ();
129128 }
@@ -186,7 +185,7 @@ protected static boolean testVarags() {
186185 final ArrayImg < FloatType , ? > brightness = new ArrayImgFactory < FloatType >( new FloatType () ).create ( dims );
187186
188187 try {
189- new ImgMath ( new Div ( new Max ( red , green , blue ), 3.0 ) ).into ( brightness );
188+ new ImgMath ( div ( max ( red , green , blue ), 3.0 ) ).into ( brightness );
190189 } catch (Exception e ) {
191190 e .printStackTrace ();
192191 }
@@ -201,36 +200,13 @@ protected static boolean testVarags() {
201200 return 100 * 100 * 100 * 10 == sum ;
202201 }
203202
204- static protected boolean testNeg () {
205- final ArrayImg < FloatType , ? > in = new ArrayImgFactory < FloatType >( new FloatType () ).create ( new long []{ 10 , 10 } );
206- for ( final FloatType t : in )
207- t .setOne ();
208- final ArrayImg < FloatType , ? > out = new ArrayImgFactory < FloatType >( new FloatType () ).create ( new long []{ 10 , 10 } );
209-
210- try {
211- new ImgMath ( new Neg ( in ) ).into ( out );
212- } catch (Exception e ) {
213- e .printStackTrace ();
214- }
215-
216- double sum = 0 ;
217-
218- for ( final FloatType t : out )
219- sum += t .getRealDouble ();
220-
221- System .out .println ( "Sum Neg: " + sum );
222-
223-
224- return out .dimension ( 0 ) * out .dimension ( 1 ) == -sum ;
225- }
226-
227203 protected boolean testLetOneLevel () {
228204
229205 final ArrayImg < FloatType , ? > img = new ArrayImgFactory < FloatType >( new FloatType () ).create ( new long []{ 10 , 10 } );
230206 final ArrayImg < FloatType , ? > target = new ArrayImgFactory < FloatType >(new FloatType () ).create ( img );
231207
232208 try {
233- new ImgMath ( new Let ( "one" , 1 , new Add ( img , new Var ( "one" ) ) ) ).into ( target );
209+ new ImgMath ( let ( "one" , 1 , add ( img , var ( "one" ) ) ) ).into ( target );
234210 } catch (Exception e ) {
235211 e .printStackTrace ();
236212 }
@@ -250,10 +226,10 @@ protected boolean testLetTwoLevels() {
250226 final ArrayImg < FloatType , ? > target = new ArrayImgFactory < FloatType >(new FloatType () ).create ( img );
251227
252228 try {
253- new ImgMath ( new Add ( new Let ( "one" , 1 ,
254- new Add ( img , new Var ( "one" ) ) ),
255- new Let ( "two" , 2 ,
256- new Add ( new Var ( "two" ), 0 ) ) ) ).into ( target );
229+ new ImgMath ( add ( let ( "one" , 1 ,
230+ add ( img , var ( "one" ) ) ),
231+ let ( "two" , 2 ,
232+ add ( var ( "two" ), 0 ) ) ) ).into ( target );
257233 } catch (Exception e ) {
258234 e .printStackTrace ();
259235 }
@@ -276,9 +252,9 @@ protected boolean testMultiLet() {
276252 t .setReal ( 100.0d );
277253
278254 try {
279- new ImgMath ( new Let ( "pixel" , img ,
280- "constant" , 10.0d ,
281- new Add ( new Var ( "pixel" ), new Var ( "constant" ) ) ) ).into ( target );
255+ new ImgMath ( let ( "pixel" , img ,
256+ "constant" , 10.0d ,
257+ add ( var ( "pixel" ), var ( "constant" ) ) ) ).into ( target );
282258 } catch (Exception e ) {
283259 e .printStackTrace ();
284260 }
@@ -301,10 +277,10 @@ protected boolean testNestedMultiLet() {
301277 t .setReal ( 100.0d );
302278
303279 try {
304- new ImgMath ( new Let ( "pixel" , img ,
305- "constant" , 10.0d ,
306- new Add ( new Var ( "pixel" ), new Let ( "pixel2" , img ,
307- new Sub ( new Var ( "pixel2" ), new Var ( "constant" ) ) ) ) ) ).into ( target );
280+ new ImgMath ( let ( "pixel" , img ,
281+ "constant" , 10.0d ,
282+ add ( var ( "pixel" ), let ( "pixel2" , img ,
283+ sub ( var ( "pixel2" ), var ( "constant" ) ) ) ) ) ).into ( target );
308284 } catch (Exception e ) {
309285 e .printStackTrace ();
310286 }
@@ -319,31 +295,26 @@ protected boolean testNestedMultiLet() {
319295 }
320296
321297
322- // @Test
298+ @ Test
323299 public void test1 () {
324300 assertTrue ( testImgMath1 () );
325301 }
326302
327- // @Test
303+ @ Test
328304 public void test2 () {
329305 assertTrue ( testIterationOrder () );
330306 }
331307
332- // @Test
308+ @ Test
333309 public void test3 () {
334310 assertTrue ( comparePerformance ( 30 ) );
335311 }
336312
337- // @Test
313+ @ Test
338314 public void test4 () {
339315 assertTrue ( testVarags () );
340316 }
341317
342- //@Test
343- public void test5 () {
344- assertTrue ( testNeg () );
345- }
346-
347318 @ Test
348319 public void testLet1Simple () {
349320 assertTrue ( testLetOneLevel () );
0 commit comments