NASA-PDS / transform

Transforms PDS3 and PDS4 product labels and data into various formats.
https://nasa-pds.github.io/transform/
Apache License 2.0
14 stars 1 forks source link

Add support for transforming PDS3 image files to 16-bit output #15

Open jordanpadams opened 4 years ago

jordanpadams commented 4 years ago

Is your feature request related to a problem? Please describe. Per user request, would like the capability to convert a 16bit PDS3 image to a 16bit output viewable image format.

Currently all images are output to 8bit formats.

isenberg commented 2 years ago

Same for PDS4.

I'd say the current processing is a bug where it just linearly scales for example the raw EDR files from Perseverance Rover SignedMSB2 (16 bit) to 8 bit PNG or 8 bit TIFF. The time of 8 bit numbers of image intensity is over for many years now.

Or does some other free software exist to convert the current Mars 2020 raw images on current macOS? NASAView for example isn't available anymore for current macOS.

Example: Download EDR pair of .IMG/.XML from the _raw directories of https://pds-imaging.jpl.nasa.gov/data/mars2020 and then run it:

% grep data_type SOME_ID.xml
        <data_type>SignedMSB2</data_type>

% /usr/libexec/java_home -v 1.8.0 --exec java -showversion \
  -Dcom.sun.media.jai.disableMediaLib=true \
  -Doverwrite.output=true -cp $HOME/git/transform/target/transform-*-SNAPSHOT-jar-with-dependencies.jar \
  gov.nasa.pds.transform.TransformLauncher -f png SOME_ID.xml

% file SOME_ID.png
SOME_ID.png: PNG image data, 1280 x 960, 8-bit/color RGB, non-interlaced

In case anyone is wondering about how to build the jar with dependencies here from source. Add the following lines in pom.xml after

               <goal>single</goal>
             </goals>
             <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>

With that a simple git clone and mvn package is needed to build it on OpenJDK 8.

isenberg commented 2 years ago

In case others want to give it a try:

I looked a bit into the code around src/main/java/gov/nasa/pds/transform/product/Pds4ImageTransformer.java and the 8 bit output appears to be caused by the JAI image writer outside of the PDS tools, but I'm not 100% sure yet. At least the used gov.nasa.pds.objectAccess.ImageExporter is producing internally 16 bit arrays (ElementArray.getDataType() returns SignedMSB2) though later that's reduced to 8.

Even enforcing with ((TwoDImageExporter)exporter).setTargetPixelDepth(16) didn't help. Still 8bit output.

Switching to the latest versions of the PDS loader libraries didn't help either. It's simple, just change in pom.xml:

     <dependency>
       <groupId>gov.nasa.pds</groupId>
       <artifactId>pds3-product-tools</artifactId>
-      <version>4.0.1</version>
+      <version>4.1.0</version>
       <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>gov.nasa.pds</groupId>
       <artifactId>pds4-jparser</artifactId>
-      <version>1.2.0</version>
+      <version>2.2.1</version>
       <scope>compile</scope>
     </dependency>
     <dependency>

If it's due to the old JAI, a solution may be to replace that by https://eclipse.github.io/imagen/migration which uses internally the newer javax.imageio.ImageIO. But even the old JAI already supported 32bit/channel images and at least 16bit/channel PNG writing.