By name, a binary image is one that has two levels. But is it essential that those two colors are black and white? Or any other combination also allowed as shown in attached snap. Snap is output image, updated image, that is generated as a result of below code.
My code
[X,map]= imread('lena.png');
subplot 121
imshow(X)
R=X(:,:,1);
G=X(:,:,2);
B=X(:,:,3);
title('Orginal Image');
[r c]=size(R);
for i=1:r
for j=1:c
if R(i,j)<128
X1(i,j,1)=0;
else
X1(i,j,1)=1;
end
end
end
for i=1:r
for j=1:c
if G(i,j)<128
X1(i,j,2)=0;
else
X1(i,j,2)=1;
end
end
end
for i=1:r
for j=1:c
if B(i,j)<128
X1(i,j,3)=0;
else
X1(i,j,3)=1;
end
end
end
subplot 122
imshow(X1);
title('Updated Image');