From 8bc606c0f55fd1d54a8fc3ab07d8c43eef6e0978 Mon Sep 17 00:00:00 2001 From: Gabor Kovacs Date: Fri, 10 May 2024 16:51:37 -0700 Subject: [PATCH] Add scaling rounded by default to 4 decimal places in determining mipmaptransforms and mipmapresolutions. --- .../bdv/img/omezarr/XmlIoZarrImageLoader.java | 9 ++++--- .../java/bdv/img/omezarr/ZarrImageLoader.java | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/bdv/img/omezarr/XmlIoZarrImageLoader.java b/src/main/java/bdv/img/omezarr/XmlIoZarrImageLoader.java index f9dfcd4..a49961f 100644 --- a/src/main/java/bdv/img/omezarr/XmlIoZarrImageLoader.java +++ b/src/main/java/bdv/img/omezarr/XmlIoZarrImageLoader.java @@ -35,6 +35,7 @@ import bdv.spimdata.XmlIoSpimDataMinimal; import java.io.File; +import java.util.Arrays; import java.util.Map; import java.util.TreeMap; @@ -110,15 +111,13 @@ public ZarrImageLoader fromXml(final Element elem, final File basePath, } public static void main(String[] args) throws SpimDataException { -// final String fn = "/home/gkovacs/data/davidf_zarr_dataset.xml"; - final String fn = "/home/gabor.kovacs/data/davidf_zarr_dataset.xml"; -// final String fn = "/home/gabor.kovacs/data/zarr_reader_test_2022-11-16/bdv_zarr_test3.xml"; -// final String fn = "/Users/kgabor/data/davidf_zarr_dataset.xml"; + final String fn = "/home/gkovacs/data/davidf_sample_dataset/davidf_zarr_dataset.xml"; +// final String fn = "/home/gabor.kovacs/data/davidf_zarr_dataset.xml"; final SpimDataMinimal spimData = new XmlIoSpimDataMinimal().load(fn); final ViewerImgLoader imgLoader = (ViewerImgLoader) spimData.getSequenceDescription().getImgLoader(); final ViewerSetupImgLoader setupImgLoader = imgLoader.getSetupImgLoader(0); int d = setupImgLoader.getImage(0).numDimensions(); - setupImgLoader.getMipmapResolutions(); + System.out.println(Arrays.toString(setupImgLoader.getMipmapTransforms())); // BigDataViewer.open(spimData, "BigDataViewer Zarr Example", new ProgressWriterConsole(), ViewerOptions.options()); System.out.println("imgLoader = " + imgLoader); System.out.println("setupimgLoader = " + setupImgLoader); diff --git a/src/main/java/bdv/img/omezarr/ZarrImageLoader.java b/src/main/java/bdv/img/omezarr/ZarrImageLoader.java index 0c94a1a..388d411 100644 --- a/src/main/java/bdv/img/omezarr/ZarrImageLoader.java +++ b/src/main/java/bdv/img/omezarr/ZarrImageLoader.java @@ -69,6 +69,8 @@ */ public class ZarrImageLoader implements ViewerImgLoader, MultiResolutionImgLoader, Closeable { // private final String zpath; + private static final int[] POWERS_OF_10 = {1, 10, 100, 1000, 10000, 100000, + 1000000, 10000000, 100000000, 1000000000}; private final SortedMap zgroups; private final AbstractSequenceDescription seq; private final MultiscaleImage.ZarrKeyValueReaderBuilder zarrKeyValueReaderBuilder; @@ -83,6 +85,13 @@ public class ZarrImageLoader implements ViewerImgLoader, MultiResolutionImgLoade private SortedMap setupImgLoaders; + public static double roundDouble(double s, int decimals) { + if (decimals < 0) + return s; + if (decimals >= POWERS_OF_10.length) + throw new IllegalArgumentException("Decimals out of range"); + return Math.rint(s * POWERS_OF_10[decimals]) / (double) POWERS_OF_10[decimals]; + } public ZarrImageLoader(final MultiscaleImage.ZarrKeyValueReaderBuilder zarrKeyValueReaderBuilder, final SortedMap zgroups, final AbstractSequenceDescription sequenceDescription) { this.zgroups = zgroups; @@ -296,6 +305,10 @@ private AffineTransform3D concatenateOMETransforms(final Multiscales mscales, return affT; } + + private void calculateMipmapTransforms() { + calculateMipmapTransforms(4); + } /** * Create the 3D affine transformations and calculate the resolution factors * for the multi resolution display relative to the first resolution. @@ -315,7 +328,7 @@ private AffineTransform3D concatenateOMETransforms(final Multiscales mscales, * *

Set "mipmaptransforms" and "mipmapresolutions".

*/ - private void calculateMipmapTransforms() { + private void calculateMipmapTransforms(int decimals) { // Assume everything is the same in case there are multiple timepoints final Multiscales mscale = tpMmultiscaleImages.get(0).getMultiscales(); final int numResolutions = tpMmultiscaleImages.get(0).numResolutions(); @@ -335,15 +348,19 @@ private void calculateMipmapTransforms() { for (int j = 1; j < numResolutions; ++j) { final AffineTransform3D affT = T0inv.copy(); affT.concatenate(mipmaptransforms[j]); + affT.set(roundDouble(affT.get(0, 0), decimals),0,0); + affT.set(roundDouble(affT.get(1, 1), decimals),1,1); + affT.set(roundDouble(affT.get(2, 2), decimals),2,2); mipmaptransforms[j] = affT; } // Copy out the scaling from the transformations to the mipmapresolutions mipmapresolutions = new double[numResolutions][]; for (int j = 0; j < numResolutions; ++j) { - mipmapresolutions[j] = new double[]{mipmaptransforms[j].get(0, 0), + mipmapresolutions[j] = new double[]{ + mipmaptransforms[j].get(0, 0), mipmaptransforms[j].get(1, 1), - mipmaptransforms[j].get(2, 2)}; + mipmaptransforms[j].get(2, 2) }; } // Add pixel center correction @@ -353,7 +370,6 @@ private void calculateMipmapTransforms() { 0.5 * (mipmapresolutions[j][1] - 1.), 0.5 * (mipmapresolutions[j][2] - 1.)); } - } @Override