3838
3939import org .scijava .concurrent .Parallelization ;
4040import org .scijava .function .Computers ;
41+ import org .scijava .ops .spi .Nullable ;
4142import org .scijava .ops .spi .OpDependency ;
4243
4344import org .scijava .ops .image .coloc .ShuffledView ;
@@ -69,15 +70,23 @@ public class DefaultPValue<T extends RealType<T>, U extends RealType<U>> impleme
6970 * @param image2 the second image
7071 * @param op the op
7172 * @param nrRandomizations the number of randomizations
72- * @param psfSize the psf size
73+ * @param psfSize Size of blocks for random shufflings.
7374 * @param seed the seed
7475 * @param output the output
7576 */
7677 @ Override
7778 public void compute (final RandomAccessibleInterval <T > image1 , final RandomAccessibleInterval <U > image2 ,
7879 final BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double > op ,
79- final Integer nrRandomizations , final Dimensions psfSize , final Long seed ,
80+ @ Nullable Integer nrRandomizations , @ Nullable Dimensions psfSize , @ Nullable Long seed ,
8081 final PValueResult output ) {
82+ // Check nullable arguments
83+ if (nrRandomizations == null ) {
84+ nrRandomizations = 100 ;
85+ }
86+ if (seed == null ) {
87+ seed = 0x27372034L ;
88+ }
89+
8190 final int [] blockSize = blockSize (image1 , psfSize );
8291 final RandomAccessibleInterval <T > trimmedImage1 = trim (image1 , blockSize );
8392 final RandomAccessibleInterval <U > trimmedImage2 = trim (image2 , blockSize );
@@ -101,15 +110,16 @@ public void compute(final RandomAccessibleInterval<T> image1, final RandomAccess
101110 List <Integer > params = IntStream .rangeClosed (0 , numTasks - 1 ) //
102111 .boxed ().collect (Collectors .toList ());
103112
113+ final Integer nr = nrRandomizations ;
104114 Consumer <Integer > task = (t ) -> {
105- int offset = t * nrRandomizations / numTasks ;
106- int count = (t + 1 ) * nrRandomizations / numTasks - offset ;
115+ int offset = t * nr / numTasks ;
116+ int count = (t + 1 ) * nr / numTasks - offset ;
107117 // a new one per thread and each needs its own seed
108118 final ShuffledView <T > shuffled = new ShuffledView <>(trimmedImage1 , blockSize , seeds [offset ]);
109119 Img <T > buffer = Util .getSuitableImgFactory (shuffled , type1 ).create (shuffled );
110120 for (int i = 0 ; i < count ; i ++) {
111121 int index = offset + i ;
112- if (index >= nrRandomizations )
122+ if (index >= nr )
113123 break ;
114124 if (i > 0 )
115125 shuffled .shuffleBlocks (seeds [index ]);
@@ -181,57 +191,3 @@ private static <V> RandomAccessibleInterval<V> trim(final RandomAccessibleInterv
181191 return Views .interval (image , min , max );
182192 }
183193}
184-
185- /**
186- *@implNote op names='coloc.pValue'
187- */
188- class PValueSimpleWithRandomizations <T extends RealType <T >, U extends RealType <U >> implements
189- Computers .Arity4 <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double >, Integer , PValueResult > {
190-
191- @ OpDependency (name = "coloc.pValue" )
192- private Computers .Arity6 <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double >, Integer , Dimensions , Long , PValueResult > pValueOp ;
193-
194- /**
195- * TODO
196- *
197- * @param image1 the first image
198- * @param image2 the second image
199- * @param op the op
200- * @param nrRandomizations the number of randomizations
201- * @param output the result
202- */
203- @ Override
204- public void compute (RandomAccessibleInterval <T > image1 , RandomAccessibleInterval <U > image2 ,
205- BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double > op , Integer nrRandomizations , PValueResult output ) {
206- Long defaultSeed = 0x27372034L ;
207- pValueOp .compute (image1 , image2 , op , nrRandomizations , null , defaultSeed , output );
208- }
209-
210- }
211-
212- /**
213- *@implNote op names='coloc.pValue'
214- */
215- class PValueSimple <T extends RealType <T >, U extends RealType <U >> implements
216- Computers .Arity3 <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double >, PValueResult > {
217-
218- @ OpDependency (name = "coloc.pValue" )
219- private Computers .Arity4 <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double >, Integer , PValueResult > pValueOp ;
220-
221- /**
222- * TODO
223- *
224- * @param image1 the first image
225- * @param image2 the second image
226- * @param op the op
227- * @param output the result
228- */
229- @ Override
230- public void compute (RandomAccessibleInterval <T > image1 , RandomAccessibleInterval <U > image2 ,
231- BiFunction <RandomAccessibleInterval <T >, RandomAccessibleInterval <U >, Double > op ,
232- PValueResult output ) {
233- Integer defaultNumberRandomizations = 100 ;
234- pValueOp .compute (image1 , image2 , op , defaultNumberRandomizations , output );
235- }
236-
237- }
0 commit comments