Spatial Filtering technique is used directly on pixels of an image. Mask is usually considered to be added in size so that it has a specific center pixel. This mask is moved on the image such that the center of the mask traverses all image pixels.
In this article, we are going to cover the following topics –
- To write a program in Python to implement spatial domain averaging filter and to observe its blurring effect on the image without using inbuilt functions
- To write a program in Python to implement spatial domain median filter to remove salt and pepper noise without using inbuilt functions
- Neighborhood processing in spatial domain: Here, to modify one pixel, we consider values of the immediate neighboring pixels also. For this purpose, 3X3, 5X5, or 7X7 neighborhood mask can be considered. An example of a 3X3 mask is shown below.
f(x-1, y-1) f(x-1, y) f(x-1, y+1) f(x, y-1) f(x, y) f(x, y+1) f(x+1, y-1) f(x+1, y) f(x+1, y+1)
- Low Pass filtering: It is also known as the smoothing filter. It removes the high-frequency content from the image. It is also used to blur an image. A low pass averaging filter mask is as shown.
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
- High Pass Filtering: It eliminates low-frequency regions while retaining or enhancing the high-frequency components. A high pass filtering mask is as shown.
-1/9 -1/9 -1/9 -1/9 8/9 -1/9 -1/9 -1/9 -1/9
- Median Filtering: It is also known as nonlinear filtering. It is used to eliminate salt and pepper noise. Here the pixel value is replaced by the median value of the neighboring pixel.
Below is the implementation.
In the above example, it is observed that the filtered image is slightly blurred. If we increase the size of the averaging mask, more blurring can be obtained.
In the above example, we can see that the median filtered image is considerably enhanced with hardly any salt and pepper noise in it.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Point Processing in Image Processing using Python-OpenCV
- Image Processing in Java | Set 3 (Colored image to greyscale image conversion)
- Image Processing in Java | Set 4 (Colored image to Negative image conversion)
- Image Processing in Java | Set 6 (Colored image to Sepia image conversion)
- MATLAB - Ideal Lowpass Filter in Image Processing
- MATLAB - Ideal Highpass Filter in Image Processing
- MATLAB - Butterworth Highpass Filter in Image Processing
- MATLAB - Butterworth Lowpass Filter in Image Processing
- Image Processing in Java | Set 5 (Colored to Red Green Blue Image Conversion)
- Image Processing in Java | Set 7 (Creating a random pixel image)
- Image Processing in Java | Set 8 (Creating mirror image)
- Image Processing in Java | Set 11 (Changing orientation of image)
- Image Processing in Java | Set 10 ( Watermarking an image )
- Image Edge Detection Operators in Digital Image Processing
- Image processing with Scikit-image in Python
- Spatial Filtering and its Types
- Spatial Segregation in Social Networks
- Bloom Filters - Introduction and Implementation
- Image Processing in Java | Set 1 (Read and Write)
- Image Processing In Java | Set 2 (Get and set Pixels)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.