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. |
Creates and applies a notch filter to an image in the frequency domain to remove dither patterns and other regular noise patterns. |
last modified: January 18, 2020
USAGE: notch [-r rad] [-t thresh] [-c centrad] [-h horizontal] [-v vertical] [-o outer] [-L left] [-R right] [-U upper] [-B bottom] [-m median] [-d dilate] [-s smooth] [-S] [-K] infile outfile
-r .... rad ............. blurring radius for generating mask from spectrum; PURPOSE: To create and apply a notch filter to an image in the frequency domain to remove dither patterns and other regular noise patterns. DESCRIPTION: NOTCH creates a notch filter image from the frequency domain spectrum of an image and then uses it as a mask image in the frequency domain to remove dither patterns and other regular noise patterns. This avoids manually drawing the mask from the spectrum, but may not do quite as good a job. Certain parameters must be estimated from viewing the spectrum image. The key ones include: 1) a binarization threshold (usually found automatically), 2) a radius near the center of the image to preserve low frequency components, 3) the thickness of a horizontal and/or a vertical linear mask from edge to edge crossing the center of the image, again to preseve low frequencies in one or the other (x or y) direction. The spectrum image is the basis of the notch filter. It will show distinct bright "star-like" patterns and short to medium repeated line patterns that represent some kind of dither or regular noise patterns in the original image. We want to eliminate these artifacts without suppressing any frequency domain signals, which also will be brightest at the very center and spread out around it. Thus we want an ultimate mask that is white everywhere and black where these star-like and linear patterns appear in the spectrum. So we will do some processing to try to extract these bright patterns in the spectrum and then mask out the areas of signal that we want to preserve and then invert or negate the result to form the final mask.
The order of processing is as follows:
ARGUMENTS: -r ... RAD is the radius of the blur used to compute the difference image (image-blurredimage) from the spectrum image. This difference image will then be thresholded. Values are integers>0. The default=7, which seems to be rather robust. -t ... THRESH is the value in percent used to threshold the difference image. Values are integers between 0 and 100. The default is to compute the threshold automatically using an entropy thresholding technique. -c ... CENTRAD is the radius of a circular mask applied at the center of thresholded image, which is used to preserve the low frequency signal content in the spectrum. Values are integers>0. The default=2, but can made larger to preserve higher frequencies. But the radius should not be so large as to cover any of the star-like or linear patterns that appear in the spectrum due to the dither-like patterns that we want to remove. -h ... HORIZONTAL is the thickness of a rectangular mask extending across the spectrum along the horizontal center line. This is used to preserve signal content along this center line, if one sees a narrow bright fuzzy area that extends completely accross this center line. If one sees a bright, constant intensity area of uniform thickness that does not cross the center, then that is likely part of the dither-like pattern that we want to remove and so should not be masked. Values are positive integers. The default is 0 to indicate no masking along this region. -v ... VERTICAL is the thickness of a rectangular mask extending across the spectrum along the vertical center line. This is used to preserve signal content along this center line, if one sees a narrow bright fuzzy area that extends completely accross this center line. If one sees a bright, constant intensity area of uniform thickness that does not cross the center, then that is likely part of the dither-like pattern that we want to remove and so should not be masked. Values are positive integers. The default is 0 to indicate no masking along this region. -o ... OUTER is a parameter that determines an outer circular mask use to preserve the high frequency signal content in the outer regions of the spectrum. The radius of the circular mask is given by the half-width of the spectrum image minus the outer parameter. The outer parameter can be estimated simply by the pixel distance from the center of any side of the spectrum inward such that the circular mask will not cover any star-like or linear patterns due to the dither pattern, but may cover any other extraneous bright areas along the outer sides or corners of the spectrum. Values are integers>=0. The default=0 indicating no masking. -L ... LEFT is the thickness of a rectangular mask extending across the left side of the spectrum, which may be used to cover any extraneous bright areas along the left side that are not inclusive of any star-like or strong linear patterns associated with the dither. This may be used to preserve the high frequency components of the image signal in this region. Values are positive integers. The default is 0 to indicate no masking along this region. -R ... RIGHT is the thickness of a rectangular mask extending across the right side of the spectrum, which may be used to cover any extraneous bright areas along the right side that are not inclusive of any star-like or strong linear patterns associated with the dither. This may be used to preserve the high frequency components of the image signal in this region. Values are positive integers. The default is 0 to indicate no masking along this region. -U ... UPPER is the thickness of a rectangular mask extending across the upper (top) side of the spectrum, which may be used to cover any extraneous bright areas along the right side that are not inclusive of any star-like or strong linear patterns associated with the dither. This may be used to preserve the high frequency components of the image signal in this region. Values are positive integers. The default is 0 to indicate no masking along this region. -B ... BOTTOM is the thickness of a rectangular mask extending across the bottom side of the spectrum, which may be used to cover any extraneous bright areas along the right side that are not inclusive of any star-like or strong linear patterns associated with the dither. This may be used to preserve the high frequency components of the image signal in this region. Values are positive integers. The default is 0 to indicate no masking along this region. -m ... MEDIAN is the amount or radius of a median filter applied to try to remove extraneous bright specks that are associated with the signal and not bright star-like patterns associate with the dither pattern. Values are integers>=0. The default=0 (no median filtering). If the dither star and linear patterns are too small or thin, then it is not a good idea to apply the median filtering as it will remove these star-like and linear patterns as well. -d ... DILATE is the radius of the dilation that is used to make the star-like and linear patterns larger and stronger. Values are integers>=0. The default=1 -s ... SMOOTH is the smoothing distance to ramp the transition from white to black in the final mask. This is used to avoid introducing ringing artifacts in the recovered image. Values are integers>=0. The default=1. -S ... Show (display) the mask image. Values are yes or no. The default=no. If yes, then the X11 display system must be enabled. -k ... Keep (save) the mask image to disk. Values are yes or no. The default=no. If yes, then the resulting mask image will start with the same name used for the output (less the suffix) with '_mask.gif' appended. REQUIREMENTS: IM IM 6.5.4-3 or higher due to the use -fft. Also requires the FFTW delegate library to compute the Fourier Transform. Q8 IM compilation is not generally recommended and may not carry enough precision for the Fourier Transform. See http://www.fmwconcepts.com/imagemagick/fourier_transforms/fourier.html for more details about the Fourier Transform with ImageMagick. 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. |
Clown Image |
|
Original Image |
Spectrum |
Argument: |
Generated Mask |
Clown Image |
|
Original Image |
Spectrum |
Argument: |
Generated Mask |
Dunes Image |
|
Original Image |
|
Spectrum |
|
Argument: |
|
Generated Mask |
|
Fingerprint Image |
|
Original Image |
Spectrum |
Argument: |
Generated Mask |
Medieval_Cut Image |
|
Original Image | |
Spectrum |
|
Argument: | |
Generated Mask |
|
Twig Image |
|
Original Image |
Spectrum |
Argument: |
Generated Mask |
What the script does is as follows for safecolor=none:
|