MATLAB: Gray image to 8 bit planes using bit plane slicing

binaryimage processingMATLABmatrix array

i have written a code to find the 8 bit planes of the gray image. i saved those images which should be in binary now. but when i am reading those images it is showing its pixel values few 0 and most 255 in binary only 0's and 1's should be there and when i did this size(d) it displayed 598 931 3.
i want it to be a in a form of 2-d array matrix with only 0's and 1's
can any one tell me what is the problem occurring?
A=imread('boy.tif');
B=bitget(A,1); figure, imshow(logical(B));title('Bit plane 1');
B=bitget(A,2); figure, imshow(logical(B));title('Bit plane 2');
B=bitget(A,3); figure, imshow(logical(B));title('Bit plane 3');
B=bitget(A,4); figure, imshow(logical(B));title('Bit plane 4');
B=bitget(A,5); figure, imshow(logical(B));title('Bit plane 5');
B=bitget(A,6); figure, imshow(logical(B));title('Bit plane 6');
B=bitget(A,7); figure, imshow(logical(B));title('Bit plane 7');
B=bitget(A,8); figure, imshow(logical(B));title('Bit plane 8');
this what i used then gave names to each of them
and when i read d=imread('bp0.tif') its giving 0 and 255 (only 0 and 255) i want ones and zeros and size should be a 2-d array why does it show 598 931 3

Best Answer

You have a color image. I don't know what bitget() returns or means in the case of a 3 plane color image. Why don't you use rgb2gray() or extract one of the color channels?
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(B);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale.
grayImage = rgb2gray(B); % Take weighted average of channels.
end
or
% Extract the individual red, green, and blue color channels.
redChannel = B(:, :, 1);
greenChannel = B(:, :, 2);
blueChannel = B(:, :, 3);
Let us know what happens after that.
Also, see my attached bit plane viewer program.
Related Question