Querying an Image Interactively

QUESTION: I've seen this neat thing in ENVI where you can move your cursor over an image and ENVI reports back the position in the image and the image value at that location. It is possible to something like this in IDL?

ANSWER: Yes, you can use a Catalyst program named ImgWin to do this. To run this program you must install on your IDL path both the Catalyst Library programs and the Coyote Library programs, which are freely available. See the article How to Install the Catalyst and Coyote Libraries for details on how to install these two libraries and add them to your IDL path. The ImgWin program can be called in several ways. If the program is called without arguments, you will be asked to select an IDL image file that can be read by the IDL routine READ_IMAGE. These would include JPEG, TIFF, PNG, and DICOM image files.

Otherwise, you can call ImgWin with any 2D image array or true-color image variable.

    IDL> image2D = LoadData(12)    IDL> ImgWin, image2D 
   IDL> image24 = LoadData(16)    IDL> ImgWin, image24  

You see in the figure below what the program looks like when called with the commands above. As you move your cursor in the image window, the program continuously updates the image location and the value of the image at that location. The image window is completely resizeable.

ImgWin with 2D image array. ImgWin with true-color image.
ImgWin program with 2D image array on the left and a true-color image on the right.
 

It is also possible to call ImgWin with an image object.

   IDL> imgObj = Obj_New('CatImage', loaddata(7))    IDL> ImgWin, imgObj 

Adding Image Axes

The ImgWin program can also be called in such a way that axes are added to the image. For example, your image might have a particular size or data coordinate system associated with it, and you would like to know where you are inside your image in this data coordinate space. For example, here is a microscope image, in which the field of view is 8 mm in X and 5 mm in Y. We can look at this image like this.

   IDL> image = LoadData(20)
   IDL> ImgWin, image, /AXES, XRANGE=[0,8], YRANGE=[0,5] 

Notice in this particular image, the data locations are now given in units of mm, whereas the pixel locations are given in pixel units.

The image with axes.
The image with axes and a data coordinate system.
 

Full-Resolution Images

The ImgWin program can also be called in such a way that you can display a large image at full-resolution. (This can also be done from within a normal ImgWin program from the File menu.) In this case, the resizeable window can be used to look at a smaller or larger portion of the much larger full-resolution image.

   IDL> ImgWin, image, /FULL_RESOLUTION 
ImgWin normal window ImgWin full-resolution window.
ImgWin program with a normal window on the left and a full-resolution window on the right. Image courtesy of Paul Endersby, NSIDC, Boulder, CO.
 

Version of IDL used to prepare this article: IDL 7.0.3.

Google
 
Web Coyote's Guide to IDL Programming