2929
3030package net .imagej .ops .deconvolve ;
3131
32- import java .util .Iterator ;
3332import java .util .concurrent .ExecutorService ;
3433import java .util .function .BiFunction ;
3534import java .util .function .Function ;
3635
36+ import net .imglib2 .Cursor ;
3737import net .imglib2 .Dimensions ;
38+ import net .imglib2 .IterableInterval ;
39+ import net .imglib2 .RandomAccess ;
3840import net .imglib2 .RandomAccessibleInterval ;
3941import net .imglib2 .img .Img ;
4042import net .imglib2 .type .numeric .ComplexType ;
4446import org .scijava .Priority ;
4547import org .scijava .ops .OpDependency ;
4648import org .scijava .ops .core .Op ;
47- import org .scijava .ops .core .computer .Computer3 ;
4849import org .scijava .ops .core .computer .Computer5 ;
4950import org .scijava .ops .core .computer .Computer7 ;
51+ import org .scijava .ops .core .inplace .Inplace3First ;
5052import org .scijava .param .Parameter ;
5153import org .scijava .plugin .Plugin ;
5254import org .scijava .struct .ItemIO ;
@@ -88,14 +90,17 @@ public class RichardsonLucyCorrection<I extends RealType<I>, O extends RealType<
8890
8991 //TODO is this allowed (to divide an O by an I)? Should it be?
9092// @OpDependency(name = "math.divide") TODO: allow the matcher to fix this
91- private Computer3 <Iterable <O >, Iterable <I >, Double , Iterable <O >> divide = (in1 , in2 , in3 , out ) -> {
92- Iterator <O > itr1 = in1 .iterator ();
93- Iterator <I > itr2 = in2 .iterator ();
94- Iterator <O > itrout = out .iterator ();
93+ private Inplace3First <IterableInterval <O >, RandomAccessibleInterval <I >, Double > divide = (io , in2 , in3 ) -> {
94+ Cursor <O > ioCursor = io .cursor ();
95+ RandomAccess <I > inRA = in2 .randomAccess ();
9596
96- while (itr1 .hasNext () && itr2 .hasNext () && itrout .hasNext ()) {
97- Double val2 = itr2 .next ().getRealDouble ();
98- itrout .next ().setReal (val2 == 0 ? in3 : itr1 .next ().getRealDouble () / val2 );
97+ while (ioCursor .hasNext ()) {
98+ Double val1 = ioCursor .next ().getRealDouble ();
99+ inRA .setPosition (ioCursor );
100+ Double val2 = inRA .get ().getRealDouble ();
101+ if (val2 != 0 ) System .out .println (val2 );
102+ if (val1 == 0 ) ioCursor .next ().setReal (in3 );
103+ else ioCursor .next ().setReal (val2 / val1 );
99104 }
100105 };
101106
@@ -115,10 +120,8 @@ public void compute(RandomAccessibleInterval<I> observed,
115120 ExecutorService es ,
116121 RandomAccessibleInterval <O > correction )
117122 {
118- RandomAccessibleInterval <O > copyReblurred = copy .apply (reblurred );
119-
120123 // divide observed image by reblurred
121- divide .compute (Views .iterable (reblurred ), Views . iterable ( observed ) , 0.0 , Views . iterable ( copyReblurred ) );
124+ divide .mutate (Views .iterable (reblurred ), observed , 0.0 );
122125
123126 // correlate with psf to compute the correction factor
124127 // Note: FFT of psf is pre-computed and set as an input parameter of the op
0 commit comments