loading...

How to build amazing image filters with Python— Median filter 📷 , Sobel filter ⚫️ ⚪️

enzoftware profile image Enzo Lizama Paredes ・2 min read

How to build amazing image filters with Python— Median filter 📷 , Sobel filter ⚫️ ⚪️

Nowadays, I’m starting in a new programming language : Python 🐍 . And I am pleased to share some of my knowledge about this new topic , which is image processing.
digital image processing

What is digital image processing ?

It is a set of techniques whose objective is to obtain a result with a specific application from a source image, improving certain characteristics that allow you to extract information from the image.
OK , After a short introduction about the meaning of image processing, Let’s continue with the filters that I will show you in this post.

Median filter

Median filter
Taken from http://artemhlezin.com/2016/09/04/median.html
This filter is used to eliminate the ‘noise’ of the images, mainly is salt-n-pepper noise.
There is not much theory beyond the one in the picture. This is how the filter works : gets all the values inside a mask, sorts them and then assigns the mean value to the coordinate.
This is how it looks an image with salt and pepper noise :

In Python 🐍 the filter works like this, enter to check the result:


And this is the result :
Result

Sobel filter

The Sobel operator is an algorithm for edge detection, a technique to find the limits between regions in an image. The edge detection algorithm help us separate some specific parts of the source image and take them off from the background. There is more interesting theory about edge detection and the Sobel operator , but we will focus on the Python 🐍 implementation.
Due to the excitement for the South American World Cup qualifiers I decided to use this image for example :
Vamos Perú
In Python 🐍 the filter works like this, enter to check the result:


And this is the result :
Result

Conclusion

I mentioned that there is much more theory about this subject; so, I will leave some articles that, in my opinion, are the most complete and better explained in the web.
References
Saush Blog’s , good description about sobel operator and other image processing filter.
https://blog.saush.com
An edge detection implementation in C++.
https://stackoverflow.com/questions/40445415/sobel-edge-detection-implementation
A detailed article about of median filter.
http://fourier.eng.hmc.edu/e161/lectures/smooth_sharpen/node2.htm
Another implementation of Sobel filter.
http://homepages.inf.ed.ac.uk/rbf/HIPR2/sobel.htm

Thanks for reading this little post , totally open to feedback. Questions in the comment box and show your support 👏❤️ .
You can watch my open-source projects in my Github account.

Posted on by:

enzoftware profile

Enzo Lizama Paredes

@enzoftware

Challenges lover. Problem solver. Occasional writer. Software Engineer student :octocat:. Passionate about soccer :soccer:. @HackSpacePeru

Discussion

markdown guide
 

Amazing article. So interesting. Never thought of building image filters with Python. For those who are new to python, you can learn the basics from these Python Tutorials >> data-flair.training/blogs/category...

 

This is really nice! I am currently using Python for my image processing class and we never just processed the data as you did but it seems quite simple. We used a library called skimage it offers a lot of possiblities and makes it easy to process images. You can apply various filters, perform histogram equalization and other transformations. Have fun with image processing and Python!

 

Good luck with your Python adventures! There's a LOONG history between Python and data processing as you are discovering :-)