## Wednesday, 27 November 2013

### How to Implement Bitplane slicing in MATLAB?

AIM:  Study and Implementation of Bitplane Slicing in MATLAB.

THEORY:
Separating a digital image into its bit-planes is useful for analyzing the relative importance played by each bit of image, a process aids in determining the adequacy of the no. of bits used to quantize each pixel. This type of decomposition is useful for image compression. This term of bit-plane extraction for an 8 bit image, it is not difficult to show that the (binary) image for bit-plane 7 can be obtained by processing input image with a thresholding gray-level transformation function.

Bitplane Slicing
Suppose consider image having 4 by 4 size and consider bit depth of each pixel is 4 bit, then minimum pixel value of image is 0 and maximum pixel value of image is 2^4-1  i.e 15. So on the basis of these pixels it has 4 bitplanes, LSB bitplane, 2nd bitplane, 3rd bitplane and MSB bitplane.

Fig 1: Original Image Having size 4*4

Fig 2: Binary Pixel Representation of fig 1

Fig 3: LSB Bitplane                                                  Fig 4: 2nd Bitplane

Fig 5: 3rd Bitplane                                             Fig 6: MSB Bitplane

MATLAB Instructions:

A = imread(filename, fmt) reads a grayscale or color image from the file specified by the string filename. If the file is not in the current directory, or in a directory on the MATLAB path, specify the full pathname. The text string fmt specifies the format of the file by its standard file extension.
bitget:

 C = bitget(A,bit)
C= bitget(A,bit) returns the value of the bit at position bit in A. Operand A must be an unsigned integer; a double or array containing unsigned integers, doubles or both. the bit input must be a number between 1 and the number of bits in the unsigned class of A.

PROGRAM:

 Function of Bitplane Slicing: function [pl1 pl2 pl3 pl4 pl5 pl6 pl7 pl8]=bitplane_code(img) [row col]=size(img); b=zeros(row,col,8); for k=1:8     for i=1:row         for j=1:col             b(i,j,k)=bitget(img(i,j),k);         end     end end pl1=b(:,:,1); pl2=b(:,:,2); pl3=b(:,:,3); pl4=b(:,:,4); pl5=b(:,:,5); pl6=b(:,:,6); pl7=b(:,:,7); pl8=b(:,:,8); end

 Test Application of Bitplane Slicing: clc [file path]=uigetfile('*.*'); a=imread(file); [r c p]=size(a); if (p==3)     error('Input image should be Grayscale') else     [pl1,pl2,pl3,pl4,pl5,pl6,pl7,pl8]=bitplane_code(a); end figure;     subplot(3,3,1);imshow(pl1);title('1st pln');     subplot(3,3,2);imshow(pl2);title('2nd pln');     subplot(3,3,3);imshow(pl3);title('3rd pln');     subplot(3,3,4);imshow(pl4);title('4th pln');     subplot(3,3,5);imshow(pl5);title('5th pln');     subplot(3,3,6);imshow(pl6);title('6th pln');     subplot(3,3,7);imshow(pl7);title('7th pln');     subplot(3,3,8);imshow(pl8);title('8th pln')     rec=pl1+pl2*2+pl3*4+pl4*8+pl5*16+pl6*32+pl7*64+pl8*128;     subplot(3,3,9);imshow(uint8(rec));title('Rec Img')       [file path]=uiputfile('*.bmp');     imwrite(pl8,[path file]) pl6=b(:,:,6); pl7=b(:,:,7); pl8=b(:,:,8); end

OUTPUT:
For Grayscale Image:
Fig 7: Grayscale Image

Fig 8: Bitplanes of Grayscale Image

For Color Image:
Fig 9: Color Image

Output: for Color Image
Error using ==> test_bitplane_coding at 6
Input image should be Grayscale

1. how to find the bit planes without using bitget function or other standard matlab function

2. Jai GLA