Fanning Software Consulting

Replacing Image Data in iImage

QUESTION: I've started to work with the iTools, and they look great, but I have a question I wonder if anyone can help me with.

If I create an instance of an iTool (for example, iImage), how can I force the iTool to display a new data set from my application (or from the IDL command line for that matter)? For example:

   IDL> a = dist(100)
   IDL> iImage, a, ident=id
   IDL> b = dist(256)

Now I would like to display "b" in my iImage. I don't want to use the File/Import/IDL Variable, I want to be able to do this via an IDL procedure or function call.

ANSWER: I think I know how to solve your problem. A quick look at the iImage code shows the parameter set identified as "Image Parameters", and the image data identified as "ImagePixels". So I proceeded this way. (You may need my LoadData program to run this code.) First, set up an iImage tool with your initial image in it.

   ini_image = LoadData(7)
   iImage, ini_image, IDENTIFIER=myImageTool

Next, obtain a reference to the iTool system object.

   theSystem = _IDLitSys_GetSystem()

Note: In recent versions of iTools (circa IDL 6.1) getting the iTool reference is easier than this. You can simply call the ITGETCURRENT function and it will return the current iTool identifier. Also, you can use the TOOL keyword to get an object reference to the current iTool:

   myImageTool = ITGetCurrent(TOOL=theImageObject)

The image parameters are stored in the Data Manager container of the system tool. You can obtain the image parameters by their identifier.

   imageParams = theSystem -> GetByIdentifier("/Data Manager/Image Parameters")

Get the original data out of this object and display, just to convince yourself you know what you are doing. :-)

   imageObject = imageParams -> GetByIdentifier("Imagepixels")
   ok = imageObject -> GetData(orig_image)
   TV, orig_image

Finally, replace the original image with a new image.

   newImage = LoadData(5)
   ok = imageObject -> SetData(newImage)
Walla! The new image axes are even scaled appropriately. You have got to like that!

The fine folks at RSI also point out that you can replace the image in the iImage tool from the command line by using the VIEW_NEXT keyword. They point out that if you only have one view, the code below will replace the image data in the way you want it to.

   IDL> iImage, Loaddata(7)
   IDL> iImage, Loaddata(5), /View_Next

Web Coyote's Guide to IDL Programming