Thresholding is the simplest method of image segmentation and the most common way to convert a grayscale image to a binary image.
In thresholding, we select a threshold value and then all the gray level value which is below the selected threshold value is classified as 0(black i.e background ) and all the gray level which is equal to or greater than the threshold value are classified as 1(white i.e foreground).
Here g(x, y) represents threshold image pixel at (x, y) and f(x, y) represents greyscale image pixel at (x, y).
- Read target image into MATLAB environment.
- Convert it to a grayscale Image if read image is an RGB Image.
- Calculate a threshold value, T
- Create a new Image Array (say ‘binary’) with the same number of rows and columns as original image array, containing all elements as 0 (zero).
- Assign 1 to binary(i, j), if gray level pixel at (i, j) is greater than or equal to the threshold value, T ; else assign 0 to binary(i, j).
Do the same for all gray level pixels.
Below is the implementation of above algorithm :
Advantages of thresholding:
- This method is easy to understand and simple to implement.
- It Converts a grayscale image to binary image.
- Resultant binary image is easy to analyze.
Disadvantages of thresholding:
- We only consider the intensity of the image for thresholding process, but not consider any relationship between the pixels. So, the pixels identified by thresholding process might not be continuous.
- While thresholding process we can easily include the extraneous pixels that aren’t part of the desired region and can easily miss the pixels that are part of desired region.
- It is also very sensitive to noise in the image. The result of thresholding process gets worse as noise gets worse.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Python | Thresholding techniques using OpenCV | Set-1 (Simple Thresholding)
- Python | Thresholding techniques using OpenCV | Set-2 (Adaptive Thresholding)
- Python | Thresholding techniques using OpenCV | Set-3 (Otsu Thresholding)
- MATLAB | RGB image to grayscale image conversion
- Java | Converting an Image into Grayscale using cvtColor()
- MATLAB | Complement colors in a Grayscale Image
- MATLAB | Display histogram of a grayscale Image
- MATLAB | Change the color of background pixels by OTSU Thresholding
- OpenCV: Segmentation using Thresholding
- MATLAB | Complement colors in a Binary image
- LSB based Image steganography using MATLAB
- Matlab | Edge Detection of an image without using in-built function
- Create Mirror Image using MATLAB
- How to vertically flip an Image using MATLAB
- Matlab program to rotate an image 180 degrees clockwise without using function
- MATLAB - Image Edge Detection using Prewitt Operator from Scratch
- MATLAB - Image Edge Detection using Sobel Operator from Scratch
- MATLAB - Image Edge Detection using Robert Operator from Scratch
- Extract bit planes from an Image in Matlab
- Image Processing in MATLAB | Fundamental Operations
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.