Manual threshold_ What is wrong?

3 views (last 30 days)
Nisreen Sulayman
Nisreen Sulayman on 12 Sep 2019
Edited: Nisreen Sulayman on 12 Sep 2019
img = imread('cameraman.tif');
%Threshold the image at the intensity level 128
%make all the values in the image less than 128 to 0 and equal or greater than 128 to 255
imgT = img;
[M N]=size(img);
for i=1:M
for j=1:N
if (img(i,j)==128 || img(i,j)>128)
imgT(i,j)=1;
else
imgT(i,j)=0;
end
end
end
figure;
subplot(1,2,1)
imshow(img)
subplot(1,2,2)
imshow(imgT, [])
imgT=uint8(imgT);

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!