f=imread('cman.tif');%读图
[m,n]=size(f);
img=zeros(m,n,8);%储存比特平面(二值图像)
for i=1:m
for j=1:n
p=dec2bin(f(i,j),8);%十进制灰度值转为二进制
for k=1:length(p)
if p(k)=='0'
img(i,j,9-k)=0;
else
img(i,j,9-k)=1;
end
end
end
end
subplot(241),imshow(img(:,:,8))
subplot(242),imshow(img(:,:,7))
subplot(243),imshow(img(:,:,6))
subplot(244),imshow(img(:,:,5))
subplot(245),imshow(img(:,:,4))
subplot(246),imshow(img(:,:,3))
subplot(247),imshow(img(:,:,2))
subplot(248),imshow(img(:,:,1))
结果如下:
依次是比特平面8到1,对应比特位数从左到右,位数越高,相应比特平面所含图像信息越多。