MATLAB: How to show 8 bits of an image like this photo

bit planeshomeworkImage Processing Toolbox

I have an image, and I want to show it like this photo:

Best Answer

Shimaa - if we assume that the image is 8-bit (unsigned integer) and is grayscale (like in your attachment) and that it is two-dimensional only (i.e. 256x256), then we can determine the first bit only (least-significant bit and so is right most bit in the 8-bit pixel) by using bitand as follows
mask = 1;
singleBitImg = bitand(cameraManImg, mask);
In the above, we are applying a mask of 1 (or, in binary, 00000001) which will zero all but the first bit from each pixel in our image. We can then plot the pixel1Img and move to the second bit. Since the binary 00000001 zeroed all bits but the first, then we want to zero all bits but the second, so we need a binary mask of 00000010. We can easily get this using the bitshift function which shifts the bits to the left (or right). In this case, we want to shift the bits of our mask one bit to the left.
mask = 1;
mask = bitshift(mask,1);
singleBitImg = bitand(cameraManImg, mask);
And you do the same for the remaining six bits, shifting the mask one bit to the left on each iteration of a loop. You can use then use subplot to place each of your nine images (the original along with the eight calculated above) into nine different subplots within the same figure.