How to extract 24 binary images from one RGB image which is of 24-bit/pixel color depth?

3 ビュー (過去 30 日間)
Anushka
Anushka 2015 年 8 月 18 日
回答済み: Image Analyst 2015 年 8 月 19 日
How to extract 24 binary images from one RGB image which is of 24-bit/pixel color depth in matlab ?

回答 (2 件)

David Young
David Young 2015 年 8 月 18 日
編集済み: David Young 2015 年 8 月 18 日
Try this:
% example rgb 24-bit image
img = imread('peppers.png');
% Make the binary array array corresponding to each bit
% and store it in a element of a cell array. bitarrays{1} has
% bit 1 for the r band, bitarrays{9} has bit 1 for the g band,
% bitarrays{24} has bit 8 for the b band, etc.
bitarrays = cell(1, 24); % allocate cell array
for b = 1:24
band = floor((b-1)/8) + 1;
bitinband = b - 8*(band-1);
bitarrays{b} = bitget(img(:,:,band), bitinband);
end
To see if the results look reasonable, display each image in turn:
for b = 1:24
imshow(bitarrays{b}, []);
pause;
end
One question though: why do you want to do this? I can't think of a reason why it would be useful, and if you would like to say what the underlying problem is, it may be that someone can suggest a much better way to tackle it.

Image Analyst
Image Analyst 2015 年 8 月 19 日
David's answer looks good. By the way, I also answered in your duplicate post: http://www.mathworks.com/matlabcentral/answers/223883-how-to-get-each-plane-of-a-24-bit-plane-image#answer_189718

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by