Copyright © Fred Weinhaus My scripts are available free of charge for non-commercial (non-profit) use, ONLY. For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php Please read the Pointers For Use on my home page to properly install and customize my scripts. |
Performs binary or grayscale morphologic operations on an image, including dilate, erode, open and close. |
last modified: December 15, 2018
USAGE: morphology [-m mode] [-t type] [-i iterations] [-r ramp] 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, close and others. DESCRIPTION: MORPHOLOGY applies any one of the following morphologic operations to an image: dilate, erode, open or close, and other similar types of operations, depending on the 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 black and white) 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 morphological operators: dilate, erode, open, close, tophat, bottomhat, and gradient can be used in any mode. For 'binary' mode you can also use edgein, edgeout, majority, feather, thin, prune and thicken. For 'grayscale' mode you can also use average and spread.
The dilate operation returns the maximum value in the neighborhood.
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 for all but thin, prune and thicken, which run until convergence as a default. -r ramp ... RAMP distance for type=feather only. The white areas of a binary image will be linearly ramped to black from ramp distance inside the white area up to the black edge. Ramp is a float>=0; The default=0. NOTE: The thin, prune and thicken operations can be slow due to each iteration containing 8 complex operations.
References: 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: | |
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 |
Thinning |
||
Original Image |
Arguments: |
Animation |
Thinning Of Shape With No Holes |
||
Original Image |
Arguments: |
Animation |
Pruning Of Thinned Shape With No Holes |
||
Original Image |
Arguments: |
Arguments: |
Generate Thick Outline Of Shape With No Holes |
||
Original Shape With No Hole |
Outline |
Dilated Outline |
Thinning Of Thick Outline Of Shape |
||
Thick Outline Of Shape |
Arguments: |
Animation |
Pruning Of Thinned Outline Of Shape |
||
Thinned Outline Of Shape |
Arguments: |
Animation |
Can You Guess What The Skeleton Of This Images Will Be? |
Thickening of Characters Image |
||
Original Image |
Arguments: |
Animation |
Using Open And Tophat To Remove And Extract Patterns |
|
Original Image |
Hatch Pattern Removed |
Original Image |
Hatch Pattern Extracted |
What the script does is as follows:
This is equivalent to the following IM commands for
|