1. Filter type
Spatial and frequency domain filters are generally divided into four types of filters - low-pass, high-pass, band-stop, and band-pass filters.
Low Pass Filter: Allows only low frequency details to pass, attenuating high frequency details. Example: smoothing filter.
High Pass Filter: Allows only high frequency details to pass, attenuating low frequency details. Example: Sharpen Mask filter.
Band Stop Filter: Attenuates signals within a certain frequency range. Frequencies below a certain threshold and above another are allowed to pass.
Bandpass filter: Allows only signals within a specific frequency band to pass, attenuating frequencies below a threshold and above another threshold to pass.
2. Generate a zone plate
The zone plate is used to test the characteristics of the filter. There are several versions of the zone plate, the one I'll use can be generated by: , where x, y belong to [-8.2, 8.2] in steps of 0.0275, resulting in a 597x597 image.
python reference code
def zone(x, y):
return 0.5 * (1 + math.cos(x * x + y * y))
SIZE = 597
image = np.zeros((SIZE, SIZE))
start = -8.2
end = 8.2
step = 0.0275
def dist_center(y, x):
global SIZE
center = SIZE / 2
return math.sqrt( (x - center)**2 + (y - center)**2)
for y in range(0, SIZE):
for x in range(0, SIZE):
if dist_center(y, x) > 300:
continue
y_val = start + y * step
x_val = start + x * step
image[y, x] = zone(x_val, y_val)
Zone Plate Pictures
3. Apply a low-pass filter on the zone plate
python reference code
kernel_size = 15
lowpass_kernel_gaussian = gkern(kernel_size)
lowpass_kernel_gaussian = lowpass_kernel_gaussian / lowpass_kernel_gaussian.sum()
lowpass_kernel_box = np.ones((kernel_size, kernel_size))
lowpass_kernel_box = lowpass_kernel_box / (kernel_size * kernel_size)
lowpass_image_gaussian = cv2.filter2D(image, -1, lowpass_kernel_gaussian)
lowpass_image_box = cv2.filter2D(image, -1, lowpass_kernel_box)
example image
4. Apply a high-pass filter on the zone plate
In the spatial domain, a high pass filtered image (like an unsharp mask) can be obtained by subtracting the low pass filtered image from the image itself.
python reference code
highpass_image_gaussian = image - lowpass_image_gaussian
highpass_image_gaussian = np.absolute(highpass_image_gaussian)
highpass_image_box = image - lowpass_image_box
highpass_image_box = np.absolute(highpass_image_box)
example image
5. Apply a bandstop filter on the zone plate
Similarly, a band-stop filtered image can be obtained by adding the low-pass filtered and high-pass filtered images (at different thresholds).
python reference code
bandreject_image = lowpass_image_gaussian + highpass_image_box
example image
6. Apply a bandpass filter on the zone plate
Whereas a bandpass filtered image can be obtained by subtracting the bandstop filtered image from the image itself.
python reference code
bandpass_image = image - bandreject_image
bandpass_image = np.absolute(bandpass_image)
example image