Skip to content

Commit

Permalink
bfconvert: remove extra channels if -channel was used
Browse files Browse the repository at this point in the history
Fixes ome#4149.
  • Loading branch information
melissalinkert committed Mar 26, 2024
1 parent 8bcb3c3 commit 55d48a7
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;
import java.util.SortedMap;

Expand Down Expand Up @@ -84,6 +85,7 @@
import loci.formats.services.OMEXMLServiceImpl;

import ome.xml.meta.OMEXMLMetadataRoot;
import ome.xml.model.Channel;
import ome.xml.model.Image;
import ome.xml.model.Pixels;
import ome.xml.model.enums.PixelType;
Expand Down Expand Up @@ -591,11 +593,22 @@ public boolean testConvert(IFormatWriter writer, String[] args)
String xml = service.getOMEXML(service.asRetrieve(store));
OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) store.getRoot();
IMetadata meta = service.createOMEXMLMetadata(xml);
OMEXMLMetadataRoot newRoot = (OMEXMLMetadataRoot) meta.getRoot();
if (series >= 0) {
Image exportImage = new Image(root.getImage(series));
Pixels exportPixels = new Pixels(root.getImage(series).getPixels());
Image exportImage = newRoot.getImage(series);
Pixels exportPixels = newRoot.getImage(series).getPixels();

if (channel >= 0) {
List<Channel> channels = exportPixels.copyChannelList();

for (int c=0; c<channels.size(); c++) {
if (c != channel) {
exportPixels.removeChannel(channels.get(c));
}
}
}

exportImage.setPixels(exportPixels);
OMEXMLMetadataRoot newRoot = (OMEXMLMetadataRoot) meta.getRoot();
while (newRoot.sizeOfImageList() > 0) {
newRoot.removeImage(newRoot.getImage(0));
}
Expand Down Expand Up @@ -639,6 +652,17 @@ public boolean testConvert(IFormatWriter writer, String[] args)
store.setPixelsType(PixelType.UINT8, i);
}

if (channel >= 0) {
Pixels exportPixels = newRoot.getImage(i).getPixels();
List<Channel> channels = exportPixels.copyChannelList();

for (int c=0; c<channels.size(); c++) {
if (c != channel) {
exportPixels.removeChannel(channels.get(c));
}
}
}

if (channel >= 0) {
meta.setPixelsSizeC(new PositiveInteger(1), i);
}
Expand Down

0 comments on commit 55d48a7

Please sign in to comment.