IMG - Image Processing Program [TOC]

User's Guide For IMG (

by Ben-chin Cha (07/23/02)


IMG program provides the IDL user with a general purpose image process program. It is a mouse driven widget application.

This program can accept the image data in TIF/PNG/JPG/ASCII/XDR format and process the image flexiblely by rotating, reversing, resizing, and extracting rectangular ROI. A user then can use the various features of img program to tailor the image plot according to his desire.

Each TIF, PNG, JPG files are standard image files, which can be 8,16,24 bit images with color tables. For 2D image file, if there is no color table associated with it the default 'Rainbow+White' color table will be used initially, e.g. the XDR, ASCII and 8 bit JPEG 2D images file falls into these category.

Each XDR image file consists of 2D image, plus a vector of 6 numbers: [Xmin,Xmax,Ymin,Ymax,Vmin,Vmax] which defines the geometric and value ranges of the 2D image. The XDR file can be directly generated by view2d, vw2d, image2d, plot2d.

Each ASCII file consists of 2D image data(W,H) only, it contains of W rows of data , each row of data contains of H number of values.

For 8 bit image file, this program can calculate the linear approximate raw data based on the user adjustable input X,Y dimensions and X,Y and Value ranges. The ROI image output can be converted to any format supported by img program.

The plot2d program can be accessed for processing XDR or 8 bit image file. The scan2d_overlay program will be accessed to overlay multiple XDR image files which can have different geometric regions.

The widget window associated with IMG program is readjustable by the window manager.

Command Syntax

Please refer User's Reference Guide for IMG for command syntax.


Setup Requirement for Unix System

At APS all IDL programs are installed in the /usr/local/epics/extensions/bin/$HOST_ARCH directory. For proper operation of these programs, a user first has to make sure that the IDL 5.3 or later is used. For example, use IDL 5.5 release, set the following :
	source /usr/local/rsi/idl_5.5/bin/idl_setup 
In order to access IDL programs installed in the local epics/extensions/bin, a user has to make sure that the following two environment variables are set before invoking IDL :
         setenv EPICS_EXTENSIONS /usr/local/epics/extensions
and make sure the directory /usr/local/epics/extensions/bin/$HOST_ARCH is in his/her IDL search path.

Access IMG Program

To access the IMG program from the UNIX prompt just enter the following
This commnad will automatically load the, and program into the IDL session and with default drawing area size of 400 by 300 pixels.

To access the IMG program from the IDL prompt within the idl session just enter the following command at the IDL prompt:

	IDL> .run PS_open  
	IDL> .run image 
	IDL> img [,Xsize=400,Ysize=300] [,Group=group]  


The main window consists of the drawing area and a row of pull down menu widgets. The pull down menu widgets allow the user to access the various features of the img program.

The menu buttons labeled with the suffix ... indicate there is a window or widgets associated with it.

The drawing area plot dynamically reflects the plot option changes through the interface features selected by the user.

Menu Bar

File Menu

		Open...		- dialog to accept various types of input file
		Printer...	- dialog to override default printer
		Print 		- send drawing area content to the PS printer
		Exit		- exit the img program
The file types accepted by img include '*.tif*', '*.jpg', '*.png', '*.xdr', '*.txt'. The image file acceptable can be any one of the 8/16/24 bit TIF / PNG / JPG file. The raw 2D image data file acceptable can be either ASCII / XDR format (see introduction above).

Views Menu

		Bottom-Up Mirror Image  
		Left-Right Mirror Image
		Transpose Image	
		Reduce Image by 1/4	 
		Reduce Image by half
		Expand Image by two
		Expand Image by 1/4
		Extract Image (Scaled)...  	 [redraw image]
		Extract Image (Original)...	 [redraw image in input raw size]
		Extract ROI Only		 [redraw extracted image]
		Color Table...			 
		Restore Input Color Table 
The drawing area image can be reversed bottom-up or left-right, or transposed. The drawing area can be resized by the window manager as well as the reduction and expansion menu items.

Image area can be drawn as scaled or as raw original 2D image size. For the 2D image data the special region of interest can be extracted from the drawing area by clicking the left and right mouse button. The extracted ROI area can be entered by the user through the Extract TV Image calculation dialog (see below). The plot2d program will be used to display the extracted ROI.

Any IDL supported color tables can be loaded into img through the 'Color Table...' dialog. The 'Restore Input Color Table' item restores the original image color table from the input file.

SaveTVRD Menu

The SaveTVRD menu allows the user to save the drawing area content and port to any other image processing program. Currently TIFF / JPEG / PNG formats are supported.
		PNG	- save TVRD image as PNG file
		TIFF	- save TVRD image as TIFF file
		R-TIFF	- save bottom-up TVRD image as TIFF file
		JPEG	- save TVRD image as JPEG file

SaveRawData Menu

The image currently loaded into img program data structure can be ported to any other format supported by this program. Save raw 2D image data as various portable image files. If the raw 2D image data with X,Y dimension much less than the window width and height, then the image files saved by this method occupy much less disk space than SaveTVRD.
		PNG	- save raw 2D image as PNG file
		TIFF	- save raw 2D image as TIFF file
		R-TIFF	- save raw 2D image bottom-up as TIFF file
		JPEG	- save raw 2D image as JPEG file
		XDR	- save raw 2D image as XDR file

Tools Menu

The tools menu currently contains the 'Overlay2DImages...' item, which will call the scan2d_overlay program. It first let the user selects a set of 2D image XDR files to be overlaied, then re-constuct the resultant image data array based on the X,Y ranges of each image file, and then pops up the 2D image overaly program.

Help Menu

		Extracted Data...
		File Name...
The 'Help...' item shows the help page for this image process program. The 'Extracted Data...' item gives instruction how to define the ROI use the data extraction dialog. This dialog only works for 2D image data or 8 bit image file. The 'File Name...' item shows the file types supported by img.

Drawing Area

The default drawing area is 400x300 pixels. The initial plot of selected image file is plotted based on the default option settings by the IMG. The color table associated with the image file is automatically loaded into the img program. For 2D ASCII / XDR image file, the IDL color table 39 (ranbow + white) will be used.

Mouse Button Events

The mouse button cursor position is used to query and define the ROI of the image area. The text fields in the Extract TV Image Calculation dialog (see below) will reflect the mouse position being clicked.
		LMB - Left Mouse Button define the lower left corner of ROI
		RMB - Right Mouse Button define the upper right corner of ROI
		MMB - Middel Mouse Button to query X,Y pixels at the cursor 

Extract TV Image Dialog

This dialog will pop up when any of the 'Extract...' item from the 'Views Menu' is selected. This dialog shows the current Xmin,Xmax,Ymin,Ymax,Vmin,Vmax of the image file. This will be used for calculate the approximate 2D image data based on use specified ROI.

ROI Pixel Fields

Four pixel fields from the drawing area define the extracted ROI.
	Pixel Rranges for ROI: XL, XR, YL,YR

Data Range Fields

Eight fields define the real physical values corresponding to the extracted ROI. These fields can be used to calulate the approximate image data distribution if the origianl image file is a 8 bit TIFF file.
	Resize Data Dimension:  Width, Height
	Image Value Range :     Vmax, Vmin
	X Axis Range:  		Xmin, Xmax
	Y Axis Range:  		Ymin, Ymax

Control Buttons

	Accept & Plot2D...  - Recalculate 2D image array and 
				display by plot2d program
	Hlep...		    - Help page about this dialog
	Cancel		    - Close this dialog

If the original file is a 2D TIFF file, this ROI extraction method can be used to save the new image data as XDR data. With reduced value of Width and Height and without lost of data information, the data reduction purpose can be reached. For example in this document, the image drawing area is 400x300 pixels, but the physical image data dimension is 10x10, the newly calculated image as shown by plot2d which can be saved by the XDR button in plot2d program.