Digitally, an image is represented in terms of pixels.
These pixels can be expressed further in terms of bits.
Consider the image ‘coins.png’ and the pixel representation of the image.
Consider the pixels that are bounded within the yellow line. The binary formats for those values are (8-bit representation)
The binary format for the pixel value 167 is 10100111
Similarly, for 144 it is 10010000
This 8-bit image is composed of eight 1-bit planes.
Plane 1 contains the lowest order bit of all the pixels in the image.
And plane 8 contains the highest order bit of all the pixels in the image.
Let’s see how we can do this using MATLAB
A=[167 133 111
144 140 135
159 154 148]
B=bitget(A,1); %Lowest order bit of all pixels
‘bitget’ is a MATLAB function used to fetch a bit from the specified position from all the pixels.
B=[1 1 1
0 0 1
1 0 0]
B=bitget(A,8);%Highest order bit of all pixels
B=[1 1 0
1 1 1
1 1 1]
MATLAB CODE:
%Bit Planes from 1 to 8. Output Format: Binary
A=imread('coins.png');
B=bitget(A,1);
figure,
subplot(2,2,1);imshow(logical(B));title('Bit plane 1');
B=bitget(A,2);
subplot(2,2,2);imshow(logical(B));title('Bit plane 2');
B=bitget(A,3);
subplot(2,2,3);imshow(logical(B));title('Bit plane 3');
B=bitget(A,4);
subplot(2,2,4);imshow(logical(B));title('Bit plane 4');
B=bitget(A,5);
figure,
subplot(2,2,1);imshow(logical(B));title('Bit plane 5');
B=bitget(A,6);
subplot(2,2,2);imshow(logical(B));title('Bit plane 6');
B=bitget(A,7);
subplot(2,2,3);imshow(logical(B));title('Bit plane 7');
B=bitget(A,8);
subplot(2,2,4);imshow(logical(B));title('Bit plane 8');
Image reconstruction using n bit planes.
1. The nth plane in the pixels are multiplied by the constant 2^n-1
2. For instance, consider the matrix
A= A=[167 133 111
144 140 135
159 154 148] and the respective bit format
3. Combine the 8 bit plane and 7 bit plane.
For 10100111, multiply the 8 bit plane with 128 and 7 bit plane with 64.
(1x128)+(0x64)+(1x0)+(0x0)+(0x0)+(1x0)+(1x0)+(1x0)=128
4. Repeat this process for all the values in the matrix and the final result will be
[128 128 64
128 128 128
128 128 128]
MATLAB CODE:
%Image reconstruction by combining 8 bit plane and 7 bit plane
A=imread('coins.png');
B=zeros(size(A));
B=bitset(B,7,bitget(A,7));
B=bitset(B,8,bitget(A,8));
B=uint8(B);
figure,imshow(B);
Image reconstructed using 8 and 7 bit planes |
Explanation:
‘bitset’ is used to set a bit at a specified position. Use ‘bitget’ to get the bit at the positions 7 and 8 from all the pixels in matrix A and use ‘bitset’ to set these bit values at the positions 7 and 8 in the matrix B.
%Image reconstruction by combining 8,7,6 and 5 bit planes
A=imread('coins.png');
B=zeros(size(A));
B=bitset(B,8,bitget(A,8));
B=bitset(B,7,bitget(A,7));
B=bitset(B,6,bitget(A,6));
B=bitset(B,5,bitget(A,5));
B=uint8(B);
figure,imshow(B);
Image reconstructed using 5,6,7 and 8 bit planes |
Also check bit plane compression.