|
IDL Reference Guide: Procedures and Functions |
|
The XROI procedure is a utility for interactively defining regions of interest (ROIs), and obtaining geometry and statistical data about these ROIs.
This routine is written in the IDL language. Its source code can be found in the file xroi.pro in the lib/utilities subdirectory of the IDL distribution.
| Note See Using XROI, for detailed information describing importing images, modifying image and ROI colors, retrieving ROI information and growing regions. |
XROI [, ImageData] [, R] [, G] [, B] [, /BLOCK] [[, /FLOATING] , GROUP=widget_ID] [, /MODAL] [, REGIONS_IN=value] [, REGIONS_OUT=value] [, REJECTED=variable] [, RENDERER={0 | 1}] [, ROI_COLOR=[r, g, b] or variable] [, ROI_GEOMETRY=variable] [, ROI_SELECT_COLOR=[r, g, b] or variable] [, STATISTICS=variable] [, TITLE=string] [, TOOLS=string/string array {valid values are 'Translate-Scale', 'Rectangle', 'Ellipse', 'Freehand Draw', 'Polygon Draw', and 'Selection'}] [, X_SCROLL_SIZE=value] [, Y_SCROLL_SIZE=value]
ImageData is both an input and output argument. It is an array representing an 8-bit or 24-bit image to be displayed. ImageData can be any of the following:
If ImageData is not supplied, the user will be prompted for a file via DIALOG_PICKFILE. On output, ImageData will be set to the current image data. (The current image data can be different than the input image data if the user imported an image via the File
Import Image menu item.)
R, G, and B are arrays of bytes representing red, green, or blue color table values, respectively. R, G, and B are both input and output arguments. On input, these values are applied to the image if the image is 8-bit. To get the red, green, or blue color table values for the image on output from XROI, specify a named variable for the appropriate argument. (If the image is 24-bit, this argument will output a 256-element byte array containing the values given at input, or BINDGEN(256) if the argument was undefined on input.)
Set this keyword to have XMANAGER block when this application is registered. By default, BLOCK is set equal to zero, providing access to the command line if active command line processing is available. Note that setting the BLOCK keyword causes all widget applications to block, not just this application. For more information, see the documentation for the NO_BLOCK keyword to XMANAGER.
| Note Only the outermost call to XMANAGER can block. Therefore, to have XROI block, any earlier calls to XMANAGER must have been called with the NO_BLOCK keyword. See the documentation for the NO_BLOCK keyword to XMANAGER for an example. |
Set this keyword, along with the GROUP keyword, to create a floating top-level base widget. If the windowing system provides Z-order control, floating base widgets appear above the base specified as their group leader. If the windowing system does not provide Z-order control, the FLOATING keyword has no effect.
| Note Floating widgets must have a group leader. Setting this keyword without also setting the GROUP keyword causes an error. |
Set this keyword to the widget ID of the widget that calls XROI. When this keyword is specified, the death of the caller results in the death of XROI.
Set this keyword to block other IDL widgets from receiving events while XROI is active.
Set this keyword to an array of IDLgrROI references. This allows you to open XROI with previously defined regions of interest (see Example: Save ROI Data). This is also useful when using a loop to open multiple images in XROI. By using the same named variable for both the REGIONS_IN and REGIONS_OUT keywords, you can reuse the same ROIs in multiple images (see Example: Preserving ROIs Among Images). This keyword also accepts –1, or OBJ_NEW() (Null object) to indicate that there are no ROIs to read in. This allows you to assign the result of a previous REGIONS_OUT to REGIONS_IN without worrying about the case where the previous REGIONS_OUT is undefined.
Set this keyword to a named variable that will contain an array of IDLgrROI references. This keyword is assigned the null object reference if there are no ROIs defined. By using the same named variable for both the REGIONS_IN and REGIONS_OUT keywords, you can reuse the same ROIs in multiple images (see Example: Preserving ROIs Among Images).
| Note This keyword must be used in conjunction with the BLOCK keyword. |
Set this keyword to a named variable that will contain those REGIONS_IN that are not in REGIONS_OUT. The objects defined in the variable specified for REJECTED can be destroyed with a call to OBJ_DESTROY, allowing you to perform cleanup on objects that are not required (see Example: Preserving ROIs Among Images). This keyword is assigned the null object reference if no REGIONS_IN are rejected by the user.
| Note This keyword must be used in conjunction with the BLOCK keyword. |
Set this keyword to an integer value to indicate which graphics renderer to use when drawing objects within the window. Valid values are:
This keyword is both an input and an output parameter. Set this keyword to a
3-element byte array, [r, g, b], indicating the color of ROI outlines when they are not selected. This color will be used by XROI unless and until the color is changed by the user via the "Unselected Outline Color" portion of the "ROI Outline Colors" dialog (which is accessed by selecting Edit
ROI Outline Colors). If this keyword is assigned a named variable, that variable will be set to the current [r, g, b] value at the time that XROI returns.
Set this keyword to a named variable that will contain an array of anonymous structures, one for each ROI that is valid when this routine returns. The structures will contain the following fields:
If there are no valid regions of interest when this routine returns, ROI_GEOMETRY will be undefined.
| Note If there are no REGIONS_IN, XROI must either be modal or must block control flow in order for ROI_GEOMETRY to be defined upon exit from XROI. Otherwise, XROI will return before an ROI can be defined, and ROI_GEOMETRY will therefore be undefined. |
| Note This keyword must be used in conjunction with the BLOCK keyword. |
This keyword is both an input and an output parameter. Set this keyword to a
3-element byte array, [r, g, b], indicating the color of ROI outlines when they are selected. This color will be used by XROI unless and until the color is changed by the user via the "Selected Outline Color" portion of the "ROI Outline Colors" dialog (which is accessed by selecting Edit
ROI Outline Colors). If this keyword is assigned a named variable, that variable will be set to the current [r, g, b] value at the time that XROI returns.
Set this keyword to a named variable to receive an array of anonymous structures, one for each ROI that is valid when this routine returns. The structures will contain the following fields:
If ImageData is 24-bit, or if there are no valid regions of interest when the routine exits, STATISTICS will be undefined.
| Note If there are no REGIONS_IN, XROI must either be modal or must block control flow in order for STATISTICS to be defined upon exit from XROI. Otherwise, XROI will return before an ROI can be defined, and STATISTICS will therefore be undefined. |
Set this keyword to a string to appear in the XROI title bar.
Set this keyword a string or vector of strings from the following list to indicate which ROI manipulation tools should be supported when XROI is run:
If more than one string is specified, a series of bitmap buttons will appear at the top of the XROI widget in the order specified (to the right of the fixed set of bitmap buttons used for saving regions, displaying region information, copying to clipboard, and flipping the image). If only one string is specified, no additional bitmap buttons will appear, and the manipulation mode is implied by the given string. If this keyword is not specified, bitmap buttons for all three manipulation tools are included on the XROI toolbar.
Set this keyword to the width of the scroll window. If this keyword is larger than the image width then it will be set to the image width. The default is to use the image width or the screen width, whichever is smaller.
Set this keyword to the height of the scroll window. If this keyword is larger than the image height then it will be set to the image height. The default is to use the image height or the screen height, whichever is smaller.
XROI displays a top-level base with a menu, toolbar and draw widget. After defining an ROI, the ROI Information window appears, as shown in the following figure:
As you move the mouse over an image, the x and y pixel locations are shown in the status line on the bottom of the XROI window. For 8-bit images, the data value (z) is also shown. If an ROI is defined, the status line also indicates the mouse position relative to the ROI using the text "Inside", "Outside", "On Edge," or "On Vertex."
The XROI toolbar contains the following buttons:
Depending on the value of the TOOLS keyword, the XROI toolbar may also contain the following buttons:
To import an image into XROI, select File
Import Image. This opens a DIALOG_READ_IMAGE dialog, which can be used to preview and select an image.
To change the color table properties for the current image, select Edit
Image Color Table. This opens the CW_PALETTE_EDITOR dialog, which is a compound widget used to edit color palettes. See CW_PALETTE_EDITOR for more information. This menu item is grayed out if the image does not have a color palette.
To change the outline colors for selected and unselected ROIs, select Edit
ROI Outline Colors. This opens the ROI Outline Colors dialog, which consists of two CW_RGBSLIDER widgets for interactively adjusting the ROI outline colors. The left widget is used to define the color for the selected ROI, and the right widget is used to define the color of unselected ROIs. You can select the RGB, CMY, HSV, or HLS color system from the Color System drop-down list.
To view geometry and statistical data about the currently selected ROI, click the Info button or select Edit
ROI Information. This opens the ROI Information dialog, which displays area, perimeter, number of pixels, minimum and maximum pixel values, mean, and standard deviation. Values for statistical information (minimum, maximum, mean, and standard deviation) appear as "N/A" for 24-bit images.
To view a histogram for an ROI, use either the shortcut menu or the ROI Information dialog.
To view an ROI's histogram plot using the shortcut menu:
To view an ROI's histogram plot using the ROI Information dialog:
Either of the previous methods opens an iTool showing the ROI's histogram that can be used to interactively control the plot properties.
| Note XROI's histogram plot feature now supports RGB images. |
Once a region has been created, it may be used as a source ROI for region growing. Region growing is a process of generating one or more new ROIs based upon the image pixel values that fall within the source ROI and the values of the neighboring pixels. New pixels are added to the new grown region if those image pixel values fall within a specified threshold.
| Note This option is an interactive implementation of the REGION_GROW function. |
To create a new, grown region, do the following:
By threshold or select Grow Region
By std. dev. multiple from the shortcut menu to control how the region is grown.
The By threshold option grows the region to include all neighboring pixels that fall within a specified threshold range. By default, the range is defined by the minimum and maximum pixel values occurring within the original region. To specify a different threshold range, see Using the Region Grow Properties Dialog in the following section.
The By std. dev. multiple option grows a region to include all neighboring pixels that fall within the range of:
Mean +/- StdDevMultiplier * StdDev
where Mean is the mean value of the pixel values within the source ROI, StdDevMultiplier is a multiplier that is set using the Region Grow Properties dialog (described below), and StdDev is the sample standard deviation of the pixel values within the original region.
The Region Grow Properties dialog allows you to view and edit the properties associated with a region growing process. To bring up the Region Grow Properties dialog, do one of the following:
This brings up the Region Grow Properties dialog, shown in the following figure.
![]() |
The Region Grow Properties dialog offers the following options:
|
Option
|
Description
|
|---|---|
|
Pixel search method:
|
Describes which pixels are searched when growing the original ROI. The option are:
|
|
Threshold range:
|
Represents the minimum and maximum image pixel values that are to be included in the grown region when using the Grow Region
By threshold option (described in Growing an ROI). By default, the range of pixel values used are those occurring in the ROI to be grown.
To change the threshold values, uncheck Use source ROI threshold and enter the minimum and maximum threshold values in the Min: and Max: fields provided.
|
|
Standard deviation multiplier:
|
Represents the factor by which the sample standard deviation of the original ROI's pixel values is multiplied. This factor only applies when the Grow Region
By std. dev. multiple option (described in Growing an ROI) is used.
Change the multiplier value by typing the value into the Standard deviation multiplier field provided.
|
|
For RGB image, use:
|
Determines the basis of region growing for an RGB (rather than indexed) image. The image data values used when growing a RGB region can be one of the following:
Luminosity = (0.3 * Red) + (0.59 * Green) + (0.11 * Blue)
Note - For indexed images, the image data itself is always used for region growing.
|
|
Acceptance criteria:
|
Determines which contours of the grown region are accepted as new regions, (which will also be displayed in the draw area and in the ROI Information dialog list of regions). The region growing process can result in a large number of contours, some of which may be considered insignificant. By default, no more than two regions (those with the greatest geometrical area) are accepted. Modify the acceptance criteria by altering the following values:
|
An ROI can be deleted using either the shortcut menu or using the ROI Information dialog.
To delete an ROI using the shortcut menu:
To delete an ROI using the ROI Information dialog:
ROI Information. This opens the ROI Information dialog.
See the following examples:
This example opens a single image in XROI:
image = READ_PNG(FILEPATH('mineral.png', $
SUBDIR=['examples', 'data']))
XROI, image
This example reads 3 images from the file mr_abdomen.dcm, and calls XROI for each image. A single list of regions is maintained, saving the user from having to redefine regions on each image:
PRO docs_xroi_maintain_rois
; Read 3 images from mr_abdomen.dcm and open each one in XROI:
FOR i=0,2 DO BEGIN
image = READ_DICOM(FILEPATH('mr_abdomen.dcm',$
SUBDIR=['examples', 'data']), IMAGE_INDEX=i)
XROI, image, r, g, b, REGIONS_IN = regions, $
REGIONS_OUT = regions, $
ROI_SELECT_COLOR = roi_select_color, $
ROI_COLOR = roi_color, REJECTED = rejected, /BLOCK
OBJ_DESTROY, rejected
ENDFOR
OBJ_DESTROY, regions
END
Perform the following steps:
XROI's File
Save ROIs option allows you to save selected regions of interest. This example shows how to restore such a save file. Suppose you have a file named mineralRoi.sav that contains regions of interest selected in the mineral.png image file. You would need to complete the following steps to restore the file:
mineralRoi.sav. Provide a value for the RESTORE procedure's RESTORED_OBJECTS keyword. Using the scenario stated above, you could enter the following:RESTORE, 'mineralRoi.sav', RESTORED_OBJECTS = myRoi
myRoi as the value for REGIONS_IN as follows:XROI, READ_PNG(FILEPATH('mineral.png', SUBDIRECTORY = $
['examples', 'data'])), REGIONS_IN = myRoi
This opens the previously selected regions of interest in the XROI utility.
You can easily share your own IDL routines or utilities with other IDL users by using the SAVE routine to create a binary file of your compiled code. The following example creates a SAVE file of the XROI utility (a .pro file) and from within this file, restores a secondary SAVE file containing selected regions of interest.
XROI at the command line to open the XROI utility.
mineral.png from the examples/data subdirectory of the IDL distribution.
Save ROIs and name the file mineralROI.sav. This creates a SAVE file containing the regions of interest selected within the image.
PRO myXRoi
; Restore ROI object data by specifying a value for the
; RESTORED_OBJECTS keyword.
RESTORE, 'mineralROI.sav', RESTORED_OBJECTS = myROI
; Open XROI, specifying the previously defined value for the
; restored object data as the value for "REGIONS_IN".
XROI, READ_PNG(FILEPATH('mineral.png', $
SUBDIRECTORY = ['examples', 'data'])), $
REGIONS_IN = myROI, /BLOCK
END
Save the routine as myXRoi.pro
.FULL_RESET_SESSION at the IDL command line before creating a SAVE file to avoid saving unwanted session information.
.COMPILE myXRoi.pro
RESOLVE_ALL
| Note RESOLVE_ALL does not resolve procedures or functions that are called via quoted strings such as CALL_PROCEDURE, CALL_FUNCTION, or EXECUTE, or in keywords that can contain procedure names such as TICKFORMAT or EVENT_PRO. You must manually compile these routines. |
myXRoi.sav, containing all of the XROI utility routines. When the SAVE procedure is called with the ROUTINES keyword and no arguments, it creates a SAVE file containing all currently compiled routines. Because the routines associated with the XROI utility are the only ones that are currently compiled in our IDL session, we can create a SAVE file as follows:SAVE, /ROUTINES, FILENAME='myXRoi.sav'
myXRoi.sav. If the SAVE file uses the .sav extension and has the same base name as the main level routine, and all necessary files (in this case, mineralROI.sav and myXRoi.sav) are stored in the current working directory, simply type the name of the file, minus the .sav extension, at the command line:
myXRoi
The following figure will appear, showing the selected regions of interest.
![]() |
IDL Online Help (March 06, 2007)