How to show 8 bits of an image like this photo?
Show older comments
I have an image, and I want to show it like this photo:

Accepted Answer
More Answers (1)
Image Analyst
on 1 Nov 2015
Edited: Image Analyst
on 1 Nov 2015
Looks like my demo. You can use bitget() like I did in my demo (below).
% Demo to extract and view bitplanes in a gray scale image.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(3, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
for bp = 0 : 7
% Extract the bit plane image using bpget().
bitPlaneImage = bitget(grayImage, bp+1);
% bitPlaneImage = bitand(grayImage, 2^bp);
% Display it as pure black and white (not gray scale).
subplot(3, 3, bp+2);
imshow(bitPlaneImage, []);
caption = sprintf('Bit Plane %d.', bp);
title(caption, 'FontSize', fontSize);
end
msgbox('Done with demo');

1 Comment
Shimaa Baset
on 2 Nov 2015
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!