Program for Threshold in MATLAB

a=imread('olympic-torch.jpg');
m=rgb2gray(a);
t=input('Enter treshold value');
s=size(m);
b=m;
fori=1:s(1)
for j=1:s(2)
if(m(i,j)<t)
b(i,j)=0;
else
b(i,j)=255;
end;
end;
end;
subplot(2,2,1);
imshow(m);
subplot(2,2,2);
imshow(b);

Output

Output

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.