From 0df492ff14771bf21e4a9ae89dd7a66d3b5f7bdf Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Wed, 12 Oct 2022 13:54:42 +0900 Subject: [PATCH] perform autoscaling if floating point thumbnail found. --- .../tools/BioFormatsImageThumbnail.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java b/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java index 0b7b5be..e3a9014 100644 --- a/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java +++ b/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java @@ -21,7 +21,9 @@ import javax.imageio.stream.ImageOutputStream; import loci.common.DebugTools; import loci.formats.FormatException; +import loci.formats.FormatTools; import loci.formats.ImageReader; +import loci.formats.gui.AWTImageTools; import loci.formats.gui.BufferedImageReader; public class BioFormatsImageThumbnail { @@ -89,8 +91,10 @@ public class BioFormatsImageThumbnail { final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) { final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next(); final ImageWriteParam param = writer.getDefaultWriteParam(); - param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - param.setCompressionQuality(quality); + if (param.canWriteCompressed()) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + } writer.setOutput(ios); writer.write(null, new IIOImage(removeAlphaChannel(image, matColor), null, null), param); writer.dispose(); @@ -166,12 +170,19 @@ public class BioFormatsImageThumbnail { } } reader.setSeries(series); - final int no = 0; + final int z = reader.getSizeZ() / 2; // middle of slices + final int t = reader.getSizeT() / 2; // middle of frames + final int c = 0; // first channel + final int no = reader.getIndex(z, c, t); // System.out.println("series count: " + seriesCount); // System.out.println("image count: " + reader.getImageCount()); // System.out.println("resolution: " + reader.getResolutionCount()); // System.out.println("thubmail series: " + series); ret = reader.openThumbImage(no); + if (!FormatTools.isFloatingPoint(reader.getPixelType())) { + // auto scalling floating point thumbnail. + ret = AWTImageTools.autoscale(ret); + } } catch (final Throwable t) { for (Throwable e = t; e != null; e = e.getCause()) { if (t instanceof OutOfMemoryError) { @@ -252,6 +263,7 @@ public class BioFormatsImageThumbnail { System.out.println(dataUri); // saveFile(dataUri, "/var/tmp/thumbnail." + format); } catch (final Throwable t) { + // t.printStackTrace(); System.out.println(t.getMessage()); System.exit(1); }