snapshot and swapPixelArrays

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

snapshot and swapPixelArrays

Robert Lockwood
Thought I had this working but I don't. My (16 bit monochromeTIFF) images
are very low contrast so I want to automatically enhance the contrast for
display.  On the other hand I want to show the original datum at the cursor.

I have attempted to use Snapshot and swapPixelArrays but it doesn't work as
I expected. that is, backup the original data, enhance it, display it, and
then swap the buffers so that the original pixel value can be retrieved.

Display
  Imp = IJ.openImage(inFile.getPath());
  imp.getProcessor().snapshot();
  ContrastEnhancer ce = new ContrastEnhancer();
  ce.equalize(imp);
  jImagePanel.updateImage(imp);
  imp.getProcessor().swapPixelArrays();

Get datum at cursor:
  int X = e.getX();
  int Y = e.getY();
  int val = imp.getProcessor().getPixel(X, Y);

I think I'm misunderstanding something ...

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: snapshot and swapPixelArrays

Michael Schmid
Hi Robert,

if you have the original data as a snapshot in the background, the easiest would be addressing the snapshot pixels array directly.  For 16-bit data:

ImageProcessor ip = imp.getProcessor();
short[] snapshotPixels = (short[])(ip.getSnapshotPixels());

short val = snapshotPixels[x + y*width];

This assumes you have a single image, not a stack.  There is no snapshot (undo buffer) for an operation on a stack.

Michael
________________________________________________________________
On Oct 28, 2013, at 16:20, Robert Lockwood wrote:

> Thought I had this working but I don't. My (16 bit monochromeTIFF) images
> are very low contrast so I want to automatically enhance the contrast for
> display.  On the other hand I want to show the original datum at the cursor.
>
> I have attempted to use Snapshot and swapPixelArrays but it doesn't work as
> I expected. that is, backup the original data, enhance it, display it, and
> then swap the buffers so that the original pixel value can be retrieved.
>
> Display
>  Imp = IJ.openImage(inFile.getPath());
>  imp.getProcessor().snapshot();
>  ContrastEnhancer ce = new ContrastEnhancer();
>  ce.equalize(imp);
>  jImagePanel.updateImage(imp);
>  imp.getProcessor().swapPixelArrays();
>
> Get datum at cursor:
>  int X = e.getX();
>  int Y = e.getY();
>  int val = imp.getProcessor().getPixel(X, Y);
>
> I think I'm misunderstanding something ...
>
> Nate

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

Re: snapshot and swapPixelArrays

ctrueden
In reply to this post by Robert Lockwood
Hi Nate,

Using the snapshot feature just to display a 16-bit image with stretched
contrast seems very convoluted to me. Why not just set the image's
displayed min and max values to achieve the same thing?

-Curtis
On Oct 28, 2013 10:22 AM, "Robert Lockwood" <[hidden email]> wrote:

> Thought I had this working but I don't. My (16 bit monochromeTIFF) images
> are very low contrast so I want to automatically enhance the contrast for
> display.  On the other hand I want to show the original datum at the
> cursor.
>
> I have attempted to use Snapshot and swapPixelArrays but it doesn't work as
> I expected. that is, backup the original data, enhance it, display it, and
> then swap the buffers so that the original pixel value can be retrieved.
>
> Display
>   Imp = IJ.openImage(inFile.getPath());
>   imp.getProcessor().snapshot();
>   ContrastEnhancer ce = new ContrastEnhancer();
>   ce.equalize(imp);
>   jImagePanel.updateImage(imp);
>   imp.getProcessor().swapPixelArrays();
>
> Get datum at cursor:
>   int X = e.getX();
>   int Y = e.getY();
>   int val = imp.getProcessor().getPixel(X, Y);
>
> I think I'm misunderstanding something ...
>
> 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
Reply | Threaded
Open this post in threaded view
|

Fwd: snapshot and swapPixelArrays

Robert Lockwood
In reply to this post by Michael Schmid
---------- Forwarded message ----------
From: Michael Schmid <[hidden email]>
Date: Mon, Oct 28, 2013 at 8:47 AM
Subject: Re: snapshot and swapPixelArrays
To: [hidden email]



<<
if you have the original data as a snapshot in the background, the easiest
would be addressing the snapshot pixels array directly.  For 16-bit data:

ImageProcessor ip = imp.getProcessor();
short[] snapshotPixels = (short[])(ip.getSnapshotPixels());

short val = snapshotPixels[x + y*width];

This assumes you have a single image, not a stack.  There is no snapshot
(undo buffer) for an operation on a stack.
>>

Thanks, Michael, works well.

Nate

________________________________________________________________
On Oct 28, 2013, at 16:20, Robert Lockwood wrote:

> Thought I had this working but I don't. My (16 bit monochromeTIFF) images
> are very low contrast so I want to automatically enhance the contrast for
> display.  On the other hand I want to show the original datum at the
cursor.
>
> I have attempted to use Snapshot and swapPixelArrays but it doesn't work
as

> I expected. that is, backup the original data, enhance it, display it, and
> then swap the buffers so that the original pixel value can be retrieved.
>
> Display
>  Imp = IJ.openImage(inFile.getPath());
>  imp.getProcessor().snapshot();
>  ContrastEnhancer ce = new ContrastEnhancer();
>  ce.equalize(imp);
>  jImagePanel.updateImage(imp);
>  imp.getProcessor().swapPixelArrays();
>
> Get datum at cursor:
>  int X = e.getX();
>  int Y = e.getY();
>  int val = imp.getProcessor().getPixel(X, Y);
>
> I think I'm misunderstanding something ...
>
> Nate

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



--
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
|

Fwd: snapshot and swapPixelArrays

Robert Lockwood
In reply to this post by Robert Lockwood
---------- Forwarded message ----------
From: Rasband, Wayne (NIH/NIMH) [E] <[hidden email]>
Date: Mon, Oct 28, 2013 at 9:26 AM
Subject: Re: snapshot and swapPixelArrays
To: Robert Lockwood <[hidden email]>


"Using the snapshot feature just to display a 16-bit image with stretched
contrast seems very convoluted to me. Why not just set the image's
displayed min and max values to achieve the same thing?"

Chris, I have no problem displaying the stretched image, it's retrieving
the before stretch pixel value at the cursor position that's not working.

"You seem to be reinventing the wheel. ImageJ already does this. You can
look at the setMinAndMax() method in the ShortProcessor to see how it does
it. This method is used by Process>Enhance Contrast and
Image>Adjust>Brightness/Contrast to display 16-bit images contrast enhanced
without altering the pixel values."

Wayne, I don't see how to do this, could you please provide a little code?

Thanks to both

Nate




On Oct 28, 2013, at 11:20 AM, Robert Lockwood wrote:

> Thought I had this working but I don't. My (16 bit monochromeTIFF) images
> are very low contrast so I want to automatically enhance the contrast for
> display.  On the other hand I want to show the original datum at the
cursor.
>
> I have attempted to use Snapshot and swapPixelArrays but it doesn't work
as

> I expected. that is, backup the original data, enhance it, display it, and
> then swap the buffers so that the original pixel value can be retrieved.
>
> Display
>  Imp = IJ.openImage(inFile.getPath());
>  imp.getProcessor().snapshot();
>  ContrastEnhancer ce = new ContrastEnhancer();
>  ce.equalize(imp);
>  jImagePanel.updateImage(imp);
>  imp.getProcessor().swapPixelArrays();
>
> Get datum at cursor:
>  int X = e.getX();
>  int Y = e.getY();
>  int val = imp.getProcessor().getPixel(X, Y);
>
> I think I'm misunderstanding something ...
>
> 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




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

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