Posted by
Bill Christens-Barry on
Apr 11, 2006; 5:31am
URL: http://imagej.273.s1.nabble.com/using-FileOpener-on-16-bit-grayscale-in-java-app-tp3703115p3703117.html
Thanks for your feedback on this, Wayne. My difficulty is that I am
trying to avoid using an ImagePlus. I guess my question really is:
How can I get at the pixel data in a 16-bit unsigned grayscale image
without using an ImagePlus?
In my case, the image was created in ImageJ and saved as a TIFF. The
questions about FileOpener, readPixels, etc. came up while trying to
understand how ImageJ does it.
Bill Christens-Barry
> Use the getPixels() method of the ImageProcessor class to get the
> pixel data of an image. This example
>
> ImagePlus img = IJ.openImage(path);
> ImageProcessor ip = img.getProcessor();
> short[] data = (short[])ip.getPixels();
>
> works for 16-bit images. Replace short[] with byte[] for 8-bits
> images, with float[] for 32-bits images and with int[] for RGB images.
>
> -wayne
On Apr 10, 2006, at 5:38 PM, Bill Christens-Barry wrote:
> I have a 16-bit grayscale TIFF that I'd like to open, display, and
> work with in a Java app that imports and draws on various classes
> in ij.jar. I ran into trouble when I tried to use BufferedImage's
> TYPE_USHORT_GRAY to ensure that I can get at the 16-bit data.
>
> So far I haven't been successful and wondered if I might be able to
> do this using ij. A quick look at the ImageJ source and API left me
> a bit confused.
>
> I'm trying to use the FileOpener, FileInfo, ImageReader, and
> ShortProcessor classes to get at the 16-bit sample values of the
> image data. In my toy program to work this out, based on the source
> from FileOpener, the compiler gags with these errors:
>
> Rastic8r.java:45: cannot find symbol
> symbol : method createColorModel(ij.io.FileInfo)
> location: class ExtractRaster
> cm = createColorModel(fi);
> ^
> Rastic8r.java:50: cannot find symbol
> symbol : method readPixels(ij.io.FileInfo)
> location: class ij.io.ImageReader
> pixels = ir.readPixels(fi);
> ^
>
> In trying to understand the cause of these errors, I'm left
> wondering whose createColorModel() and readPixels() methods are
> used in FileOpener because I've imported java.awt.image.ColorModel,
> ij.io.FileOpener, ij.io.ImageReader, and ij.io.FileInfo. Also, in
> my code I declared a new ImageReader ir because I didn't see where
> Wayne had done this in the FileOpener source. As I see it,
> readPixels() is a method of ImageReader, so I thought I needed one.
> What am I misunderstanding here?
>
> Can anyone help me understand this by explanation or example?
>
> Thanks.
>
> Bill Christens-Barry