From 6693198dbcfd784fa96a74acb6d2ec918175fe19 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 29 Aug 2022 16:01:40 -0500 Subject: [PATCH] Fix a few small issues with OMERO rendering metadata ...and add more tests. --- .../bioformats2raw/Colors.java | 2 +- .../bioformats2raw/Converter.java | 11 +++--- .../bioformats2raw/test/ZarrTest.java | 35 +++++++++++++++++++ .../test/multichannel-colors.ome.xml | 20 +++++++++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/com/glencoesoftware/bioformats2raw/test/multichannel-colors.ome.xml diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Colors.java b/src/main/java/com/glencoesoftware/bioformats2raw/Colors.java index e643d2b..020943d 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Colors.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Colors.java @@ -111,7 +111,7 @@ public static Color getColor(OMEXMLMetadata meta, int series, int c) { // return red, green, or blue depending on the channel index int baseColor = 0xff; - int shift = (2 - (c % 3)) * 8; + int shift = (3 - (c % 3)) * 8; baseColor = baseColor << shift; return new Color(baseColor + 0xff); } diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index 7498a2a..42c0502 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -1714,18 +1714,19 @@ else if (scale instanceof Time) { int seriesIndex = seriesList.indexOf(series); Map omero = new HashMap(); - omero.put("id", 0); String name = meta.getImageName(seriesIndex); if (name == null) { name = "Series " + seriesIndex; } omero.put("name", name); - omero.put("version", NGFF_VERSION); + + int channelCount = meta.getChannelCount(seriesIndex); + boolean colorRender = channelCount > 1 && channelCount < 8; Map rdefs = new HashMap(); rdefs.put("defaultT", 0); rdefs.put("defaultZ", meta.getPixelsSizeZ(seriesIndex).getValue() / 2); - rdefs.put("model", "greyscale"); + rdefs.put("model", colorRender ? "color" : "greyscale"); omero.put("rdefs", rdefs); double[] defaultMinMax = @@ -1733,9 +1734,9 @@ else if (scale instanceof Time) { meta.getPixelsType(seriesIndex).toString())); List> channels = new ArrayList>(); - for (int c=0; c channel = new HashMap(); - channel.put("active", true); + channel.put("active", c < 3); channel.put("coefficient", 1); // set an RGB color (alpha removed) diff --git a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java index e4a7559..7970a29 100644 --- a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java +++ b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java @@ -1026,6 +1026,10 @@ public void testOMERO() throws Exception { ZarrGroup.open(output.resolve(String.valueOf(i)).toString()); Map omero = (Map) z.getAttributes().get("omero"); + + Map rdefs = (Map) omero.get("rdefs"); + assertEquals("greyscale", rdefs.get("model")); + List> channels = (List>) omero.get("channels"); assertEquals(1, channels.size()); @@ -1033,6 +1037,37 @@ public void testOMERO() throws Exception { Map channel = channels.get(0); assertEquals(names[i], channel.get("label")); assertEquals(colors[i], channel.get("color")); + assertEquals(true, channel.get("active")); + } + } + + /** + * Check for OMERO rendering metadata on a 4 channel image. + */ + @Test + public void testOMEROMultiC() throws Exception { + input = getTestFile("multichannel-colors.ome.xml"); + assertTool(); + + String[] names = {"orange", "green", "blue", "red"}; + String[] colors = {"FF7F00", "00FF00", "0000FF", "FF0000"}; + + ZarrGroup z = ZarrGroup.open(output.resolve("0").toString()); + Map omero = + (Map) z.getAttributes().get("omero"); + + Map rdefs = (Map) omero.get("rdefs"); + assertEquals("color", rdefs.get("model")); + + List> channels = + (List>) omero.get("channels"); + assertEquals(names.length, channels.size()); + + for (int c=0; c channel = channels.get(c); + assertEquals(names[c], channel.get("label")); + assertEquals(colors[c], channel.get("color")); + assertEquals(c < 3, channel.get("active")); } } diff --git a/src/test/resources/com/glencoesoftware/bioformats2raw/test/multichannel-colors.ome.xml b/src/test/resources/com/glencoesoftware/bioformats2raw/test/multichannel-colors.ome.xml new file mode 100644 index 0000000..32042a0 --- /dev/null +++ b/src/test/resources/com/glencoesoftware/bioformats2raw/test/multichannel-colors.ome.xml @@ -0,0 +1,20 @@ + + + + + + + + +Image Description 0 + + + + + + + + + + +AAAAAA==