Sunteți pe pagina 1din 2

BIT PLANE SLICING

clc;
close all;
clear all;
a=imread('cameraman.tif');
% H=imread('Tulips.jpg');
% B=rgb2gray(H);
A=imresize(a,[256 256]);
[m n]=size(A);
%To extract 7th bit plane
for i=1:m
for j=1:n
B7(i,j)=bitand(A(i,j),128);
end
end
%To extract 6th bit plane
for i=1:m
for j=1:n
B6(i,j)=bitand(A(i,j),64);
end
end
%To extract 5th bit plane
for i=1:m
for j=1:n
B5(i,j)=bitand(A(i,j),32);
end
end
%To extract 4th bit plane
for i=1:m
for j=1:n
B4(i,j)=bitand(A(i,j),16);
end
end
%To extract 3th bit plane
for i=1:m
for j=1:n
B3(i,j)=bitand(A(i,j),8);
end
end
%To extract 2nd bit plane
for i=1:m
for j=1:n
B2(i,j)=bitand(A(i,j),4);
end
end
%To extract 1st bit plane
for i=1:m
for j=1:n
B1(i,j)=bitand(A(i,j),2);
end
end
%To extract 0th bit plane
for i=1:m
for j=1:n
B0(i,j)=bitand(A(i,j),1);
end
end
recnstrct=B0+B1*(2^1)+B2*(2^2)+B3*(2^3)+B4*(2^4)+B5*(2^5)+B6*(2^6)+B7*(2^7);
figure;
subplot(1,2,1);imshow(A);title('Original image');
subplot(1,2,2);imshow(uint8(recnstrct)); title('Reconstruct image');
figure;imshow(B7);title('7th plane image');
figure;imshow(B6);title('6th plane image');
figure;imshow(B5);title('5th plane image');
figure;imshow(B4);title('4th plane image');
figure;imshow(B3);title('3rd plane image');
figure;imshow(B2);title('2nd plane image');
figure;imshow(B1);title('1st plane image');
figure;imshow(B0);title('0th plane image');
squaredErrorImage=(double(recnstrct)-double(A)).^2;
mse=sum(sum(squaredErrorImage))/(m*n);
PSNR =10*log10((256^2)/mse);
message=sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR);
msgbox(message);

S-ar putea să vă placă și