Matlab – Thresholding an Image

threshold image

This post about matlab command used in image processing for thresholding an image. Threshold is simple concept of setting range of certain value to be a value. The basic purpose of thresholding in image processing is to adjust the pixel value of an image to certain value. Lets take an example. The matlab command below can be used to thresholding an image. What this command will do is to set the pixel value to 0 if  the original pixel value is below or equal to 128. Otherwise, if the original pixel value is above 128, the new pixel value will be 255. Below is the example command.

close all;clear all;clc
[m,n]=size(a); %assign size a to m and n

for i=1:m %1 to m
for j=1:n %1 to n
if a(i,j)<=128 %pixel value less than 128
b(i,j)=0; % threshold image will be 0
b(i,j)=255; %other value – threshold image will be 255



Figure 1 will show the original image and figure 2 will show the threshold image.

threshold image

That’s all. Thank You

5 thoughts on “Matlab – Thresholding an Image”

Leave a Reply

Your email address will not be published. Required fields are marked *