|
30 | 30 | package org.scijava.ops.image.stats; |
31 | 31 |
|
32 | 32 | import net.imglib2.RandomAccess; |
33 | | -import net.imglib2.img.Img; |
| 33 | +import net.imglib2.img.array.ArrayImgs; |
34 | 34 | import net.imglib2.type.numeric.real.DoubleType; |
35 | | -import net.imglib2.type.numeric.real.FloatType; |
36 | 35 |
|
37 | 36 | import org.scijava.ops.image.AbstractOpTest; |
38 | | -import org.scijava.types.Nil; |
39 | 37 |
|
40 | 38 | import org.junit.jupiter.api.Test; |
41 | 39 | import static org.junit.jupiter.api.Assertions.assertEquals; |
|
49 | 47 | public class DefaultPNormTest extends AbstractOpTest { |
50 | 48 |
|
51 | 49 | @Test |
52 | | - public void testImg() { |
53 | | - final int[] xPositions = { 30, 79, 77, 104, 7, 52, 164, 88, 119, 65 }; |
54 | | - final int[] yPositions = { 30, 36, 80, 79, 139, 102, 77, 41, 142, 118 }; |
55 | | - final double[] pvalueExpected = { 0.5, 0.9999998132675161, 0.5, |
| 50 | + public void testPNorm() { |
| 51 | + final double[] data = { 0.0, 5.082008361816406, 0.0, 1.206267237663269, 0.0, |
| 52 | + 6.626776218414307, 0.0, 2.6551482677459717, 0.0, 4.625161170959473 }; |
| 53 | + final double[] expected = { 0.5, 0.9999998132675161, 0.5, |
56 | 54 | 0.8861427670894226, 0.5, 0.9999999999828452, 0.5, 0.9960363221624154, 0.5, |
57 | 55 | 0.999998128463855 }; |
58 | 56 |
|
59 | | - // load Z-score heatmap slice |
60 | | - Img<FloatType> zscore = openFloatImg("zscore_test_data.tif"); |
| 57 | + // create input for stats.pnorm Op |
| 58 | + var input = ArrayImgs.doubles(data, 10); |
| 59 | + var pvalue = ArrayImgs.doubles(10); |
61 | 60 |
|
62 | | - // create p-value image container |
63 | | - Img<DoubleType> pvalue = ops.op("create.img").input(zscore, |
64 | | - new DoubleType()).outType(new Nil<Img<DoubleType>>() |
65 | | - {}).apply(); |
| 61 | + // run stats.pnorm op on data |
| 62 | + ops.op("stats.pnorm").input(input).output(pvalue).compute(); |
66 | 63 |
|
67 | | - // run stats.pnorm op on Z-score data |
68 | | - ops.op("stats.pnorm").input(zscore).output(pvalue).compute(); |
69 | | - |
70 | | - // get random access and compare pixels |
| 64 | + // get random access and results are equal |
71 | 65 | final RandomAccess<DoubleType> pRA = pvalue.randomAccess(); |
72 | | - |
73 | | - // assert results are equal |
74 | | - for (int i = 0; i < xPositions.length; i++) { |
75 | | - pRA.setPosition(xPositions[i], 0); |
76 | | - pRA.setPosition(yPositions[i], 1); |
77 | | - assertEquals(pvalueExpected[i], pRA.get().getRealDouble()); |
| 66 | + for (int i = 0; i < data.length; i++) { |
| 67 | + pRA.setPosition(i, 0); |
| 68 | + assertEquals(expected[i], pRA.get().getRealDouble()); |
78 | 69 | } |
79 | 70 | } |
80 | 71 | } |
0 commit comments