|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Image processing operations for SciJava Ops. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2014 - 2024 SciJava developers. |
| 6 | + * %% |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions are met: |
| 9 | + * |
| 10 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer. |
| 12 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer in the documentation |
| 14 | + * and/or other materials provided with the distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 20 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 | + * POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * #L% |
| 28 | + */ |
| 29 | + |
| 30 | +package org.scijava.ops.image.stats; |
| 31 | + |
| 32 | +import net.imglib2.RandomAccess; |
| 33 | +import net.imglib2.img.Img; |
| 34 | +import net.imglib2.type.numeric.real.DoubleType; |
| 35 | +import net.imglib2.type.numeric.real.FloatType; |
| 36 | + |
| 37 | +import org.scijava.ops.image.AbstractOpTest; |
| 38 | +import org.scijava.types.Nil; |
| 39 | + |
| 40 | +import org.junit.jupiter.api.Test; |
| 41 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 42 | + |
| 43 | +/** |
| 44 | + * Test {@code stats.pnorm} op. |
| 45 | + * |
| 46 | + * @author Edward Evans |
| 47 | + */ |
| 48 | + |
| 49 | +public class DefaultPNormTest extends AbstractOpTest { |
| 50 | + |
| 51 | + @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, |
| 56 | + 0.8861427670894226, 0.5, 0.9999999999828452, 0.5, 0.9960363221624154, 0.5, |
| 57 | + 0.999998128463855 }; |
| 58 | + |
| 59 | + // load Z-score heatmap slice |
| 60 | + Img<FloatType> zscore = openFloatImg("zscore_test_data.tif"); |
| 61 | + |
| 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(); |
| 66 | + |
| 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 |
| 71 | + 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()); |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments