Exchange bit-planes

25 ビュー (過去 30 日間)
Brahim Aboumouadine
Brahim Aboumouadine 2020 年 12 月 24 日
コメント済み: Brahim Aboumouadine 2020 年 12 月 24 日
hey everyone
how to Exchange the third and the fifth bit-planes of a gray-scale image using bitget and bitset ??
thanks in advance

採用された回答

Image Analyst
Image Analyst 2020 年 12 月 24 日
編集済み: Image Analyst 2020 年 12 月 24 日
Here's one way:
% Demo to extract and swap 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(2, 1, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Get the 3rd bitplane
bitPlane3Image = bitget(grayImage, 3);
% Get the 5th bitplane
bitPlane5Image = bitget(grayImage, 5);
% Make the 3rd bitplane the 5th one.
grayImage = bitset(grayImage, 3, bitPlane5Image);
% Make the 5th bitplane the 3rd one.
grayImage = bitset(grayImage, 5, bitPlane3Image);
% Display the original gray scale image.
subplot(2, 1, 2);
imshow(grayImage, []);
title('Modified Grayscale Image', 'FontSize', fontSize);
fprintf('Done running %s.m.\n', mfilename);
msgbox('Done with demo');
  1 件のコメント
Brahim Aboumouadine
Brahim Aboumouadine 2020 年 12 月 24 日
thank you , this demo is really helpful :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by