Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
705e7f7e7d
|
|||
b00a67c5d0 | |||
e415ead1ec | |||
b8bfa77cc2 | |||
0df492ff14 | |||
4ea2dc7110 | |||
a4bd4b0b96 | |||
dab69b174f |
@ -13,12 +13,12 @@ mvn package
|
|||||||
|
|
||||||
### run by jar
|
### run by jar
|
||||||
```shell
|
```shell
|
||||||
java -jar ./target/dist/lib/bioformats-imageinfo-1.1.1.jar "[path to image file]"
|
java -jar ./target/dist/lib/bioformats-imageinfo-1.1.3.jar "[path to image file]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### run by fat jar
|
### run by fat jar
|
||||||
```shell
|
```shell
|
||||||
java -jar ./target/bioformats-imageinfo-1.1.1-jar-with-dependencies.jar "[path to image file]"
|
java -jar ./target/bioformats-imageinfo-1.1.3-jar-with-dependencies.jar "[path to image file]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### library usage
|
### library usage
|
||||||
|
111
pom.xml
111
pom.xml
@ -1,17 +1,15 @@
|
|||||||
<?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.1</version>
|
<version>1.1.3</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.10.1</bio-formats.version>
|
<bio-formats.version>6.12.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>
|
||||||
@ -27,14 +25,39 @@
|
|||||||
<artifactId>bio-formats-tools</artifactId>
|
<artifactId>bio-formats-tools</artifactId>
|
||||||
<version>${bio-formats.version}</version>
|
<version>${bio-formats.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-nop</artifactId>
|
||||||
|
<version>1.7.30</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce-maven</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</requireMavenVersion>
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-dependencies</id>
|
<id>copy-dependencies</id>
|
||||||
@ -44,59 +67,35 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<overWriteIfNewer>true</overWriteIfNewer>
|
<overWriteIfNewer>true</overWriteIfNewer>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<addClasspath>true</addClasspath>
|
<addClasspath>true</addClasspath>
|
||||||
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.4.1</version>
|
|
||||||
<configuration>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assembly</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>appassembler-maven-plugin</artifactId>
|
<artifactId>appassembler-maven-plugin</artifactId>
|
||||||
<version>1.10</version>
|
<version>2.1.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<assembleDirectory>${project.build.directory}/dist</assembleDirectory>
|
<assembleDirectory>${project.build.directory}/dist</assembleDirectory>
|
||||||
<repositoryLayout>flat</repositoryLayout>
|
<repositoryLayout>flat</repositoryLayout>
|
||||||
<repositoryName>lib</repositoryName>
|
<repositoryName>lib</repositoryName>
|
||||||
<programs>
|
<programs>
|
||||||
<program>
|
<program>
|
||||||
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
||||||
<id>${project.name}</id>
|
<id>${project.name}</id>
|
||||||
</program>
|
</program>
|
||||||
</programs>
|
</programs>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -109,10 +108,37 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.5.0</version>
|
||||||
|
<configuration>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>${bioformats-imageinfo.mainClass}</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptors>
|
||||||
|
<descriptor>src/main/assembly/assembly.xml</descriptor>
|
||||||
|
</descriptors>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.owasp</groupId>
|
<groupId>org.owasp</groupId>
|
||||||
<artifactId>dependency-check-maven</artifactId>
|
<artifactId>dependency-check-maven</artifactId>
|
||||||
<version>7.1.1</version>
|
<version>8.2.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -128,15 +154,18 @@
|
|||||||
<pluginRepository>
|
<pluginRepository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<name>Central Repository</name>
|
<name>Central Repository</name>
|
||||||
<url>https://repo.maven.apache.org/maven2</url>
|
<!-- <url>https://repo.maven.apache.org/maven2</url> -->
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
<layout>default</layout>
|
<layout>default</layout>
|
||||||
</pluginRepository>
|
</pluginRepository>
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>central</id>
|
<id>central</id>
|
||||||
<name>Central Repository</name>
|
<name>Central Repository</name>
|
||||||
<url>https://repo.maven.apache.org/maven2</url>
|
<!-- <url>https://repo.maven.apache.org/maven2</url> -->
|
||||||
|
<url>https://repo1.maven.org/maven2/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>ome</id>
|
<id>ome</id>
|
||||||
|
35
src/main/assembly/assembly.xml
Normal file
35
src/main/assembly/assembly.xml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?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"
|
||||||
|
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>
|
||||||
|
<formats>
|
||||||
|
<format>tar.gz</format>
|
||||||
|
<format>tar.bz2</format>
|
||||||
|
<format>zip</format>
|
||||||
|
</formats>
|
||||||
|
<fileSets>
|
||||||
|
<fileSet>
|
||||||
|
<directory>target/dist/bin</directory>
|
||||||
|
<outputDirectory>bin</outputDirectory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>*.bat</exclude>
|
||||||
|
</excludes>
|
||||||
|
<directoryMode>0755</directoryMode>
|
||||||
|
<fileMode>0755</fileMode>
|
||||||
|
</fileSet>
|
||||||
|
<fileSet>
|
||||||
|
<directory>target/dist/bin</directory>
|
||||||
|
<outputDirectory>bin</outputDirectory>
|
||||||
|
<includes>
|
||||||
|
<include>*.bat</include>
|
||||||
|
</includes>
|
||||||
|
<directoryMode>0755</directoryMode>
|
||||||
|
<fileMode>0644</fileMode>
|
||||||
|
</fileSet>
|
||||||
|
</fileSets>
|
||||||
|
<dependencySets>
|
||||||
|
<dependencySet>
|
||||||
|
<outputDirectory>lib</outputDirectory>
|
||||||
|
</dependencySet>
|
||||||
|
</dependencySets>
|
||||||
|
</assembly>
|
@ -256,12 +256,12 @@ public class BioFormatsImageInfo {
|
|||||||
} else {
|
} else {
|
||||||
final String path = args[0];
|
final String path = args[0];
|
||||||
try {
|
try {
|
||||||
DebugTools.enableLogging("ERROR");
|
DebugTools.enableLogging("OFF");
|
||||||
format = readMetadata(path, metadata);
|
format = readMetadata(path, metadata);
|
||||||
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
BioFormatsImageThumbnail.readThumbnail(path, thumbnail);
|
||||||
} catch (BioFormatsImageException e) {
|
} catch (Throwable t) {
|
||||||
status = false;
|
status = false;
|
||||||
message = e.getMessage();
|
message = t.getMessage();
|
||||||
metadata.clear();
|
metadata.clear();
|
||||||
thumbnail.clear();
|
thumbnail.clear();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import javax.imageio.stream.ImageOutputStream;
|
|||||||
import loci.common.DebugTools;
|
import loci.common.DebugTools;
|
||||||
import loci.formats.FormatException;
|
import loci.formats.FormatException;
|
||||||
import loci.formats.ImageReader;
|
import loci.formats.ImageReader;
|
||||||
|
import loci.formats.gui.AWTImageTools;
|
||||||
import loci.formats.gui.BufferedImageReader;
|
import loci.formats.gui.BufferedImageReader;
|
||||||
|
|
||||||
public class BioFormatsImageThumbnail {
|
public class BioFormatsImageThumbnail {
|
||||||
@ -89,8 +90,10 @@ public class BioFormatsImageThumbnail {
|
|||||||
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
|
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
|
||||||
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
|
final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
|
||||||
final ImageWriteParam param = writer.getDefaultWriteParam();
|
final ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
if (param.canWriteCompressed()) {
|
||||||
param.setCompressionQuality(quality);
|
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
param.setCompressionQuality(quality);
|
||||||
|
}
|
||||||
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();
|
||||||
@ -108,7 +111,10 @@ public class BioFormatsImageThumbnail {
|
|||||||
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
|
final ImageOutputStream ios = ImageIO.createImageOutputStream(baos);) {
|
||||||
final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
|
final ImageWriter writer = ImageIO.getImageWritersByFormatName("png").next();
|
||||||
final ImageWriteParam param = writer.getDefaultWriteParam();
|
final ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
if (param.canWriteCompressed()) {
|
||||||
|
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
param.setCompressionQuality(0.0f);
|
||||||
|
}
|
||||||
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();
|
||||||
@ -151,6 +157,8 @@ public class BioFormatsImageThumbnail {
|
|||||||
reader.setId(path);
|
reader.setId(path);
|
||||||
} catch (FormatException | IOException e) {
|
} catch (FormatException | IOException e) {
|
||||||
throw new BioFormatsImageException("unsupported file: " + path);
|
throw new BioFormatsImageException("unsupported file: " + path);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new BioFormatsImageException(t);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int series = 0;
|
int series = 0;
|
||||||
@ -163,19 +171,28 @@ public class BioFormatsImageThumbnail {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.setSeries(series);
|
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("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("thubmail series: " + series);
|
||||||
ret = reader.openThumbImage(no);
|
ret = reader.openThumbImage(no);
|
||||||
} catch (final Throwable e) {
|
final boolean is16bit = reader.getBitsPerPixel() > 8;
|
||||||
for (Throwable t = e; t != null; t = t.getCause()) {
|
final boolean isGrayScale = ret.getSampleModel().getNumBands() == 1;
|
||||||
if (t instanceof OutOfMemoryError) {
|
if (is16bit || isGrayScale) {
|
||||||
|
// perform auto scalling if 16bit or gray scale thumbnail image.
|
||||||
|
ret = AWTImageTools.autoscale(ret);
|
||||||
|
}
|
||||||
|
} catch (final Throwable t) {
|
||||||
|
for (Throwable e = t; e != null; e = e.getCause()) {
|
||||||
|
if (e instanceof OutOfMemoryError) {
|
||||||
throw new BioFormatsImageException("out of memory");
|
throw new BioFormatsImageException("out of memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new BioFormatsImageException(e);
|
throw new BioFormatsImageException(t);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
@ -226,7 +243,7 @@ public class BioFormatsImageThumbnail {
|
|||||||
thumbnail.put("height", height);
|
thumbnail.put("height", height);
|
||||||
thumbnail.put("mimeType", mimeType);
|
thumbnail.put("mimeType", mimeType);
|
||||||
thumbnail.put("url", dataUri);
|
thumbnail.put("url", dataUri);
|
||||||
} catch (final BioFormatsImageException e) {
|
} catch (final Throwable t) {
|
||||||
// ignore
|
// ignore
|
||||||
ret = false;
|
ret = false;
|
||||||
}
|
}
|
||||||
@ -234,22 +251,23 @@ public class BioFormatsImageThumbnail {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(final String[] args) throws BioFormatsImageException {
|
public static void main(final String[] args) {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
System.out.println("filename argument required");
|
System.out.println("filename argument required");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
final String path = args[0];
|
final String path = args[0];
|
||||||
try {
|
try {
|
||||||
DebugTools.enableLogging("ERROR");
|
DebugTools.enableLogging("OFF");
|
||||||
BufferedImage image = getImageFromBioFormatsFile(path);
|
BufferedImage image = getImageFromBioFormatsFile(path);
|
||||||
final String format = image.getColorModel().hasAlpha() ? "png" : "jpeg";
|
final String format = image.getColorModel().hasAlpha() ? "png" : "jpeg";
|
||||||
// image = resize(image, 160, 160);
|
// image = resize(image, 160, 160);
|
||||||
final String dataUri = getDataUri(image, "image/" + format);
|
final String dataUri = getDataUri(image, "image/" + format);
|
||||||
System.out.println(dataUri);
|
System.out.println(dataUri);
|
||||||
// saveFile(dataUri, "/var/tmp/thumbnail." + format);
|
// saveFile(dataUri, "/var/tmp/thumbnail." + format);
|
||||||
} catch (final BioFormatsImageException e) {
|
} catch (final Throwable t) {
|
||||||
System.out.println(e.getMessage());
|
// t.printStackTrace();
|
||||||
|
System.out.println(t.getMessage());
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user