Skip to content

Commit 48ffeb4

Browse files
committed
Copy default args from coloc Ops
1 parent eb59553 commit 48ffeb4

2 files changed

Lines changed: 29 additions & 93 deletions

File tree

scijava-ops-image/src/main/java/org/scijava/ops/image/coloc/maxTKendallTau/MTKT.java

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131

3232
import java.util.Collections;
3333
import java.util.Random;
34-
import java.util.function.BiFunction;
3534
import java.util.function.Function;
3635

37-
import org.scijava.ops.image.coloc.ColocUtil;
38-
import org.scijava.ops.image.coloc.IntArraySorter;
39-
import org.scijava.ops.image.coloc.MergeSort;
4036
import net.imglib2.RandomAccess;
4137
import net.imglib2.RandomAccessibleInterval;
4238
import net.imglib2.histogram.Histogram1d;
@@ -45,10 +41,13 @@
4541
import net.imglib2.util.Intervals;
4642
import net.imglib2.util.Util;
4743
import net.imglib2.view.Views;
48-
4944
import org.scijava.collections.IntArray;
5045
import org.scijava.function.Computers;
5146
import org.scijava.function.Functions;
47+
import org.scijava.ops.image.coloc.ColocUtil;
48+
import org.scijava.ops.image.coloc.IntArraySorter;
49+
import org.scijava.ops.image.coloc.MergeSort;
50+
import org.scijava.ops.spi.Nullable;
5251
import org.scijava.ops.spi.OpDependency;
5352

5453
/**
@@ -86,7 +85,7 @@ public class MTKT<T extends RealType<T>, U extends RealType<U>>
8685
* @return the output
8786
*/
8887
@Override
89-
public Double apply(final RandomAccessibleInterval<T> image1, final RandomAccessibleInterval<U> image2, final Long seed) {
88+
public Double apply(final RandomAccessibleInterval<T> image1, final RandomAccessibleInterval<U> image2, @Nullable Long seed) {
9089
// check image sizes
9190
// TODO: Add these checks to conforms().
9291
if (!Intervals.equalDimensions(image1, image2)) {
@@ -98,6 +97,13 @@ public Double apply(final RandomAccessibleInterval<T> image1, final RandomAccess
9897
}
9998
final int n = (int) n1;
10099

100+
// Check nullable seed
101+
if (seed == null) {
102+
// NB the original seed used in ImageJ Ops was an integer, 0x893023421.
103+
// To preserve the same value without casting, we need this value.
104+
seed = 0xffff_ffff_8930_2341L;
105+
}
106+
101107
// compute thresholds
102108
final double thresh1 = thresholdT(image1);
103109
final double thresh2 = thresholdU(image2);
@@ -142,8 +148,8 @@ static <T extends RealType<T>, U extends RealType<U>> double[][] rankTransformat
142148
double[][] finalRanks = new double[rn][2];
143149
for (int i = 0; i < rn; i++) {
144150
final int index = validIndex.getValue(i);
145-
finalRanks[i][0] = Math.floor(rankIndex1[index]);
146-
finalRanks[i][1] = Math.floor(rankIndex2[index]);
151+
finalRanks[i][0] = rankIndex1[index];
152+
finalRanks[i][1] = rankIndex2[index];
147153
}
148154
return finalRanks;
149155
}
@@ -245,29 +251,3 @@ static double calculateKendallTau(final double[][] rank,
245251
}
246252

247253
}
248-
249-
/**
250-
*@implNote op names='coloc.maxTKendallTau'
251-
*/
252-
class MTKTSimple<T extends RealType<T>, U extends RealType<U>>
253-
implements BiFunction<RandomAccessibleInterval<T>, RandomAccessibleInterval<U>, Double>
254-
{
255-
256-
@OpDependency(name = "coloc.maxTKendallTau")
257-
private Functions.Arity3<RandomAccessibleInterval<T>, RandomAccessibleInterval<U>, Long, Double> colocOp;
258-
259-
private long seed = 0x89302341;
260-
261-
/**
262-
* TODO
263-
*
264-
* @param image1
265-
* @param image2
266-
* @return the output
267-
*/
268-
@Override
269-
public Double apply(RandomAccessibleInterval<T> image1, RandomAccessibleInterval<U> image2) {
270-
return colocOp.apply(image1, image2, seed);
271-
}
272-
273-
}

scijava-ops-image/src/main/java/org/scijava/ops/image/coloc/pValue/DefaultPValue.java

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import org.scijava.concurrent.Parallelization;
4040
import org.scijava.function.Computers;
41+
import org.scijava.ops.spi.Nullable;
4142
import org.scijava.ops.spi.OpDependency;
4243

4344
import 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

Comments
 (0)