Fred's ImageMagick Scripts
|
Applies a gradient filter to an image. |
last modified: June 27, 2008
|
USAGE: gradient [-k kind] [-f filter] [t thresh] [-m mix] [-b bias] infile outfile
-k ...... kind ..... 1=approximate and 2=exact; default=1 PURPOSE: To apply a gradient filter to an image. DESCRIPTION: GRADIENT applies a 3x3 gradient magnitude filter to an image to extract the edges in the image. It is a type of high pass filter. Two kinds of gradients can be applied, approximate or exact. Two different filter forms can be used, Prewitt's, which uses equal weights or Sobel's, which uses binomial coefficient weights. The gradient can be thresholded into a binary output. The gradient can be blended (mixed) with the input image, which will cause some darkening. Therefore a bias can be added to compensate and brighten the output. Blending is done according to F = (1-m)*I + m*G, where I is the original image, G is the gradient filtered image and m = mix/100. In this case, blending does not cause image sharpening and is therefore not very useful. ARGUMENTS: -k kind is the kind of gradient, either approximate (quicker) or exact (slower). A value of kind=1 is approximate and a value o kind=2 is exact. The default is kind=1. The gradient magnitude is formed by computing both x and y first derivative convolutions on the image. For kind=1, the absolute value of each component result is computed and then added together to form the result. For kind=2, each component is squared, added together and finally the square root is computed to form the result. There is only marginal differences between the approximate and exact gradients. -f filter is the form of the filter. Two different filter forms can be used, Prewitt's, which uses equal weights or Sobel's, which uses binomial coefficient weights. A value of filter=1 is Prewitt's and a value of filter=2 is Sobel's. The default is filter=1. There is only marginal differences between the two filter form gradients.
Prewitt's Derivatives: -t thresh is the thresholding percentage used to create a binary gradient edge image. Values range from 0 to 100. A higher value will result in fewer edges in the resulting image. -m mix is the percentage mixing factor used to blend the gradient with the original image. A value of mix=0, results in the original image. A value of mix=100 results in a pure gradient image. Mixing has an effect of darkening the image, because the gradient has only positive edges. Therefore, a bias is provided to compensate for this effect. Consequently, mixing is not very effective when extracting the gradient edges. It does not cause sharpening of the image. -b bias is a percentage to brighten the image to compensate for darkening due to mixing. Values for bias are integers ranging from 0 to 100 (percent). 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. |
|
Gradient Of A True Color Image | ||||
|
Original Image |
Prewitt Approx. |
Prewitt Exact |
||
|
|
|
||
|
Original Image |
Sobel Approx. |
Sobel Exact |
||
|
|
|
||
|
Gradient Of A Grayscale Image | ||||
|
Original Image |
Prewitt Approx. |
Prewitt Exact |
||
|
|
|
||
|
Original Image |
Sobel Approx. |
Sobel Exact |
||
|
|
|
||
|
Gradient Blending | ||||
|
Original Image |
Prewitt Approx. |
Arguments: |
||
|
|
|
||
|
Original Image |
Prewitt Approx. |
Arguments: |
||
|
|
|
||
|
Gradient Thresholding | ||||
|
Original Image |
Prewitt Approx. |
Arguments: |
||
|
|
|
||
|
What the script does is as follows:
This is equivalent to the following IM commands for
|