Write a MATLAB code to perform gray level slicing operation on the image. Show original image and resultant image.



CODE:
clear all;
close all;
clc;
a=imread('cameraman.tif');
a=double(a);
b1=[];
b2=[];
b3=[];
b4=[];

b5=[];
b6=[];

b7=[];

for m=1:256
    for n=1:256
        b1(m,n)=ceil(a(m,n)/power(2,7))*power(2,7);
        b2(m,n)=ceil(a(m,n)/power(2,6))*power(2,6);
        b3(m,n)=ceil(a(m,n)/power(2,5))*power(2,5);
        b4(m,n)=ceil(a(m,n)/power(2,4))*power(2,4);
        b5(m,n)=ceil(a(m,n)/power(2,3))*power(2,3);
        b6(m,n)=ceil(a(m,n)/power(2,2))*power(2,2);
        b7(m,n)=ceil(a(m,n)/power(2,1))*power(2,1);
    end
end
       
subplot(2,4,1);
imshow(uint8(a));
title('image of cameramen','color','r'); 

subplot(2,4,2);
imshow(uint8(b7));
title('bit-7','color','r'); 
subplot(2,4,3);
imshow(uint8(b6));
title('bit-6','color','r'); 
subplot(2,4,4);
imshow(uint8(b5));
title('bit-5','color','r'); 
subplot(2,4,5);
imshow(uint8(b4));
title('bit-4','color','r'); 
subplot(2,4,6);
imshow(uint8(b3));
title('bit-3','color','r'); 

subplot(2,4,7);
imshow(uint8(b2));
title('bit-2','color','r'); 

subplot(2,4,8);
imshow(uint8(b1));
title('bit-1','color','r');  



OUTPUT: