Combining Morphological Operations
The following example uses a variety of morphological operations to remove bridges from a satellite image of New York waterways. Complete the following steps for a detailed description of the process.
Example Code
See removebridges.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. Run the example procedure by entering removebridges at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT removebridges.pro.
- Prepare the display device and load a color table:
- Specify the known dimensions and use READ_BINARY to load the image:
- Increase the image's contrast and display the image:
- Prepare to threshold the image, using an intensity histogram as a guide for determining the intensity value:
xsize = 768 ysize = 512 img = READ_BINARY(FILEPATH('nyny.dat', $ SUBDIRECTORY = ['examples', 'data']), $ DATA_DIMS = [xsize, ysize])
Note
Using an intensity histogram as a guide for determining threshold values is described in the section, Determining Intensity Values for Threshold and Stretch.
- Create a mask of the darker pixels that have values less than 70:
- Define and create a small square structuring element, which has a shape similar to the bridges which will be masked out:
- Remove details in the binary mask's shape by applying the opening operation:
- Fuse gaps in the mask's shape by applying the closing operation and display the image:
- Prepare to remove all but the largest region in the mask by labeling the regions:
- Discard the black background by keeping only the white areas of the previous figure:
- Define mainRegion as the area where the population of the labelImg region matches the region with the largest population:
- Define maskImg as the area of labelImg equal to the largest region of mainRegion, having an index number of 0 and display the image:
- Remove noise and smooth contours in the original image:
- Replace the new image with the original image, where it's not masked:
- View the results using FLICK to alternate the display between the original image and the new image containing the masked areas:
maskImg = MORPH_CLOSE(maskImg, strucElem) WINDOW, 1, title='Mask After Opening and Closing' TVSCL, maskImgThis results in the following figure:
maskImg = labelImg EQ mainRegion[0] Window, 3, TITLE = 'Final Masked Image' TVSCL, maskImgThis results in a mask of the largest region, the waterways, as shown in the following figure.



