Mask Making from ROIs

SRView 0.6e
Kyle Hedges, Ph.D.
Synergy Research, Inc.
23 December 1999

Introduction

Making a Mask Using the Script

makeMask Standalone Program
 
 
Back to User's Manual Table of Contents


Introduction

This page describes the SRView facilities for creating masks from image overlays(collections of ROIs). Masks are images, and any image can be used as a mask.  The difference is primarily one of intent. Masks are intended to describe regions of other images which are to be masked. Normally, mask images are stored on disk as one byte per pixel, and the pixels are all either 0 or some specific positive value, corresponding to OFF and ON respectively.

The methods described below for making mask images from overlays produce byte images with just two different pixel values: zero (OFF) and some positive integer between 1 and 255 (ON). These masks are used to represent volumes of interest in other images. Typically the ON pixels correspond to locations within the volumes of interest and the OFF pixels to locations outside the volumes of interest.

This page describes mask creatation from overlays. It is also possible to create a blank mask and then manually paint the ON regions into it. That is explained in the SRView Quick Start chapter.
 

Making a Mask Using the Script

A special Tcl/Tk script called makeMask.tcl has been written to create mask images from overlays. This script can be invoked from the Scripts menu by selecting Mask make & apply. makeMask.tcl makes a mask image from active ROIs of the currently displayed image. It writes the mask image to disk, loads it into memory, and applies the mask to the displayed image. Use the following procedure to create a mask with makeMask:
  1. Display the image and overlay for which you want to make a mask.
  2. Make the active label the label of the ROIs from which you want to make the mask.
  3. Select Mask make & apply from the Scripts menu.
Within a few seconds the image should change as a result of application of the newly created mask. The default mask style is red transparency.

The mask image will have the same file name as the image from which it was made except "Msk" will be appended to the name just prior to any extensions introduced by a period. Similarly, the mask image will appear in the SRView Images menu with "Msk" appended to the end of the name.

The overlay file for the image must reside in the same directory as the image and have the same name but with a .paf extension. If there is no such file makeMask.tcl will create one before making the mask. If there are unsaved changes to the overlay when makeMask.tcl is called, makeMask.tcl will save those changes before making the mask; your original overlay file will be overwritten with an updated version of the overlay.

Masks are made utilizing only ROIs drawn in the three principal planes of the image: XY, XZ and YZ. ROIs drawn on oblique planes are ignored.

To control selection and application of mask images, follow the instructions provided in the Quick Start guide.

Mask making options

The ON value for the mask defaults to 1. You can obtain any value between 1 and 255 by setting the Mask ON Value in the Settings ... dialog under the Edit menu. This value will also used in mask painting operations with the Mask Paint Tool.

A mask built from ROIs having a label other than the active ROI label can be obtained by setting the Tcl variable makeMaskRoiLabel to the label from which to make the mask. If ALL is given as the ROI label, then all ROIs in the overlay will be used in making the mask, regardless of their labels. To do this, open the Command window and enter the command:

set makeMaskRoiLabel "ALL"
Be careful when using makeMaskROILabel to control the action of makeMask.tcl. It persists, and unless it is unset, it will be used on all subsequent mask making during the current SRView session. To unset it, enter the command:
unset makeMaskRoiLabel

makeMask Standalone Program

The makeMask.tcl script utilizes a standalone program from the SRIP package called makeMask. makeMask creates a mask image from an overlay. It takes three arguments from the command line and runs without any user interaction.  Although it will normally be much easier to use the script, as previously described, you can run makeMask separately from a ordinary terminal window, or invoke it from the command line in SRView's Tcl command window. We mention this option for completeness and because in some cases it may provide a needed additional measure of flexibility in the creation of masks.

makeMask usage

makeMask  <image file name>  <ROI Label>  <mask value>
<image file name> - name of image file for which to make the mask.
<ROI Label> - label of the ROIs from which to make the mask. If <ROI Label> is "ALL" then all ROIs will be used regardless of label.
<mask value> - integer value, 1 to 255, to be used to represent ON pixels in the mask. OFF is always zero.
 
A scan analysis (.paf) file of the same name as the image file must be in the same directory as the image file. The ROIs contained in that scan analysis file are used to make the mask. The header of the image file is used to determine the header information for the new mask image. Only the image header is used, the image pixel data are not needed to make the  mask, and therefore are not read.

makeMask returns

An image file containing the mask is written to the same directory as the input image file, and with the same name, except the mask file name has "Msk" appended to the base name of the image file. For example the mask image made from the image file of name foobar.img, would be foobarMsk.img.

makeMask overwrites any existing file of the name used for the mask image.

Error messages are written to stderr.

makeMask invocation

At a terminal window command line simply follow the usage statement above.

At the command line of the Tcl command window in SRView, use the exec command to execute this standalone program:

exec makeMask  <image file name>  <ROI Label>  <mask value>
Be sure you give the full path name to the image file, or change to that directory before invoking makeMask.