Login  Register

Re: using FileOpener on 16-bit grayscale in java app ?

Posted by Wayne Rasband on Apr 11, 2006; 2:24am
URL: http://imagej.273.s1.nabble.com/using-FileOpener-on-16-bit-grayscale-in-java-app-tp3703115p3703118.html

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