From 26df445aa4d2e95c40251300a71d433614ccdd42 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 27 Jan 2023 16:03:38 +0100 Subject: [PATCH 1/2] Refactor CYXNgffBaseTest --- .../ngff/base/CYXNgffBaseTest.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java b/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java index 98a14628..22e811b2 100644 --- a/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java +++ b/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java @@ -55,25 +55,36 @@ public void checkDataset() { long x = 1; long y = 1; long z = 1; - long[] imageDimensions = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(0).getImage(0).dimensionsAsLongArray(); - if (x > imageDimensions[0] || y > imageDimensions[1] || z > imageDimensions[2]) { - throw new RuntimeException("Coordinates out of bounds"); - } - RandomAccessibleInterval randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(0).getImage(0); - VolatileCachedCellImg volatileCachedCellImg = (VolatileCachedCellImg) randomAccessibleInterval; - CellGrid cellGrid = volatileCachedCellImg.getCellGrid(); - long[] dims = new long[]{1024, 930, 1}; - int[] cellDims = new int[]{256, 256, 1}; - CellGrid expected = new CellGrid(dims, cellDims); - Assertions.assertEquals(expected, cellGrid); + final int timepointId = 0; + + for ( int channelId = 0; channelId < expectedChannelsNumber; channelId++ ) + { + long[] imageDimensions = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader( channelId ).getImage( timepointId ).dimensionsAsLongArray(); + if ( x > imageDimensions[ 0 ] || y > imageDimensions[ 1 ] || z > imageDimensions[ 2 ] ) + { + throw new RuntimeException( "Coordinates out of bounds" ); + } + + RandomAccessibleInterval< ? > randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader( channelId ).getImage( timepointId ); + VolatileCachedCellImg volatileCachedCellImg = ( VolatileCachedCellImg ) randomAccessibleInterval; + CellGrid cellGrid = volatileCachedCellImg.getCellGrid(); + long[] dims = new long[]{ 1024, 930, 1 }; + int[] cellDims = new int[]{ 256, 256, 1 }; + CellGrid expected = new CellGrid( dims, cellDims ); + Assertions.assertEquals( expected, cellGrid ); + } } @Test public void checkImgValue() { + final int timepointId = 0; + // random test data generated independently with python - RandomAccessibleInterval randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(1).getImage(0); + int channelId = 1; + RandomAccessibleInterval randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader( channelId ).getImage( timepointId ); + UnsignedShortType o = (UnsignedShortType) randomAccessibleInterval.getAt(647, 482, 0); int value = o.get(); int expectedValue = 4055; @@ -83,14 +94,18 @@ public void checkImgValue() { value = o.get(); expectedValue = 4213; Assertions.assertEquals(expectedValue, value); - - randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(2).getImage(0); + + channelId = 2; + randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(channelId).getImage(timepointId); + o = (UnsignedShortType) randomAccessibleInterval.getAt(559, 920, 0); value = o.get(); expectedValue = 1835; Assertions.assertEquals(expectedValue, value); - - randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(3).getImage(0); + + channelId = 3; + randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(channelId).getImage(timepointId); + o = (UnsignedShortType) randomAccessibleInterval.getAt(934, 929, 0); value = o.get(); expectedValue = 1724; From 0688de43b8dac2ecddec798cd7a5f84438d3f1c4 Mon Sep 17 00:00:00 2001 From: Christian Tischer Date: Fri, 27 Jan 2023 16:24:06 +0100 Subject: [PATCH 2/2] Check that value at high channel and high resolution level is larger zero --- .../ngff/base/CYXNgffBaseTest.java | 41 +++++++++++++++---- .../dataformats/ngff/v04/CYXNgffV04Test.java | 1 + 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java b/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java index 22e811b2..3404171b 100644 --- a/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java +++ b/src/test/java/dataformats/ngff/base/CYXNgffBaseTest.java @@ -28,6 +28,8 @@ */ package dataformats.ngff.base; +import mpicbg.spim.data.sequence.ImgLoader; +import mpicbg.spim.data.sequence.MultiResolutionImgLoader; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -80,14 +82,37 @@ public void checkDataset() { public void checkImgValue() { final int timepointId = 0; + int channelId; + int resolutionLevel; + RandomAccessibleInterval randomAccessibleInterval; + UnsignedShortType o; + int value; + int expectedValue; + + + final MultiResolutionImgLoader imgLoader = ( MultiResolutionImgLoader ) spimData.getSequenceDescription().getImgLoader(); + final int numResolutions = imgLoader.getSetupImgLoader( 0 ).getMipmapResolutions().length; // random test data generated independently with python - int channelId = 1; - RandomAccessibleInterval randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader( channelId ).getImage( timepointId ); - UnsignedShortType o = (UnsignedShortType) randomAccessibleInterval.getAt(647, 482, 0); - int value = o.get(); - int expectedValue = 4055; + // test high channel number in down-sampled resolution + // this was where we thought that issue could be: + // https://github.com/mobie/mobie-viewer-fiji/issues/945 + channelId = 3; + resolutionLevel = 2; + randomAccessibleInterval = imgLoader.getSetupImgLoader(channelId).getImage( timepointId, resolutionLevel ); + o = (UnsignedShortType) randomAccessibleInterval.getAt(770/4, 343/4, 0); + value = o.get(); + //expectedValue = 2871; + Assertions.assertTrue( value > 0 ); + + channelId = 1; + resolutionLevel = 0; + randomAccessibleInterval = imgLoader.getSetupImgLoader( channelId ).getImage( timepointId, resolutionLevel ); + + o = (UnsignedShortType) randomAccessibleInterval.getAt(647, 482, 0); + value = o.get(); + expectedValue = 4055; Assertions.assertEquals(expectedValue, value); o = (UnsignedShortType) randomAccessibleInterval.getAt(649, 346, 0); @@ -96,7 +121,7 @@ public void checkImgValue() { Assertions.assertEquals(expectedValue, value); channelId = 2; - randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(channelId).getImage(timepointId); + randomAccessibleInterval = imgLoader.getSetupImgLoader(channelId).getImage( timepointId, resolutionLevel ); o = (UnsignedShortType) randomAccessibleInterval.getAt(559, 920, 0); value = o.get(); @@ -104,7 +129,7 @@ public void checkImgValue() { Assertions.assertEquals(expectedValue, value); channelId = 3; - randomAccessibleInterval = spimData.getSequenceDescription().getImgLoader().getSetupImgLoader(channelId).getImage(timepointId); + randomAccessibleInterval = imgLoader.getSetupImgLoader(channelId).getImage( timepointId, resolutionLevel ); o = (UnsignedShortType) randomAccessibleInterval.getAt(934, 929, 0); value = o.get(); @@ -115,5 +140,7 @@ public void checkImgValue() { value = o.get(); expectedValue = 2871; Assertions.assertEquals(expectedValue, value); + + } } diff --git a/src/test/java/dataformats/ngff/v04/CYXNgffV04Test.java b/src/test/java/dataformats/ngff/v04/CYXNgffV04Test.java index c4569e59..81134d76 100644 --- a/src/test/java/dataformats/ngff/v04/CYXNgffV04Test.java +++ b/src/test/java/dataformats/ngff/v04/CYXNgffV04Test.java @@ -35,6 +35,7 @@ @Slf4j public class CYXNgffV04Test extends CYXNgffBaseTest{ private static final String URL = "https://s3.embl.de/i2k-2020/ngff-example-data/v0.4/cyx.ome.zarr"; + public CYXNgffV04Test() throws SpimDataException { super(URL); }