On Apr 6, 7:54 am, "ujjwal kotdiya" <
ujjwalkotd...@gmail.com> wrote:
> Is this possible to adjust bit allocation according to our requirement i.e
> now if i want image to be 5bit or 3bit or 6 bit etc.. for that purpose what i had to do
>
> thank you
--------------------------------------------------------------------
For other bits, just divide by 2^n if you want to do linear scaling.
If you want to extract out and visualize certain bitplanes, I have
demo code for that. See below:
% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
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');
baseFileName = 'cameraman.tif';
% 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(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of Original Grayscale Image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Let's use this spot for the output image.
subplot(2, 3, 5);
for bp = 0 : 7
% Compute the bit plane image.
bitPlaneImage = bitand(grayImage, 2^bp);
% Display it as pure black and white (not gray scale).
imshow(bitPlaneImage, []);
caption = sprintf('You are now viewing bitplane %d.', bp);
title(caption, 'FontSize', fontSize);
% If it's not the last bit plane, ask them if they want to
continue.
if bp ~= 7
message = sprintf('%s\nDo you want to continue', caption);
button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'No')
break;
end
end
end
msgbox('Done with demo');