Intensities is formed by 8 bits so we have 256 levels of gray. We will use this bits for bit slicing so that the image will be sliced according to selected bit.
For example, say that I want to slice the 8th bit then, I will take 1000000 (128 in decimal) and make the bitwise operation with the corresponding image. If 1st bit as 00000001 (1 in decimal) is taken than the resulting image will be full of dots because I take the least significant bit in the bitwise operation and the most significant bit when I choose 10000000 in bit slicing. So 8th bit will give me an image close to original one.
See the following code.
%Takes the image and the bit in decimal as arguments
%Decimal arguments for the bit numbers:1,2,4,8,16,35,64,128
%Insert 192 for 11000000, 8th and 7th bits. 224 for 11100000 and 240 for 11110000.
for i=1:row
for j=1:cols
%Bitwise operation is handled
B(i,j) = double(bitand(A(i,j),bit));
end
end
Here, matlab bitwise operation, which takes its arguments in decimal, is used to take the desired bit, and that bit is assigned to output image.
See the BitSlice function. Resulting image on 1 dollar image is as the following.
 |
| 1st bit is sliced |
 |
| 4th bit is sliced |
 |
| 6th bit is sliced |
 |
| 8th bit is sliced |
So, as you can see whenever I slice the more significant bit, the image is about to disappear.
No comments:
Post a Comment