grabbing image pixels

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

grabbing image pixels

Colin Poczatek
Hi all,

I'm trying to add a feature to our plugin that would get the on screen
pixels of an image (ie the pixels with whatever the current lut is and
the rois drawn on the image) and I'm having a bit of trouble.  Looking
through the awt classes it looked like PixelGrabber class was what I
wanted.  An example piece of code:

ij.ImagePlus tempimage = ij.WindowManager.getCurrentImage();
java.awt.image.BufferedImage awtimage = tempimage.getBufferedImage();
java.awt.image.PixelGrabber pixgrabber = new
java.awt.image.PixelGrabber(awtimage, 0, 0, 256, 256, true);

pixgrabber.grabPixels();
int[] pix = new int[(256*256*4)];
pix = (int[])pixgrabber.getPixels();

The true boolean in the PixelGrabber constructor is supposed to force
RGB (with an alpha channel) I think, but I only get 256^2 values.
Am I looking it the wrong place?  Is there a better way to do this?  Has
anybody done it? I didn't see anything obvious in the IJ API.

Thanks,
Collin




The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.
Reply | Threaded
Open this post in threaded view
|

Re: grabbing image pixels

Wayne Rasband
> Hi all,
>
> I'm trying to add a feature to our plugin that would get the on screen
> pixels of an image (ie the pixels with whatever the current lut is and
> the rois drawn on the image) and I'm having a bit of trouble.  Looking
> through the awt classes it looked like PixelGrabber class was what I
> wanted.  An example piece of code:
>
> ij.ImagePlus tempimage = ij.WindowManager.getCurrentImage();
> java.awt.image.BufferedImage awtimage = tempimage.getBufferedImage();
> java.awt.image.PixelGrabber pixgrabber = new
> java.awt.image.PixelGrabber(awtimage, 0, 0, 256, 256, true);
>
> pixgrabber.grabPixels();
> int[] pix = new int[(256*256*4)];
> pix = (int[])pixgrabber.getPixels();
>
> The true boolean in the PixelGrabber constructor is supposed to force
> RGB (with an alpha channel) I think, but I only get 256^2 values.
> Am I looking it the wrong place?  Is there a better way to do this?  
> Has anybody done it? I didn't see anything obvious in the IJ API.

The Plugins>Utilites>Capture Image command in the 1.42f daily build
does this. The internal plugin that implements this command can be
called using

     ImagePlus img = (new ScreenGrabber()).captureImage();

Source code for the ScreenGrabber plugin is at

     http://rsb.info.nih.gov/ij/source/ij/plugin/ScreenGrabber.java

The daily build release notes are at

     http://rsb.info.nih.gov/ij/source/release-notes.html

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: grabbing image pixels

Gabriel Landini
On Wednesday 31 December 2008, Wayne Rasband wrote:
> The Plugins>Utilites>Capture Image command in the 1.42f daily build
> does this.

This is an interesting feature.
Unfortunately there seems to be some problem with this under linux with double
screens.
If the source window (where the screen data should be grabbed into) is in
screen 1 it grabs from screen 2. If the source image is in screen 2, the
position of the grabbed data is ignored (it grabs always from the same screen
part).

By the way, when I use the screen capture in my setup, I get a double screen 2
on the left (where screen 1 should be) and a black rectangle on the right
(where screen 2 should be). Maybe this is related to the twin mode settings. I
will investigate a bit.

Happy 2009!

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: grabbing image pixels

Colin Poczatek
In reply to this post by Wayne Rasband
Thanks Wayne, that was fast.  That looks like the way to do it.  For
other's playing around with this I had to add two lines to the code I
copied into my plugin to take care of the case when the current image
window was behind a non-image window.

        win.toFront();  //added
        Point loc = win.getLocation();
        ImageCanvas ic = win.getCanvas();
        ic.update(ic.getGraphics());  //added

I did have some weirdness with virtual desktops on Linux, say running
the plugin on desktop #3 and having things show up on desktop #1.  Not
actual windows more like artifacts of windows.  But that appears to have
stopped happening.  I'll have to dig into it some more.

Happy New Year everybody,
Collin

Wayne Rasband wrote:

>> Hi all,
>>
>> I'm trying to add a feature to our plugin that would get the on
>> screen pixels of an image (ie the pixels with whatever the current
>> lut is and the rois drawn on the image) and I'm having a bit of
>> trouble.  Looking through the awt classes it looked like PixelGrabber
>> class was what I wanted.  An example piece of code:
>>
>> ij.ImagePlus tempimage = ij.WindowManager.getCurrentImage();
>> java.awt.image.BufferedImage awtimage = tempimage.getBufferedImage();
>> java.awt.image.PixelGrabber pixgrabber = new
>> java.awt.image.PixelGrabber(awtimage, 0, 0, 256, 256, true);
>>
>> pixgrabber.grabPixels();
>> int[] pix = new int[(256*256*4)];
>> pix = (int[])pixgrabber.getPixels();
>>
>> The true boolean in the PixelGrabber constructor is supposed to force
>> RGB (with an alpha channel) I think, but I only get 256^2 values.
>> Am I looking it the wrong place?  Is there a better way to do this?  
>> Has anybody done it? I didn't see anything obvious in the IJ API.
>
> The Plugins>Utilites>Capture Image command in the 1.42f daily build
> does this. The internal plugin that implements this command can be
> called using
>
>     ImagePlus img = (new ScreenGrabber()).captureImage();
>
> Source code for the ScreenGrabber plugin is at
>
>     http://rsb.info.nih.gov/ij/source/ij/plugin/ScreenGrabber.java
>
> The daily build release notes are at
>
>     http://rsb.info.nih.gov/ij/source/release-notes.html
>
> -wayne



The information in this e-mail is intended only for the person to whom it is
addressed. If you believe this e-mail was sent to you in error and the e-mail
contains patient information, please contact the Partners Compliance HelpLine at
http://www.partners.org/complianceline . If the e-mail was sent to you in error
but does not contain patient information, please contact the sender and properly
dispose of the e-mail.