Example: Listing Image Information
This example shows a simple script that lists information about any number of images, such as its number of columns and rows, in a Mira Text window. This short script illustrates some basic Pro Script concepts.
This script first calls LoadImages() to open images. These images are loaded into memory but are not displayed. When LoadImages()is called, it creates a CImageSet object into which it will save references to 1 or more images that it opens from files. The function then enters a loop in which it repeatedly calls the Windows Open dialog for you to select each file in turn. To open a file, select it and click [OK] in the Open dialog. This loads the file into memory and adds a reference to the CImageSet object. When you click[Cancel] , the function returns to the main script and returns a reference to the CImageSet it created. The script then loops over each image in the image set, listing information about it on a new line in the Text Editor window.
The script to list image information is shown below. Note that this script loads the entire image into memory each time. Although this script uses only the image header, the entire image is held in memory.
|
|
|
-- inserts LoadImages() into the script |
|
-- load images into an image set |
|
-- create a Text Editor object |
|
-- loop over all images |
|
-- get a reference to the image |
|
-- get image width and height |
|
-- shorten the file name |
|
-- list the information |
|
-- end of loop |
|
|
After the end of the for loop, there are no more statements, so the script exits. The listing in the Text Editor window remains open for use.
This is a complete and useful script that you can type into a Script Editor and execute from Mira. However, to implement good programming practice, there are some changes we might implement:
The script does not explicitly delete the opened images from memory; it depends upon Mira to do this behind the scenes. Actually, Mira does automatic automatically delete the images and reclaim memory at the end of the script. However, if the images were no longer needed after the for loop, and there were additional statements that needed to use a large amount of memory, then it would be a good thing to delete the images just after the end statement. We would simply create another, similar loop but with one internal statement: I:delete.
Following the image deletion loop, we might also delete the CImageSet object using S:delete.
Other image properties could be listed by adding statements likeI:Exptime and I:DatatypeStr.
You might terminate the script with the Exit function to show a message that the script exited.