bit plane slicing in image processing using MATLAB
MATLAB Script:
% clearing the output terminal / command window in MATLAB
clc
clear all
% 'imread'command is used to read an image file
% it reads the pixel values of an image matrix
i= imread('.../index.tif');
% 'rgb2grey' command convert the pixel intensity into grey scale value
Image= rgb2gray(i);
% pixel values are stored as 'double' variable as value can exceed from 127
% we can store values ranges from -128 to 127 as 'int' variable
I = double(Image);
% you know that image pixels usually have 256 distinct intensity levels
% and usually 8 bits / pixel hold the intensity information of grey image
% while 24 bits / pixel hold the intensity informaton of RGB image
% extracting bit one by one from c1(first bit) to c8(last bit) respectively
r1 = mod(I, 2); % Bit1
r2 = mod(floor(I/2), 2); % Bit2
r3 = mod(floor(I/4), 2); % Bit3
r4 = mod(floor(I/8), 2); % Bit4
r5 = mod(floor(I/16), 2); % Bit5
r6 = mod(floor(I/32), 2); % Bit6
r7 = mod(floor(I/64), 2); % Bit7
r8 = mod(floor(I/128), 2); % Bit8
% plotting the MATLAB figure window into 2 rows and 8 columns
% plotting original image in first subplot
subplot(2, 4, 1);
imshow(Image);
title('Original Image');
% plotting binary image having extracted bit from 1st to 8th
% in subplot from 2nd to 9th
subplot(2, 4, 2);
imshow(r1);
title('Bit Plane 1');
subplot(2, 4, 3);
imshow(r2);
title('Bit Plane 2');
subplot(2, 4, 4);
imshow(r3);
title('Bit Plane 3');
subplot(2, 4, 5);
imshow(r4);
title('Bit Plane 4');
subplot(2, 4, 6);
imshow(r5);
title('Bit Plane 5');
subplot(2, 4, 7);
imshow(r6);
title('Bit Plane 6');
subplot(2, 4, 8);
imshow(r7);
title('Bit Plane 7');
subplot(2, 4, 9);
imshow(r8);
title('Bit Plane 8');