Login  Register

Re: Possible to access pixels without creating java.awt.image

Posted by Sami Badawi-2 on May 06, 2008; 2:45pm
URL: http://imagej.273.s1.nabble.com/Possible-to-access-pixels-without-creating-java-awt-image-tp3696328p3696330.html

Hi Brian,

ImageProcessor has its own very simple data structure that is
independent of java.awt.Image.
The constructors for ColorProcessor that you are showing the code for
is taking an java.awt.Image as input, but it is only used to take the
pixels and move them over to ColorProcessor's own field int[] pixels.
There are 2 other constructors that does not take an java.awt.Image.

        public ColorProcessor(int width, int height)
        public ColorProcessor(int width, int height, int[] pixels)

ImageProcessor contains the following fields based on java.awt.Image:

        protected Image img;
        protected BufferedImage image;

But they are only used for exporting to Image when you call:

        public Image createImage() {

You can use FileOpener to open your image. Here is a couple of links:
http://rsb.info.nih.gov/ij/developer/api/ij/io/FileOpener.html
http://www.mcdb.ucla.edu/research/hartenstein/acardona/imagej_programming_tutorials.html

FileOpener.open() will give you an ImagePlus object that you can get
your ImageProcessor from.

-Sami Badawi
http://www.shapelogic.org

On Mon, May 5, 2008 at 8:11 PM, Brian Willkie <[hidden email]> wrote:

> Hello,
>
>  Is it possible to create an ImageProcessor (one that accesses the pixels in
> a given tif file) without creating an instance of java.awt.Image?
>
>
>         public ColorProcessor(Image img) {
>                 width = img.getWidth(null);
>                 height = img.getHeight(null);
>                 pixels = new int[width * height];
>                 PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height,
> pixels, 0, width);
>                 try {
>                         pg.grabPixels();
>                 } catch (InterruptedException e){};
>                 createColorModel();
>                 fgColor = 0xff000000; //black
>                 resetRoi();
>         }
>
>  Thanks,
>  Brian
>