How to access the image data backing array.

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

How to access the image data backing array.

Robert Lockwood
I'm attempting to write some testing routines to create images from short[]
arrays (unsigned shorts).  The data are produced from our one-of-a-kind
infrared camera but I don't want to run it each time until I get the
routines right as it's cumbersome and a bit of pain.

I can import the data, create a buffered image, and display it using the
code below.


fi = new FileInfo();
fi.fileName = input_file;
fi.fileType = FileInfo.GRAY16_UNSIGNED;
fi.width = imgWidth;
fi.height = imgHeight;
fi.intelByteOrder = false;
fo = new FileOpener(fi);
imp = fo.open(false);
if (imp != null) {
ip = (ShortProcessor) imp.getProcessor();
bi = ip.get16BitBufferedImage();
new ImagePlus(input_file, bi).show();
}

I'd like to be able to extract the short[] so that I can manipulate a
couple of pixels directly and then import the short[] into a new bi using a
binary input stream.  That's new to me.

Is it possible to extract the backing data to get a short[] and if so, how?

Thanks,

Nate

--
When I was 12 I thought I would live forever.
So far, so good.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: How to access the image data backing array.

Michael Schmid
Hi Robert,

you can get the pixels of an ImageProcessor with getPixels()

short[] pixels = (short[])ip.getPixels();

You don't need to create a new ImagePlus, you can simply modify the pixels
of it's ImageProcessor and then call imp.updateAndDraw() [or imp.show() if
you have not shown it already]

If you don't want to affect the original ImagePlus, work on the pixels of
a copy, see ip.duplicate(). As soon as you have an ImagePlus or
ImageProcessor, there is no need for a buffered image; you have everything
in ImageJ.

Michael
___________________________________________________________________

On Sun, November 30, 2014 00:15, Robert Lockwood wrote:

> I'm attempting to write some testing routines to create images from
> short[]
> arrays (unsigned shorts).  The data are produced from our one-of-a-kind
> infrared camera but I don't want to run it each time until I get the
> routines right as it's cumbersome and a bit of pain.
>
> I can import the data, create a buffered image, and display it using the
> code below.
>
>
> fi = new FileInfo();
> fi.fileName = input_file;
> fi.fileType = FileInfo.GRAY16_UNSIGNED;
> fi.width = imgWidth;
> fi.height = imgHeight;
> fi.intelByteOrder = false;
> fo = new FileOpener(fi);
> imp = fo.open(false);
> if (imp != null) {
> ip = (ShortProcessor) imp.getProcessor();
> bi = ip.get16BitBufferedImage();
> new ImagePlus(input_file, bi).show();
> }
>
> I'd like to be able to extract the short[] so that I can manipulate a
> couple of pixels directly and then import the short[] into a new bi using
> a
> binary input stream.  That's new to me.
>
> Is it possible to extract the backing data to get a short[] and if so,
> how?
>
> Thanks,
>
> Nate
>
> --
> When I was 12 I thought I would live forever.
> So far, so good.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html