Fanning Software Consulting

Interactive Image Location and Value

QUESTION: I love your cgImage command because I don't have to think about how big the image is when I place it in an IDL graphics window. I just give it a position and it goes there. But I often would like to know the value of my image at a particular location after I see it displayed. I know you have code like XImage that allows you to do this, but I'm displaying my images in direct graphics windows, usually with different kinds of map projections and other graphical overlays. I'd really like something that wasn't as fancy as XImage. Something quick and dirty with the Cursorcommand. Do you have anything like that?

ANSWER: I don't know what's happening to me, but I find myself becoming more and more sympathetic to the retro IDL user. There are days when I think I'll never write another IDL widget program again. Part of getting old, I guess.

So, yes, I can help.

I've written a program named cgImageInfo that can be used together with cgImage to provide you with interactive image location and value information. The idea is that when you display an image with either of these two programs, information about the image display will be stored in a Common block. (Oh, my God!!) cgImageInfo will then use this information, along with the actual image data itself, which you will pass it, and will be able to determine the image location from your cursor click in the image window and will return both the image location and the image value in the Console Window. You can do this until you RIGHT click to leave the cgImageInfo program. The code might look like this:

   IDL> image = (Indgen(10, 10) + 1) * 2
   IDL> cgErase, Color='rosy brown'
   IDL> cgImage, image, /KEEP_ASPECT, MARGIN=0.1
   IDL> cgImageInfo, image

You see the image produced from these commands below.

Image interaction with TVINFO.
Clicking along the bottom row of pixels from
left to right, you should see the output below.
 

If you use your LEFT cursor to click in the individual pixel boxes on the bottom row, from left to right, you find these results:

   Value at (0,0) is 2
   Value at (1,0) is 4
   Value at (2,0) is 6
   Value at (3,0) is 8
   Value at (4,0) is 10
   Value at (5,0) is 12
   Value at (6,0) is 14
   Value at (7,0) is 16
   Value at (8,0) is 18
   Value at (9,0) is 20

The cgImageInfo program will block the IDL command line until you RIGHT click in the current graphics window to exit the program. Be sure you don't kill the current graphics window before you exit cgImageInfo , or you may find yourself in a world of hurt.

The cgImageInfo program requires other programs in the Coyote Library to run.

Version of IDL used to prepare this article: IDL 7.0.1. And my special thanks to Matt Savoie for coming up with the idea of using cgScaleVector in combination with Value_Locate to find the pixel locations in the image. As soon as he mentioned the idea, I realized it solved a long-standing problem for me of how to associate a pixel coordinate system with an image that was displayed arbitrarily in the display window. It's one of those great synthetic ideas that look obvious in retrospect, but are nearly impossible to come up with on your own.

Google
 
Web Coyote's Guide to IDL Programming