clc;
workspace;
fontSize = 20;
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
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
fullFileName = baseFileName;
if ~exist(fullFileName, 'file')
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(grayImage);
subplot(2, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
bitPlane3Image = bitget(grayImage, 3);
bitPlane5Image = bitget(grayImage, 5);
grayImage = bitset(grayImage, 3, bitPlane5Image);
grayImage = bitset(grayImage, 5, bitPlane3Image);
subplot(2, 1, 2);
imshow(grayImage, []);
title('Modified Grayscale Image', 'FontSize', fontSize);
fprintf('Done running %s.m.\n', mfilename);
msgbox('Done with demo');
Best Answer