Routines (alphabetical) > Routines: B > BANDPASS_FILTER

# BANDPASS_FILTER

The BANDPASS_FILTER function applies a bandpass filter to a one-channel image.

A bandpass filter is useful when the general location of the noise in the frequency domain is known. The bandpass filter allows frequencies within the chosen range through and attenuates frequencies outside of the given range.

The following diagrams give a visual interpretation of the transfer functions:

This routine is written in the IDL language. Its source code can be found in the file `bandpass_filter.pro` in the `lib` subdirectory of the IDL distribution.

## Syntax

Result = BANDPASS_FILTER( ImageData, LowFreq, HighFreq [, /IDEAL] [, BUTTERWORTH=value] [, /GAUSSIAN] )

## Return Value

Returns a filtered image array of the same dimensions and type as ImageData.

## Arguments

### ImageData

A two-dimensional array containing the pixel values of the input image.

### LowFreq

The lower limit of the pass-through frequency band. This value should be between 0 and 1 (inclusive), and must be less than HighFreq.

### HighFreq

The upper limit of the pass-through frequency band. This value should be between 0 and 1 (inclusive), and must be greater than LowFreq.

## Keywords

### IDEAL

Set this keyword to use an ideal bandpass filter. In ideal bandpass filters, frequencies within the given range are passed through without attenuation and frequencies outside of the given range are completely removed. This behavior makes ideal bandpass filters very sharp.

In the previous diagram, the centered Fast Fourier Transform (FFT) is filtered by the following function, where DL is the lower bound of the frequency band, DH is the upper bound of the frequency band, and D(u,v) is the distance between a point (u,v) in the frequency domain and the center of the frequency rectangle:

### BUTTERWORTH

Set this keyword to the dimension of the Butterworth filter to apply to the frequency domain. With a Butterworth bandpass filter, frequencies at the center of the frequency band are unattenuated and frequencies at the edge of the band are attenuated by a fraction of the maximum value. The Butterworth filter does not have sharp discontinuities between frequencies that are passed and filtered.

Note: A low Butterworth dimension is close to Gaussian, and a high Butterworth dimension is close to Ideal.

In the previous diagram, the centered FFT is filtered by the following function, where D0 is the center of the frequency band, W is the width of the frequency band, D(u,v) is the distance between a point (u,v) in the frequency domain and the center of the frequency rectangle, and n is the dimension of the Butterworth filter:

Note: As n >∞, the Butterworth filter approaches the Ideal filter.

### GAUSSIAN

Set this keyword to use a Gaussian bandpass filter. In this type of filter, the transition between unfiltered and filtered frequencies is very smooth.

In the previous diagram, the centered FFT is filtered by the following function, where D0 is the center of the frequency band, W is the width of the frequency band, and D(u,v) is the distance between a point (u,v) in the frequency domain and the center of the frequency rectangle:

## Examples

In the following example, we add some sinusoidal noise to an image and filter it with BANDPASS_FILTER, using the BUTTERWORTH keyword.

; Read in the file
file = FILEPATH('moon_landing.png', SUBDIR=['examples','data'])
imageOriginal = READ_PNG(file)
; Generate some sinusoidal noise
xCoords = LINDGEN(300,300) MOD 300
yCoords = TRANSPOSE(xCoords)
noise = -SIN(xCoords*2)-SIN(yCoords*2)
imageNoise = imageOriginal + 50*noise
; Filter using a lowpass filter
imageFiltered = BANDPASS_FILTER(imageNoise, 0, 0.4, $
BUTTERWORTH=20)
; Find the image dimensions so we can display three of them
; side by side in an iImage iTool
dims = [(SIZE(imageOriginal))[1]*3, $
(SIZE(imageOriginal))[2]*1+120]
; Display the original, noise-added, and filtered images
IIMAGE, imageOriginal, VIEW_GRID=[3,1], $
VIEW_TITLE='Original Image', $
DIMENSIONS=dims, WINDOW_TITLE='BANDPASS_FILTER Example', $
/NO_SAVEPROMPT
IIMAGE, imageNoise, /VIEW_NEXT, VIEW_TITLE='Added Noise'
IIMAGE, imageFiltered, /VIEW_NEXT, $
VIEW_TITLE='Using BANDPASS_FILTER, /BUTTERWORTH'
; Increase the text size
ISETPROPERTY, 'text*', FONT_SIZE=36

## Version History

7.1 | Introduced

## See Also

MEAN_FILTER, ESTIMATOR_FILTER, BANDREJECT_FILTER, WIENER_FILTER, LEAST_SQUARES_FILTER