update bio-formats version to 6.14.0.

This commit is contained in:
Yoshihiro OKUMURA 2023-07-13 13:50:25 +09:00
parent 705e7f7e7d
commit 4c581052ab
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
7 changed files with 64 additions and 30 deletions

8
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,8 @@
{
"recommendations": [
"vscjava.vscode-java-pack",
"esbenp.prettier-vscode",
"mosapride.zenkaku",
"streetsidesoftware.code-spell-checker"
]
}

17
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// Extensions - Code Spell Checker
"cSpell.ignoreWords": ["endianness", "noflat", "nopix", "omexml"],
"cSpell.words": ["bioformats", "imageinfo", "neurodata", "riken"],
// Extentions - Prettier
"prettier.printWidth": 120,
"prettier.singleQuote": true,
"prettier.tabWidth": 4,
"java.configuration.updateBuildConfiguration": "interactive"
}

View File

@ -1,27 +1,33 @@
# BioFormatsImageInfo # BioFormatsImageInfo
Metadata extraction tool based on Bio-Formats Metadata extraction tool based on Bio-Formats
### make package ### make package
```shell ```shell
mvn package mvn package
``` ```
### run ### run
```shell ```shell
./target/dist/bin/bioformats-imageinfo "[path to image file]" ./target/dist/bin/bioformats-imageinfo "[path to image file]"
``` ```
### run by jar ### run by jar
```shell ```shell
java -jar ./target/dist/lib/bioformats-imageinfo-1.1.3.jar "[path to image file]" java -jar ./target/dist/lib/bioformats-imageinfo-1.1.4.jar "[path to image file]"
``` ```
### run by fat jar ### run by fat jar
```shell ```shell
java -jar ./target/bioformats-imageinfo-1.1.3-jar-with-dependencies.jar "[path to image file]" java -jar ./target/bioformats-imageinfo-1.1.4-jar-with-dependencies.jar "[path to image file]"
``` ```
### library usage ### library usage
```java ```java
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;

14
pom.xml
View File

@ -1,15 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId> <groupId>jp.riken.neurodata.tools.BioFormatsImageInfo</groupId>
<artifactId>bioformats-imageinfo</artifactId> <artifactId>bioformats-imageinfo</artifactId>
<version>1.1.3</version> <version>1.1.4</version>
<name>bioformats-imageinfo</name> <name>bioformats-imageinfo</name>
<url>https://neurodata.riken.jp</url> <url>https://neurodata.riken.jp</url>
<properties> <properties>
<bio-formats.version>6.12.0</bio-formats.version> <bio-formats.version>6.14.0</bio-formats.version>
<bioformats-imageinfo.mainClass>jp.riken.neurodata.tools.BioFormatsImageInfo</bioformats-imageinfo.mainClass> <bioformats-imageinfo.mainClass>jp.riken.neurodata.tools.BioFormatsImageInfo</bioformats-imageinfo.mainClass>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
@ -57,7 +59,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>3.5.0</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<id>copy-dependencies</id> <id>copy-dependencies</id>
@ -111,7 +113,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>3.5.0</version> <version>3.6.0</version>
<configuration> <configuration>
<descriptorRefs> <descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef> <descriptorRef>jar-with-dependencies</descriptorRef>
@ -138,7 +140,7 @@
<plugin> <plugin>
<groupId>org.owasp</groupId> <groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId> <artifactId>dependency-check-maven</artifactId>
<version>8.2.1</version> <version>8.3.1</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id> <id>bin</id>
<formats> <formats>

View File

@ -142,14 +142,14 @@ public class BioFormatsImageInfo {
final int seriesCount = reader.getSeriesCount(); final int seriesCount = reader.getSeriesCount();
for (int j = 0; j < seriesCount; j++) { for (int j = 0; j < seriesCount; j++) {
reader.setSeries(j); reader.setSeries(j);
final Hashtable<String, Object> seriesMagedata = reader.getSeriesMetadata(); final Hashtable<String, Object> seriesMetadata = reader.getSeriesMetadata();
if (!seriesMagedata.isEmpty()) { if (!seriesMetadata.isEmpty()) {
final Map<String, Object> seriesMetadata = new LinkedHashMap<String, Object>(); final Map<String, Object> originalMetadata = new LinkedHashMap<String, Object>();
final String[] keys = MetadataTools.keys(seriesMagedata); final String[] keys = MetadataTools.keys(seriesMetadata);
for (int i = 0; i < keys.length; i++) { for (int i = 0; i < keys.length; i++) {
seriesMetadata.put(keys[i], seriesMagedata.get(keys[i])); originalMetadata.put(keys[i], seriesMetadata.get(keys[i]));
} }
metadata.put(String.format("series[%d]", j), seriesMetadata); metadata.put(String.format("series[%d]", j), originalMetadata);
} }
} }
@ -188,7 +188,7 @@ public class BioFormatsImageInfo {
// json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map); // json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
json = mapper.writeValueAsString(map); json = mapper.writeValueAsString(map);
} catch (final Throwable e) { } catch (final Throwable e) {
// return "null" if conversion error occured // return "null" if conversion error occurred
json = "null"; json = "null";
} }

View File

@ -27,7 +27,7 @@ import loci.formats.gui.BufferedImageReader;
public class BioFormatsImageThumbnail { public class BioFormatsImageThumbnail {
protected static final float JPEG_QUORITY = 0.85f; protected static final float JPEG_QUALITY = 0.85f;
protected static final int BACKGROUND_COLOR = 0x000000; protected static final int BACKGROUND_COLOR = 0x000000;
protected static final double MAXIMUM_SCALE = 2.0; protected static final double MAXIMUM_SCALE = 2.0;
@ -39,14 +39,14 @@ public class BioFormatsImageThumbnail {
final double scaleHeight = (double) height / (double) imageHeight; final double scaleHeight = (double) height / (double) imageHeight;
double scale = Math.min(scaleWidth, scaleHeight); double scale = Math.min(scaleWidth, scaleHeight);
if (scale > MAXIMUM_SCALE) { if (scale > MAXIMUM_SCALE) {
// limit scalling size to maximum scale // limit scaling size to maximum scale
scale = MAXIMUM_SCALE; scale = MAXIMUM_SCALE;
} }
int resizeWidth = imageWidth; int resizeWidth = imageWidth;
int resizeHeight = imageHeight; int resizeHeight = imageHeight;
Image resizeImage = image; Image resizeImage = image;
if (scale != 1.0) { if (scale != 1.0) {
// resize image if dimension is different with requrested dimension. // resize image if dimension is different with requested dimension.
resizeWidth = (int) (scale * (double) imageWidth); resizeWidth = (int) (scale * (double) imageWidth);
resizeHeight = (int) (scale * (double) imageHeight); resizeHeight = (int) (scale * (double) imageHeight);
resizeImage = image.getScaledInstance(resizeWidth, resizeHeight, Image.SCALE_AREA_AVERAGING); resizeImage = image.getScaledInstance(resizeWidth, resizeHeight, Image.SCALE_AREA_AVERAGING);
@ -86,8 +86,8 @@ public class BioFormatsImageThumbnail {
protected static byte[] getJpegByteArray(final BufferedImage image, final float quality, final int matColor) protected static byte[] getJpegByteArray(final BufferedImage image, final float quality, final int matColor)
throws BioFormatsImageException { throws BioFormatsImageException {
byte[] ret = null; byte[] ret = null;
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) { final ImageOutputStream ios = ImageIO.createImageOutputStream(bos);) {
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next(); final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
final ImageWriteParam param = writer.getDefaultWriteParam(); final ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed()) { if (param.canWriteCompressed()) {
@ -97,7 +97,7 @@ public class BioFormatsImageThumbnail {
writer.setOutput(ios); writer.setOutput(ios);
writer.write(null, new IIOImage(removeAlphaChannel(image, matColor), null, null), param); writer.write(null, new IIOImage(removeAlphaChannel(image, matColor), null, null), param);
writer.dispose(); writer.dispose();
ret = baos.toByteArray(); ret = bos.toByteArray();
} catch (final IOException e) { } catch (final IOException e) {
throw new BioFormatsImageException(e); throw new BioFormatsImageException(e);
} }
@ -107,8 +107,8 @@ public class BioFormatsImageThumbnail {
protected static byte[] getPngByteArray(final BufferedImage image) throws BioFormatsImageException { protected static byte[] getPngByteArray(final BufferedImage image) throws BioFormatsImageException {
byte[] ret = null; byte[] ret = null;
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) { final ImageOutputStream ios = ImageIO.createImageOutputStream(bos);) {
final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next(); final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
final ImageWriteParam param = writer.getDefaultWriteParam(); final ImageWriteParam param = writer.getDefaultWriteParam();
if (param.canWriteCompressed()) { if (param.canWriteCompressed()) {
@ -118,7 +118,7 @@ public class BioFormatsImageThumbnail {
writer.setOutput(ios); writer.setOutput(ios);
writer.write(null, new IIOImage(image, null, null), param); writer.write(null, new IIOImage(image, null, null), param);
writer.dispose(); writer.dispose();
ret = baos.toByteArray(); ret = bos.toByteArray();
} catch (final IOException e) { } catch (final IOException e) {
throw new BioFormatsImageException(e); throw new BioFormatsImageException(e);
} }
@ -133,7 +133,7 @@ public class BioFormatsImageThumbnail {
bytes = getPngByteArray(image); bytes = getPngByteArray(image);
break; break;
case "image/jpeg": case "image/jpeg":
bytes = getJpegByteArray(image, JPEG_QUORITY, BACKGROUND_COLOR); bytes = getJpegByteArray(image, JPEG_QUALITY, BACKGROUND_COLOR);
break; break;
default: default:
throw new BioFormatsImageException("Unsupported image format: " + mimeType); throw new BioFormatsImageException("Unsupported image format: " + mimeType);
@ -178,12 +178,12 @@ public class BioFormatsImageThumbnail {
// System.out.println("series count: " + seriesCount); // System.out.println("series count: " + seriesCount);
// System.out.println("image count: " + reader.getImageCount()); // System.out.println("image count: " + reader.getImageCount());
// System.out.println("resolution: " + reader.getResolutionCount()); // System.out.println("resolution: " + reader.getResolutionCount());
// System.out.println("thubmail series: " + series); // System.out.println("thumbnail series: " + series);
ret = reader.openThumbImage(no); ret = reader.openThumbImage(no);
final boolean is16bit = reader.getBitsPerPixel() > 8; final boolean is16bit = reader.getBitsPerPixel() > 8;
final boolean isGrayScale = ret.getSampleModel().getNumBands() == 1; final boolean isGrayScale = ret.getSampleModel().getNumBands() == 1;
if (is16bit || isGrayScale) { if (is16bit || isGrayScale) {
// perform auto scalling if 16bit or gray scale thumbnail image. // perform auto scaling if 16bit or gray scale thumbnail image.
ret = AWTImageTools.autoscale(ret); ret = AWTImageTools.autoscale(ret);
} }
} catch (final Throwable t) { } catch (final Throwable t) {