16-bit gray PNG write broken?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

16-bit gray PNG write broken?

G. Jehle
Hi everyone,

I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).

Whenever I try to save a simple '16-bit grayscale' image
as PNG, ImageJ saves a '8-bit/color RGB' image instead.

I generated a 16-bit gray PNG using Matlab.
Opening the PNG in ImageJ; works just fine with ImageJ
recognizing the file as 16-bit gray, all values look ok.

However, using 'File > Save As > PNG...' on the very
file just opened results in a '8-bit/color RGB' PNG to be
saved.

Any ideas to why this might happen?

//
Best regards,

G. Jehle

HTWG Konstanz - University of Applied Sciences
Fakultät Informatik

HTWG Konstanz
Fakultät Informatik
Brauneggerstraße 55
D-78462 Konstanz
www.htwg-konstanz.de
Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

Harry Parker
This is a long standing limitation of ImageJ's built-in PNG writer.

The solution is to install the "Image IO" plugin. This adds the ability to save 16 bit PNG files correctly, as well as other formats such as compressed and tiled TIFF images.  

See the Image IO plugin home page at
http://ij-plugins.sourceforge.net/plugins/imageio

and download it from
http://sourceforge.net/project/showfiles.php?group_id=44711&package_id=37687

 
--
Harry Parker
Senior Imaging Systems Engineer
Digital Imaging Systems, Inc.



----- Original Message ----
From: G. Jehle <[hidden email]>
To: [hidden email]
Sent: Tuesday, September 9, 2008 1:48:02 PM
Subject: 16-bit gray PNG write broken?

Hi everyone,

I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).

Whenever I try to save a simple '16-bit grayscale' image
as PNG, ImageJ saves a '8-bit/color RGB' image instead.

I generated a 16-bit gray PNG using Matlab.
Opening the PNG in ImageJ; works just fine with ImageJ
recognizing the file as 16-bit gray, all values look ok.

However, using 'File > Save As > PNG...' on the very
file just opened results in a '8-bit/color RGB' PNG to be
saved.

Any ideas to why this might happen?

//
Best regards,

G. Jehle

HTWG Konstanz - University of Applied Sciences
Fakultät Informatik

HTWG Konstanz
Fakultät Informatik
Brauneggerstraße 55
D-78462 Konstanz
www.htwg-konstanz.de




Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

Wayne Rasband
In reply to this post by G. Jehle
On Sep 9, 2008, at 1:48 PM, G. Jehle wrote:

> Hi everyone,
>
> I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).
>
> Whenever I try to save a simple '16-bit grayscale' image
> as PNG, ImageJ saves a '8-bit/color RGB' image instead.
>
> I generated a 16-bit gray PNG using Matlab.
> Opening the PNG in ImageJ; works just fine with ImageJ
> recognizing the file as 16-bit gray, all values look ok.
>
> However, using 'File > Save As > PNG...' on the very
> file just opened results in a '8-bit/color RGB' PNG to be
> saved.
>
> Any ideas to why this might happen?

ImageJ 1.41d and later saves 16-bit and 32-bit images as 8-bit PNGs.
Earlier versions saved as RGB. ImageJ converts to 8-bits when saving in
PNG format so that the images are more likely to display correctly in
other applications. Save in TIFF format if you need to preserve 16-bit
or 32-bit values.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

G. Jehle
Quoting Wayne Rasband <[hidden email]>:

> On Sep 9, 2008, at 1:48 PM, G. Jehle wrote:
>
> > Hi everyone,
> >
> > I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).
> >
> > Whenever I try to save a simple '16-bit grayscale' image
> > as PNG, ImageJ saves a '8-bit/color RGB' image instead.
> >
> > I generated a 16-bit gray PNG using Matlab.
> > Opening the PNG in ImageJ; works just fine with ImageJ
> > recognizing the file as 16-bit gray, all values look ok.
> >
> > However, using 'File > Save As > PNG...' on the very
> > file just opened results in a '8-bit/color RGB' PNG to be
> > saved.
> >
> > Any ideas to why this might happen?
>
> ImageJ 1.41d and later saves 16-bit and 32-bit images as 8-bit PNGs.
> Earlier versions saved as RGB. ImageJ converts to 8-bits when saving in
> PNG format so that the images are more likely to display correctly in
> other applications. Save in TIFF format if you need to preserve 16-bit
> or 32-bit values.

Thanks for the info wayne.

Although I have to say that, IMHO, this is bad.
Changing bit depth without giving a warning, even more so
in a case where the image format actually supports the higher
bit depth is very, very misleading and a source for error and frustration.

Are there any considerations for future versions of ImageJ
to make this behavior optional?
I'd really like to use 16-bit grayscale PNG.

Where can I submit a bug report? (I'm serious)

> -wayne
>


//
Best regards,

G. Jehle

HTWG Konstanz - University of Applied Sciences
Fakultät Informatik

HTWG Konstanz
Fakultät Informatik
Brauneggerstraße 55
D-78462 Konstanz
www.htwg-konstanz.de
Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

Wayne Rasband
Here is a plugin that saves a 16-bit image as a 16-bit PNG.

-wayne

import ij.plugin.*;
import ij.*;
import ij.io.*;
import ij.process.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
/** Saves a 16-bit image in PNG format.  */
public class PNG16_Writer implements PlugIn {
     public void run(String path) {
         ImagePlus imp = IJ.getImage();
         if (imp.getBitDepth()!=16)
             {IJ.error("16-bit image reqired"); return;}
         SaveDialog sd = new SaveDialog("Save as PNG...",
imp.getTitle(), ".png");
         String name = sd.getFileName();
         if (name==null) return;
         String dir = sd.getDirectory();
         try {
               ShortProcessor sp = (ShortProcessor )imp.getProcessor();
               BufferedImage bi = sp.get16BitBufferedImage();
                   ImageIO.write(bi, "png", new File( dir+name));
         } catch (Exception e) {
              IJ.showMessage("PNG16 Writer", "An error occured writing
the file.\n \n" + e);
         }
     }
}


On Sep 9, 2008, at 3:22 PM, G. Jehle wrote:

> Quoting Wayne Rasband <[hidden email]>:
>
>> On Sep 9, 2008, at 1:48 PM, G. Jehle wrote:
>>
>>> Hi everyone,
>>>
>>> I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).
>>>
>>> Whenever I try to save a simple '16-bit grayscale' image
>>> as PNG, ImageJ saves a '8-bit/color RGB' image instead.
>>>
>>> I generated a 16-bit gray PNG using Matlab.
>>> Opening the PNG in ImageJ; works just fine with ImageJ
>>> recognizing the file as 16-bit gray, all values look ok.
>>>
>>> However, using 'File > Save As > PNG...' on the very
>>> file just opened results in a '8-bit/color RGB' PNG to be
>>> saved.
>>>
>>> Any ideas to why this might happen?
>>
>> ImageJ 1.41d and later saves 16-bit and 32-bit images as 8-bit PNGs.
>> Earlier versions saved as RGB. ImageJ converts to 8-bits when saving
>> in
>> PNG format so that the images are more likely to display correctly in
>> other applications. Save in TIFF format if you need to preserve 16-bit
>> or 32-bit values.
>
> Thanks for the info wayne.
>
> Although I have to say that, IMHO, this is bad.
> Changing bit depth without giving a warning, even more so
> in a case where the image format actually supports the higher
> bit depth is very, very misleading and a source for error and
> frustration.
>
> Are there any considerations for future versions of ImageJ
> to make this behavior optional?
> I'd really like to use 16-bit grayscale PNG.
>
> Where can I submit a bug report? (I'm serious)
>
>> -wayne
>>
>
>
> //
> Best regards,
>
> G. Jehle
>
> HTWG Konstanz - University of Applied Sciences
> Fakultät Informatik
>
> HTWG Konstanz
> Fakultät Informatik
> Brauneggerstraße 55
> D-78462 Konstanz
> www.htwg-konstanz.de
>
Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

G. Jehle
Quoting Wayne Rasband <[hidden email]>:

> Here is a plugin that saves a 16-bit image as a 16-bit PNG.
>
> -wayne

I bow to you in awe and thankfulness!

Thanks a lot for the extremely quick workaround.

//
Regards,
Gregor

> import ij.plugin.*;
> import ij.*;
> import ij.io.*;
> import ij.process.*;
> import java.io.*;
> import java.awt.image.*;
> import javax.imageio.ImageIO;
> /** Saves a 16-bit image in PNG format.  */
> public class PNG16_Writer implements PlugIn {
>      public void run(String path) {
>          ImagePlus imp = IJ.getImage();
>          if (imp.getBitDepth()!=16)
>              {IJ.error("16-bit image reqired"); return;}
>          SaveDialog sd = new SaveDialog("Save as PNG...",
> imp.getTitle(), ".png");
>          String name = sd.getFileName();
>          if (name==null) return;
>          String dir = sd.getDirectory();
>          try {
>                ShortProcessor sp = (ShortProcessor )imp.getProcessor();
>                BufferedImage bi = sp.get16BitBufferedImage();
>   ImageIO.write(bi, "png", new File( dir+name));
>          } catch (Exception e) {
>               IJ.showMessage("PNG16 Writer", "An error occured writing
> the file.\n \n" + e);
>          }
>      }
> }
>
>
> On Sep 9, 2008, at 3:22 PM, G. Jehle wrote:
>
> > Quoting Wayne Rasband <[hidden email]>:
> >
> >> On Sep 9, 2008, at 1:48 PM, G. Jehle wrote:
> >>
> >>> Hi everyone,
> >>>
> >>> I'm running ImageJ 1.39u on Ubuntu GNU/Linux (x86_64).
> >>>
> >>> Whenever I try to save a simple '16-bit grayscale' image
> >>> as PNG, ImageJ saves a '8-bit/color RGB' image instead.
> >>>
> >>> I generated a 16-bit gray PNG using Matlab.
> >>> Opening the PNG in ImageJ; works just fine with ImageJ
> >>> recognizing the file as 16-bit gray, all values look ok.
> >>>
> >>> However, using 'File > Save As > PNG...' on the very
> >>> file just opened results in a '8-bit/color RGB' PNG to be
> >>> saved.
> >>>
> >>> Any ideas to why this might happen?
> >>
> >> ImageJ 1.41d and later saves 16-bit and 32-bit images as 8-bit PNGs.
> >> Earlier versions saved as RGB. ImageJ converts to 8-bits when saving
> >> in
> >> PNG format so that the images are more likely to display correctly in
> >> other applications. Save in TIFF format if you need to preserve 16-bit
> >> or 32-bit values.
> >
> > Thanks for the info wayne.
> >
> > Although I have to say that, IMHO, this is bad.
> > Changing bit depth without giving a warning, even more so
> > in a case where the image format actually supports the higher
> > bit depth is very, very misleading and a source for error and
> > frustration.
> >
> > Are there any considerations for future versions of ImageJ
> > to make this behavior optional?
> > I'd really like to use 16-bit grayscale PNG.
> >
> > Where can I submit a bug report? (I'm serious)
> >
> >> -wayne
> >>
> >
> >
> > //
> > Best regards,
> >
> > G. Jehle
> >
> > HTWG Konstanz - University of Applied Sciences
> > Fakultät Informatik
> >
> > HTWG Konstanz
> > Fakultät Informatik
> > Brauneggerstraße 55
> > D-78462 Konstanz
> > www.htwg-konstanz.de
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: 16-bit gray PNG write broken?

weicap
In reply to this post by Wayne Rasband
Many thanks.