12- and 14-bit PNGs in imageJ

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

12- and 14-bit PNGs in imageJ

Nathaniel Cunningham
I have some 12-bit and 14-bit PNG images (generated in LabVIEW).  When
opened in imageJ, they are read in as 16-bit images (expected), but their
values are incorrect.  Examining some of the values, and comparing with the
correct values for those pixels, I find that the first 2 (first 4) bits of
the 14-bit (12-bit) values are being repeated, in order to generate the
16-bit values.  (Perhaps the extra bits are actually being taken from
adjacent pixels) E.g.:

the 12-bit value 262
000100000110
is read by imageJ as the 16-bit value 4193
0001000001100001

and the 14-bit value 10356
10100001110100
is read as the 16-bit value 41426
1010000111010010

I am able to read these same images in correctly with IDL.  Is there a way
to ensure that ImageJ also reads them properly?  Might there be something
wrong with my PNG images themselves?  I've posted one example at the link
below:
The file '14-bit_example.png' (345 KB) is available for download at
http://dropbox.unl.edu/uploads/20090216/025c949ee3bfe378/14-bit_example.png
for the next 7 days.

Thanks for any help.
--Nathaniel
Reply | Threaded
Open this post in threaded view
|

File Conversion bug and Batch Converter

Hugo A. M. Torres
  Hello again listmates,

If I try to convert 16bit color images into 8bit grayscale by doing
"image>type>8bit" I get an RGB stack instead.

The way I found around that is doing "image, color, stack to rgb"
followed by "image, type, 8bit".

Shouldn't I be able to convert directly? Maybe its a bug...

Also, I tried to apply the batch converter plugin to convert all the
files from a folder to 8bit-TIFF and this is what I get:

java.lang.ClassCastException: [S cannot be cast to [B
        at ij.io.ImageWriter.write8BitStack(ImageWriter.java:38)
        at ij.io.ImageWriter.write(ImageWriter.java:214)
        at ij.io.TiffEncoder.write(TiffEncoder.java:118)
        at ij.io.TiffEncoder.write(TiffEncoder.java:138)
        at ij.io.FileSaver.saveAsTiffStack(FileSaver.java:126)
        at ij.io.FileSaver.saveAsTiff(FileSaver.java:79)
        at ij.plugin.filter.Writer.run(Writer.java:20)
        at
ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:245)
        at
ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:102)
        at ij.IJ.runPlugIn(IJ.java:151)
        at ij.Executer.runCommand(Executer.java:119)
        at ij.Executer.run(Executer.java:58)
        at ij.IJ.run(IJ.java:241)
        at ij.IJ.run(IJ.java:284)
        at ij.IJ.saveAs(IJ.java:1312)
        at ij.IJ.saveAs(IJ.java:1249)
        at Batch_Converter.convert(Batch_Converter.java:59)
        at Batch_Converter.run(Batch_Converter.java:26)
        at ij.IJ.runUserPlugIn(IJ.java:176)
        at ij.IJ.runPlugIn(IJ.java:142)
        at ij.Executer.runCommand(Executer.java:119)
        at ij.Executer.run(Executer.java:58)
        at java.lang.Thread.run(Thread.java:619)
Reply | Threaded
Open this post in threaded view
|

Re: 12- and 14-bit PNGs in imageJ

Nathaniel Cunningham
In reply to this post by Nathaniel Cunningham
I used imagemagick's "convert" command to convert one of these PNGs to
TIFF.  The resulting TIFF has the wrong values -- whether read by ImageJ or
IDL.  I also read in one of the problematic PNGs with IDL, then saved the
resulting (correct) image array to a new PNG.  ImageJ reads the correct
values from this new file.

I conclude that the problem lies with the original PNG image file, which
apparently gives inconsistent results among image readers/viewers; I will
investigate further.

Thanks,
Nathaniel

On Tue, Feb 10, 2009 at 12:09 AM, Rasband Wayne <[hidden email]> wrote:

> Nathaniel,
>
> This is not something I can fix since ImageJ uses the javaIO  package to
> read PNGs. Can LabView save in TIFF format? If necessary, I can fix problems
> in ImageJ's TIFF reader.
>
> -wayne
>
>
>
> On Feb 9, 2009, at 5:27 PM, Nathaniel Cunningham wrote:
>
>  I have some 12-bit and 14-bit PNG images (generated in LabVIEW).  When
>> opened in imageJ, they are read in as 16-bit images (expected), but their
>> values are incorrect.  Examining some of the values, and comparing with
>> the
>> correct values for those pixels, I find that the first 2 (first 4) bits of
>> the 14-bit (12-bit) values are being repeated, in order to generate the
>> 16-bit values.  (Perhaps the extra bits are actually being taken from
>> adjacent pixels) E.g.:
>>
>> the 12-bit value 262
>> 000100000110
>> is read by imageJ as the 16-bit value 4193
>> 0001000001100001
>>
>> and the 14-bit value 10356
>> 10100001110100
>> is read as the 16-bit value 41426
>> 1010000111010010
>>
>> I am able to read these same images in correctly with IDL.  Is there a way
>> to ensure that ImageJ also reads them properly?  Might there be something
>> wrong with my PNG images themselves?  I've posted one example at the link
>> below:
>> The file '14-bit_example.png' (345 KB) is available for download at
>> http://dropbox.unl.edu/uploads/20090216/025c949ee3bfe378/14-
>> bit_example.png
>> for the next 7 days.
>>
>> Thanks for any help.
>> --Nathaniel
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: File Conversion bug and Batch Converter

Wayne Rasband
In reply to this post by Hugo A. M. Torres
>   Hello again listmates,
>
> If I try to convert 16bit color images into 8bit grayscale by doing
> "image>type>8bit" I get an RGB stack instead.

The Image>Type>8-bit command converts 16-bit composite color images  
(e.g., 48-bit RGB TIFFs) into 8-bit composite color images. You can use  
Image>Type>RGB Color followed by Image>Type>8-bit to convert a  
composite color image into an 8-bit grayscale image.

> The way I found around that is doing "image, color, stack to rgb"
> followed by "image, type, 8bit".
>
> Shouldn't I be able to convert directly? Maybe its a bug...
>
> Also, I tried to apply the batch converter plugin to convert all the
> files from a folder to 8bit-TIFF and this is what I get:

There is an updated version of the Batch_Converter plugin at

    http://rsb.info.nih.gov/ij/plugins/batch-converter.html

that fixed this bug.

-wayne

> java.lang.ClassCastException: [S cannot be cast to [B
> at ij.io.ImageWriter.write8BitStack(ImageWriter.java:38)
> at ij.io.ImageWriter.write(ImageWriter.java:214)
> at ij.io.TiffEncoder.write(TiffEncoder.java:118)
> at ij.io.TiffEncoder.write(TiffEncoder.java:138)
> at ij.io.FileSaver.saveAsTiffStack(FileSaver.java:126)
> at ij.io.FileSaver.saveAsTiff(FileSaver.java:79)
> at ij.plugin.filter.Writer.run(Writer.java:20)
> at
> ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.
> java:245)
> at
> ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:102)
> at ij.IJ.runPlugIn(IJ.java:151)
> at ij.Executer.runCommand(Executer.java:119)
> at ij.Executer.run(Executer.java:58)
> at ij.IJ.run(IJ.java:241)
> at ij.IJ.run(IJ.java:284)
> at ij.IJ.saveAs(IJ.java:1312)
> at ij.IJ.saveAs(IJ.java:1249)
> at Batch_Converter.convert(Batch_Converter.java:59)
> at Batch_Converter.run(Batch_Converter.java:26)
> at ij.IJ.runUserPlugIn(IJ.java:176)
> at ij.IJ.runPlugIn(IJ.java:142)
> at ij.Executer.runCommand(Executer.java:119)
> at ij.Executer.run(Executer.java:58)
> at java.lang.Thread.run(Thread.java:619)
>
Reply | Threaded
Open this post in threaded view
|

Re: File Conversion bug and Batch Converter

Hugo A. M. Torres
Thank you so very much for the plugin update Wayne

That will save me a lot of work!

This community is amazing, great job =]

On Tue, 2009-02-10 at 10:51 -0500, Wayne Rasband wrote:

> >   Hello again listmates,
> >
> > If I try to convert 16bit color images into 8bit grayscale by doing
> > "image>type>8bit" I get an RGB stack instead.
>
> The Image>Type>8-bit command converts 16-bit composite color images  
> (e.g., 48-bit RGB TIFFs) into 8-bit composite color images. You can use  
> Image>Type>RGB Color followed by Image>Type>8-bit to convert a  
> composite color image into an 8-bit grayscale image.
>
> > The way I found around that is doing "image, color, stack to rgb"
> > followed by "image, type, 8bit".
> >
> > Shouldn't I be able to convert directly? Maybe its a bug...
> >
> > Also, I tried to apply the batch converter plugin to convert all the
> > files from a folder to 8bit-TIFF and this is what I get:
>
> There is an updated version of the Batch_Converter plugin at
>
>     http://rsb.info.nih.gov/ij/plugins/batch-converter.html
>
> that fixed this bug.
>
> -wayne
>
> > java.lang.ClassCastException: [S cannot be cast to [B
> > at ij.io.ImageWriter.write8BitStack(ImageWriter.java:38)
> > at ij.io.ImageWriter.write(ImageWriter.java:214)
> > at ij.io.TiffEncoder.write(TiffEncoder.java:118)
> > at ij.io.TiffEncoder.write(TiffEncoder.java:138)
> > at ij.io.FileSaver.saveAsTiffStack(FileSaver.java:126)
> > at ij.io.FileSaver.saveAsTiff(FileSaver.java:79)
> > at ij.plugin.filter.Writer.run(Writer.java:20)
> > at
> > ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.
> > java:245)
> > at
> > ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:102)
> > at ij.IJ.runPlugIn(IJ.java:151)
> > at ij.Executer.runCommand(Executer.java:119)
> > at ij.Executer.run(Executer.java:58)
> > at ij.IJ.run(IJ.java:241)
> > at ij.IJ.run(IJ.java:284)
> > at ij.IJ.saveAs(IJ.java:1312)
> > at ij.IJ.saveAs(IJ.java:1249)
> > at Batch_Converter.convert(Batch_Converter.java:59)
> > at Batch_Converter.run(Batch_Converter.java:26)
> > at ij.IJ.runUserPlugIn(IJ.java:176)
> > at ij.IJ.runPlugIn(IJ.java:142)
> > at ij.Executer.runCommand(Executer.java:119)
> > at ij.Executer.run(Executer.java:58)
> > at java.lang.Thread.run(Thread.java:619)
> >

--
Hugo Arruda de Moura Torres
==================================
Departamento de Biofísica
Universidade Federal de São Paulo
Rua Botucatu 862 7o. andar
CEP 04023-062 Vila Clementino
São Paulo - SP - Brasil
Tel:+55 (11) 5576 4530 r.220
Fax: 55 11 5571 5780