Sei sulla pagina 1di 3

IMAGE THRESHOLDING

%Global thresholding

clc;
clear all;
close all;
A=imread('cameraman.tif');
subplot(2,3,1);
imshow(A);
title('Original image');
[r c]=size(A);
b=A;
fori=1:1:r
for j=1:1:c
if(b(i,j)<127)
b(i,j)=0;
else
b(i,j)=256;
end
end
end
subplot(2,3,2);
imshow(b);
title('Global thresholding of image');

%Mean Adaptive threshoding


tmean=mean(mean(A));
m=A;
for x=1:r
for y=1:c
if(A(x,y)<tmean)
m(x,y)=0;
else
m(x,y)=256;
end
end
end
subplot(2,3,3);
imshow(m);
title('Mean Adaptive thresholding of image');
IMAGE THRESHOLDING

%Meadian Adaptive threshoding

tmedian=median(median(A));
md=A;
for x=1:r
for y=1:c
if(A(x,y)<tmedian)
md(x,y)=0;
else
md(x,y)=256;
end
end
end
subplot(2,3,4);
imshow(md);
title('Median Adaptive thresholding of image');

%Max-Min Adaptive threshoding

tmax=max(max(A));
tmin=min(min(A));
tmm=(tmax+tmin)/2;
mm=A;
for x=1:r
for y=1:c
if(A(x,y)<tmm)
mm(x,y)=0;
else
mm(x,y)=256;
end
end
end
subplot(2,3,5);
imshow(mm);
title('Max-Min Adaptive thresholding of image');

%Adaptive thresholding

add=m+md+mm;
IMAGE THRESHOLDING

subplot(2,3,6);
imshow(add);
title('Adaptive thresholding of image');

Potrebbero piacerti anche