Smoothing with MORPH_OPEN
The MORPH_OPEN function applies the opening operation, which is erosion followed by dilation, to a binary or grayscale image. The opening operation removes noise from an image while maintaining the overall sizes of objects in the foreground. Opening is a useful process for smoothing contours, removing pixel noise, eliminating narrow extensions, and breaking thin links between features. After using an opening operation to darken small objects and remove noise, thresholding or other morphological processes can be applied to the image to further refine the display of the primary shapes within the image.
The following example applies the opening operation to an image of microscopic spherical organisms, Rhinosporidium seeberi protozoans. After applying the opening operation and thresholding the image, only the largest elements of the image are retained, the mature R.seeberi organisms. Complete the following steps for a detailed description of the process.
Example Code
See morphopenexample.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering morphopenexample at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT morphopenexample.pro.
- Prepare the display device and load grayscale color table:
- Select and open the image file:
- Get the image dimensions, prepare a window and display the image:
- Define the radius of the structuring element and create a disk-shaped element to extract circular features:
- Apply the MORPH_OPEN function to the image, specifying the GRAY keyword for the grayscale image:
- Display the image:
- Create a window and use HISTOGRAM in conjunction with PLOT, displaying an intensity histogram to help determine the threshold intensity value:
- Using the histogram as a guide, create a binary image. To prepare to remove background noise, retain only areas of the image where pixel values are equal to or greater than 160:
- Apply the opening operation to the binary image to remove noise and smooth contours, and then display the image:
file = FILEPATH('r_seeberi.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, image, /GRAYSCALE
dims = SIZE(image, /DIMENSIONS) WINDOW, 0, XSIZE = 2*dims[0], YSIZE = 2*dims[1], $ TITLE = 'Defining Shapes with Opening Operation' TVSCL, image, 0
radius = 7 strucElem = SHIFT(DIST(2*radius+1), radius, radius) LE radiusCompared to the previous example, a larger element is used in order to retain only the larger image elements, discarding all of the smaller background features. Further increases in the size of the structuring element would extract even larger image features.
Tip
EnterPRINT, strucElemto view the structure created by the previous statement.
TVSCL, morphImg, 1The following figure shows the original image (left) and the application of the opening operation to the original image (right). The opening operation has enhanced and maintained the sizes of the large bright objects within the image while blending the smaller background features.
The following steps apply the opening operator to a binary image.
WINDOW, 1, XSIZE = 400, YSIZE = 300 PLOT, HISTOGRAM(img)Note
Using an intensity histogram as a guide for determining threshold values is described in the section, Determining Intensity Values for Threshold and Stretch.
The combination of thresholding and applying the opening operation has successfully extracted the primary foreground features as shown in the following figure.

