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. |
Thresholds an image to binary (b/w) format using a moving window adaptive thresholding approach. |
last modified: May 23, 2019
USAGE: localthresh [-m method] [-r radius] [-b bias] [-n negate] infile outfile
-m .... method .......... method for computing threshold statistics; PURPOSE: To automatically thresholds an image to binary (b/w) format using a moving window adaptive thresholding approach. DESCRIPTION: LOCALTHRESH thresholds an image to binary (b/w) format using a moving window adaptive thresholding approach. For each window placement the center pixel is compared to some measure of either mean or combination of mean and either standard deviation or mean absolute deviation within the window. If the center pixel is larger than this measure by some bias value, then the center pixel is made white; otherwise it is made black. The moving window is a circle with Gaussian profile. NOTE: the image MUST have the "objects" or foreground as white and the "non-objects" or background as black. Thus the image must either be preprocessed using the IM function -negate or have the script do that using its negate parameter. IMPORTANT: For acceptable results, the window size generally should be larger than the dimension of the "objects" to be detected in the image by the thresholding. Consequently, this method is best applied to images of text, small objects or edges. ARGUMENTS: -m method ... METHOD specifies what statistical measure to use to compute the threshold for each window placement. Method 1 compares the center pixel to the window mean, and if larger than the bias, the center is made white; otherwise black. Method 2 compares the center pixel to the window mean plus the bias times the window standard deviation, and if the center pixels is larger, it is made white; otherwise black. Method 3 compares the center pixel to the window mean plus the bias times the square root of window mean absolute deviation and if the center pixel is larger, it is made white; otherwise black. The default is method=1. Note that method=1 is similar to the IM function -lat (but uses a circular gaussian weighted window rather than a square uniform weighted window and more importantly does not suffer from the image shift resulting with the IM -lat function). -r radius ... RADIUS specifies the radius for the gaussian profile window. The value may be a float, but must be greater than or equal to 3. The default=15. For acceptable results, the radius generally must be larger than the feature dimension that is to be detected by the thresholding. -b bias ... BIAS is the bias parameter used in each of the two methods to determine the threshold. Larger bias values will have the effect of removing more "noise" from the result, but too large a value may remove parts of the foreground objects that are detected. Values for bias are expressed as (percent) floats where bias>=0. The default=20. -n negate ... NEGATE indicates whether to negate the image before and after processing, since this technique only works when the "object" or foreground is white and the "non-object" or background is black. Values may be either yes or no. The default=no.
REFERENCES: see the following: 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. |
Local Adaptive Thresholding Of Various Images |
|||
Pictures Were Obtained from: |
|||
Original Image |
Arguments: |
Arguments: |
Arguments: |
![]() |
![]() |
![]() |
![]() |
Original Image |
Arguments: |
Arguments: |
Arguments: |
![]() |
![]() |
![]() |
![]() |
Original Image |
Arguments: |
Arguments: |
Arguments: |
![]() |
![]() |
![]() |
![]() |
Original Image |
Arguments: |
Arguments: |
Arguments: |
![]() |
![]() |
![]() |
![]() |
See A Comparison Of Each Image Against Each Thresholding Technique
What the script does is as follows:
This is equivalent to the following IM commands for method 1 where the "objects" are bright.
|