DIP EXP 3. [ Bit Plane Slicing ]

 %%MATLAB CODE FOR BIT PLANE EXTRACTION %%

clc
clear all
close all;
a=imread('sample.jpg');
subplot(331);
imshow(uint8(a));
title('Original Image');
a=double(a);
[row col]=size(a);
w=zeros(row,col);
for r=1:8
for x=1:row
for y=1:col
c=dec2bin (a(x,y),8); % converts decimal to binary
d=c(r);
w(x,y)=double(d); %% since w is a char and cannot be plotted
if w(x,y)==49 %% since double of d will be either 49 or 48
w(x,y)=255;
else
w(x,y)=0;
end
end
end
p=uint8(w);
switch (r)
case 1
subplot(332);
imshow(p); title('Image with M.S.B');
case 2
subplot(333);
imshow(p); title('Image with 7th bit');
case 3
subplot(334);
imshow(p); title('Image with 6th bit');
case 4
subplot(335);
imshow(p); title('Image with 5th bit');
case 5
subplot(336);
imshow(p); title('Image with 4th bit');
case 6
subplot(337);
imshow(p); title('Image with 3rd bit');
case 7
subplot(338);
imshow(p); title('Image with 2nd bit');
case 8
subplot(339);
imshow(p); title('Image with L.S.B');
end
end
Next Post Previous Post
No Comment
Add Comment
comment url