Wednesday 15 September 2010

matlab - Digital image reconstruction with bit planes -



matlab - Digital image reconstruction with bit planes -

i trying reconstruct image extracted bit planes.

firstly show original image , secondly pictures per bit-plane.

here code:

i = imread('myphoto.jpg'); a=bitget(i,1); subplot(3,3,1), imshow(logical(a));title('bit plane 1'); a=bitget(i,2); subplot(3,3,2), imshow(logical(a));title('bit plane 2'); a=bitget(i,3); subplot(3,3,3), imshow(logical(a));title('bit plane 3'); a=bitget(i,4); subplot(3,3,4), imshow(logical(a));title('bit plane 4'); a=bitget(i,5); subplot(3,3,5), imshow(logical(a));title('bit plane 5'); a=bitget(i,6); subplot(3,3,6), imshow(logical(a));title('bit plane 6'); a=bitget(i,7); subplot(3,3,7), imshow(logical(a));title('bit plane 7'); a=bitget(i,8); subplot(3,3,8), imshow(logical(a));title('bit plane 8');

now want reconstruct photo using bit plane photos. must start of import bit adding next of import bit etc. must show photos together. wrote code not sure if right.

m1 = bitget(a,8)*2^0; m2 = bitget(a,7)*2^1; m3 = bitget(a,6)*2^2; m4 = bitget(a,5)*2^3; m5 = bitget(a,4)*2^4; m6 = bitget(a,3)*2^5; m7 = bitget(a,2)*2^6; m8 = bitget(a,1)*2^7; figure,subplot(3,3,1),imshow(m1); subplot(3,3,2),imshow(m2); subplot(3,3,3),imshow(m3); subplot(3,3,4),imshow(m4); subplot(3,3,5),imshow(m5); subplot(3,3,6),imshow(m6); subplot(3,3,7),imshow(m7); subplot(3,3,8),imshow(m8);

with each a=bitget(i,...); overwrite previous a. there's no hope of getting image way. store each 1 , can back.

i = imread('cameraman.tif'); ib = 1:8, a{ib}=bitget(i,ib); end

each bit-plane in cell of a (clear a first if errors).

reconstruct summation:

iout = zeros(size(i),'like',i); ib = 1:8, iout = iout + a{ib}*(2^(ib-1)); end

or utilize bitset, in spirit of exercise:

iout = zeros(size(i),'like',i); ib = 1:8, iout = bitset(iout,ib,a{ib}); end

for images integer-valued pixels, should lossless:

>> isequal(i,iout) ans = 1

image matlab image-processing bit-manipulation

No comments:

Post a Comment