Image filtering using scikit image thresholding methods

Utkal Sinha
Nov 6 · 2 min read

Images are just collections of numbers called pixels. These numbers range from 0 to 255 where a 0 value represents a dark pixel whereas a value 255 denotes a full bright pixel. These numbers are represented in the form of a matrix or table where an intersection of rows and columns denotes a unique pixel in the image. By the way, this is for grey images as shown below:

Leopard Grey Image to pixels values representation

For a colour image, it is a superimposition of 3 layers or matrices or tables representing a red channel matrix, a green channel matrix and a blue channel matrix. These 3 channels are commonly referred to as RGBcoding of an image as shown in the following image:

Leopard Color Image to RGB layers pixels values representation

However, RGB is not the only colour image encoding mechanism. There are other image colour spaces such as YCbCr and CMYK. List of color spaces and their uses shows an extensive list of such colour spaces.

In this post, the RGB colour space would be used.

Thresholding

Thresholding is a simple image preprocessing or filtering method using which each pixel value in the image matrix is replaced with 0 (representing dark) if the existing pixel is less than a constant value K, and is replaced with 255 (representing a bright pixel) if the existing pixel value is more than the constant value K. This constant K is known as the threshold value in the thresholding operation.

The result of a thresholding operation is a binary image since the thresholded image only contains two-pixel values: 0 and 255. Following is the thresholded image of the above leopard image.

Leopard binary image obtained using threshold_otsu from skimage.filters package

Following is the code snippet to obtain the above binary image:


AIMLBox

AIMLBox is a medium.com publication that helps readers understand complex AI & ML concepts. AIMLBox also publishes stories on the latest developments in the field of Artificial Intelligence and Machine Learning. AIMLBox publication is an initiative of Utkal Sinha (utkalsinha.com)

Utkal Sinha

Written by

Machine Learning Engineer. He graduated with a master’s degree in CS from NIT Rourkela. He enjoys competitive programming as a hobby. More at: utkalsinha.com

AIMLBox

AIMLBox

AIMLBox is a medium.com publication that helps readers understand complex AI & ML concepts. AIMLBox also publishes stories on the latest developments in the field of Artificial Intelligence and Machine Learning. AIMLBox publication is an initiative of Utkal Sinha (utkalsinha.com)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade