Skip to content

Commit

Permalink
Fix a few small issues with OMERO rendering metadata
Browse files Browse the repository at this point in the history
...and add more tests.
  • Loading branch information
melissalinkert committed Aug 29, 2022
1 parent 8ab3ceb commit 6693198
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/glencoesoftware/bioformats2raw/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1714,28 +1714,29 @@ else if (scale instanceof Time) {
int seriesIndex = seriesList.indexOf(series);

Map<String, Object> omero = new HashMap<String, Object>();
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<String, Object> rdefs = new HashMap<String, Object>();
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 =
getRange(FormatTools.pixelTypeFromString(
meta.getPixelsType(seriesIndex).toString()));

List<Map<String, Object>> channels = new ArrayList<Map<String, Object>>();
for (int c=0; c<meta.getChannelCount(seriesIndex); c++) {
for (int c=0; c<channelCount; c++) {
Map<String, Object> channel = new HashMap<String, Object>();
channel.put("active", true);
channel.put("active", c < 3);
channel.put("coefficient", 1);

// set an RGB color (alpha removed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,48 @@ public void testOMERO() throws Exception {
ZarrGroup.open(output.resolve(String.valueOf(i)).toString());
Map<String, Object> omero =
(Map<String, Object>) z.getAttributes().get("omero");

Map<String, Object> rdefs = (Map<String, Object>) omero.get("rdefs");
assertEquals("greyscale", rdefs.get("model"));

List<Map<String, Object>> channels =
(List<Map<String, Object>>) omero.get("channels");
assertEquals(1, channels.size());

Map<String, Object> 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<String, Object> omero =
(Map<String, Object>) z.getAttributes().get("omero");

Map<String, Object> rdefs = (Map<String, Object>) omero.get("rdefs");
assertEquals("color", rdefs.get("model"));

List<Map<String, Object>> channels =
(List<Map<String, Object>>) omero.get("channels");
assertEquals(names.length, channels.size());

for (int c=0; c<channels.size(); c++) {
Map<String, Object> channel = channels.get(c);
assertEquals(names[c], channel.get("label"));
assertEquals(colors[c], channel.get("color"));
assertEquals(c < 3, channel.get("active"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Creator="OME Bio-Formats 6.6.1-SNAPSHOT" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd">
<Instrument ID="Instrument:0">
<Filter ID="Filter:0:0">
<TransmittanceRange CutIn="350" CutOut="450"/>
</Filter>
</Instrument>
<Image ID="Image:0" Name="test">
<Description>Image Description 0</Description>
<Pixels BigEndian="false" DimensionOrder="XYZCT" ID="Pixels:0" Interleaved="false" PhysicalSizeX="1.0" PhysicalSizeXUnit="µm" PhysicalSizeY="1.0" PhysicalSizeYUnit="µm" PhysicalSizeZ="1.0" PhysicalSizeZUnit="µm" SignificantBits="8" SizeC="4" SizeT="1" SizeX="1" SizeY="1" SizeZ="1" Type="uint8">
<Channel AcquisitionMode="FluorescenceLifetime" Color="-8453889" ContrastMethod="Brightfield" EmissionWavelength="300.3" EmissionWavelengthUnit="nm" ExcitationWavelength="400.3" ExcitationWavelengthUnit="nm" Fluor="Fluor" ID="Channel:0:0" IlluminationType="Oblique" NDFilter="1.0" Name="orange" PinholeSize="0.5" PinholeSizeUnit="µm" PockelCellSetting="0" SamplesPerPixel="1"/>
<Channel AcquisitionMode="FluorescenceLifetime" ContrastMethod="Brightfield" EmissionWavelength="520.0" EmissionWavelengthUnit="nm" ExcitationWavelength="600.0" ExcitationWavelengthUnit="nm" Fluor="Fluor" ID="Channel:0:1" IlluminationType="Oblique" NDFilter="1.0" Name="green" PinholeSize="0.5" PinholeSizeUnit="µm" PockelCellSetting="0" SamplesPerPixel="1"/>
<Channel AcquisitionMode="FluorescenceLifetime" ContrastMethod="Brightfield" Fluor="Fluor" ID="Channel:0:2" IlluminationType="Oblique" NDFilter="1.0" Name="blue" PinholeSize="0.5" PinholeSizeUnit="µm" PockelCellSetting="0" SamplesPerPixel="1">
<LightPath>
<EmissionFilterRef ID="Filter:0:0"/>
</LightPath>
</Channel>
<Channel AcquisitionMode="FluorescenceLifetime" ContrastMethod="Brightfield" Fluor="Fluor" ID="Channel:0:3" IlluminationType="Oblique" NDFilter="1.0" Name="red" PinholeSize="0.5" PinholeSizeUnit="µm" PockelCellSetting="0" SamplesPerPixel="1"/>
<Plane DeltaT="0.1" DeltaTUnit="s" ExposureTime="10.0" ExposureTimeUnit="s" PositionX="1.0" PositionXUnit="reference frame" PositionY="1.0" PositionYUnit="reference frame" PositionZ="1.0" PositionZUnit="reference frame" TheC="0" TheT="0" TheZ="0"/>
<BinData xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" Length="4" BigEndian="false">AAAAAA==</BinData></Pixels></Image></OME>

0 comments on commit 6693198

Please sign in to comment.