Skip to content

Commit

Permalink
forceRGB parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrd committed Aug 30, 2023
1 parent fb1a885 commit 181ff99
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion generic-archiver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Generic library to write archives folders.</description>
Expand Down
2 changes: 1 addition & 1 deletion hdfs-archiver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library to read and write archives on HDFS.</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
<packaging>pom</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>Parent project of pyramidio, a Java tool to read and write image pyramids. Bio-Formats enhanced version.</description>
Expand Down
2 changes: 1 addition & 1 deletion pyramidio-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Command line interface to build image pyramids.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class FilesArchiverFactory {
public static FilesArchiver createFromURI(String uri)
throws IOException {
try {
URI outputURI = new URI(uri);
URI outputURI = new URI(uri.replace(" ", "%20"));
String scheme = outputURI.getScheme();
logger.info("Got scheme " + scheme + " for URI " + uri);

Expand Down
10 changes: 7 additions & 3 deletions pyramidio-cli/src/main/java/gov/nist/isg/pyramidio/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public static void main(String[] args) {
"Tile format such as jpg, png "
+ "(default to the same format than the input)");
options.addOption(tileFormatOption);

Option forceRgbOption = new Option("rgb", "forceRGB", false,
"The output will be forced to RGB888 discarding the input image properties.");
options.addOption(forceRgbOption);

Option parallelismOption = new Option("p", "parallelism", true,
"Number of threads to use (default to number of cpu cores).");
Expand Down Expand Up @@ -139,13 +143,13 @@ public static void main(String[] args) {

try {
long start = System.currentTimeMillis();
logger.info(inputFile + " - is about to start to build a pyramid.");
logger.info(inputFile + " - is about to start to build a pyramid. Output folder: " + outputFolder);

try (FilesArchiver archiver = FilesArchiverFactory
.createFromURI(outputFolder)) {
spb.buildPyramid(
//@darwinjob new DirectImageReader(inputFile),
new BioFormatsImageReader(inputFile),
new BioFormatsImageReader(inputFile, commandLine.hasOption(forceRgbOption.getOpt())),
inputFileBaseName,
archiver,
parallelism,
Expand Down Expand Up @@ -224,6 +228,6 @@ private static float getCalculatedPercentage(File inputFile) {
}

private static void printHelp(Options options) {
new HelpFormatter().printHelp("pyramidio", options);
new HelpFormatter().printHelp("java -jar pyramidio-cli-[version].jar -i my-image.jpg -o (my-output-folder || scheme:///path/file[.tar, .seq])", options);
}
}
2 changes: 1 addition & 1 deletion pyramidio/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library to read and write image pyramids.</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.uio.nesys.pyramidio;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
Expand All @@ -22,13 +23,32 @@ public class BioFormatsImageReader implements PartialImageReader {

private BufferedImageReader bufferedImageReader;
private ImageReader imageReader;
private boolean forceRGB;

private static final Logger logger = Logger.getLogger(
BioFormatsImageReader.class.getName());

/**
* Processing non RGB888 image seems to be an issue. See https://github.com/darwinjob/pyramidio-bioformats/issues/13
* If you see any output artifacts try forceRGB=true
* @param file
* @throws FormatException
* @throws IOException
*/
public BioFormatsImageReader(File file) throws FormatException, IOException {
this (file, false);
}

/**
*
* @param file
* @param forceRGB
* @throws FormatException
* @throws IOException
*/
public BioFormatsImageReader(File file, boolean forceRGB) throws FormatException, IOException {
imageReader = new ImageReader();
imageReader.setId(file.getPath());
this.forceRGB = forceRGB;
bufferedImageReader = new BufferedImageReader(imageReader);
}

Expand All @@ -46,12 +66,25 @@ public BufferedImage read() throws IOException {
public BufferedImage read(Rectangle rectangle) throws IOException {
try {
logger.fine("Reading rectangle: " + rectangle);
return bufferedImageReader.openImage(0, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
BufferedImage bi = bufferedImageReader.openImage(0, rectangle.x, rectangle.y, rectangle.width, rectangle.height);

if (forceRGB) {
return convertToRGB(bi);
}
return bi;
} catch (FormatException e) {
throw new IOException(e);
}
}

private BufferedImage convertToRGB(BufferedImage src) {
BufferedImage img= new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g2d= img.createGraphics();
g2d.drawImage(src, 0, 0, null);
g2d.dispose();
return img;
}

@Override
public int getWidth() {
return imageReader.getSizeX();
Expand Down
2 changes: 1 addition & 1 deletion s3-archiver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library to read and write archives on Amazon S3.</description>
Expand Down
2 changes: 1 addition & 1 deletion tar-archiver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>gov.nist.isg</groupId>
<artifactId>pyramidio-parent</artifactId>
<version>1.1.5</version>
<version>1.1.6</version>
</parent>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library to read and write archives in tar files.</description>
Expand Down

0 comments on commit 181ff99

Please sign in to comment.