Fred's ImageMagick Scripts
|
Performs binary or grayscale morphologic operations on an image, including dilate, erode, open and close. |
last modified: May 30, 2008
|
USAGE: morphology [-m mode] [-t type] [-i iterations] infile outfile
-m .... mode ........... binary or grayscale morphology; default=binary PURPOSE: To perform binary or grayscale morphologic operations on an image, including dilate, erode, open and close. DESCRIPTION: MORPHOLOGY applies any one of the following morphologic operations to an image: dilate, erode, open or close using values in a 3x3 neighborhood of each pixel in the image. The dilate operation returns the maximum value in the neighborhood. The erode operation returns the minimum value in the neighborhood. The open operation performs a dilate followed by an erode. The close operations performs an erode followed by a dilate. If the mode is set to binary, the script assumes the input image is binary (thresholded to 0 and max quantum value) and applies a much more efficient algorithm. ARGUMENTS: -m mode ... MODE specifies the algorithmic approach to use. The allowed values are binary and grayscale. If mode is set to binary, the script assumes the input image will be binary (thresholded to 0 and max quantum value) and will apply a more efficient algorithm. If mode is set to grayscale, the script will apply a slightly less efficient algorithm that can be used on grayscale or color images. The default is binary. -t type ... TYPE specifies the morphologic technique to apply to the image. The choices are dilate, erode, open and close. The dilate operation returns the maximum value in the neighborhood. The erode operation returns the minimum value in the neighborhood. The open operation performs a dilate followed by an erode. The close operations performs an erode followed by a dilate. Binary mode also allows for majority, edgein and edgout. The majority operation returns white if the majority of pixels is white and black otherwise. The edgein and edgeout operations return the interior or exteriour edge at the transition between white and black. The default is open. When the input is a binary image, dilate/erode will add/remove white pixels at all transitions from white to black. Similarly, open/close will make interior black areas larger or smaller, but keep the overall outer shape about the same. When the input image is grayscale or color, dilate/erode and close/open will brighten/darken the color transitions. -i iterations ... ITERATIONS specifies the number of iterations to apply for the specified technique. Note that for open and close, the iterations are applied successively to the first erode or dilate and then repeated successively for the second dilate or erode. Iteration is ignored for binary mode edgein and edgeout. The default is 1. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
|
Binary Morphology |
||
|
Original Image |
Arguments: |
|
|
|
|
|
Arguments: |
Arguments: |
|
|
|
|
|
Arguments: |
Arguments: | |
|
|
|
|
Arguments: |
Arguments: | |
|
|
|
|
Grayscale Morphology |
|
|
Original Image |
|
|
|
|
Arguments: |
Arguments: |
|
|
|
Arguments: |
Arguments: |
|
|
|
Example Use - Mask Creation |
|
|
Original Image |
difference from background |
|
|
|
thresholded difference |
pad border to avoid bleeding |
|
|
|
morphologic close operation |
remove padding |
|
|
|
What the script does is as follows:
This is equivalent to the following IM commands for
|