フィルターのクリア

How to get each plane of a 24 bit plane image?

3 ビュー (過去 30 日間)
Anushka
Anushka 2015 年 6 月 15 日
回答済み: Image Analyst 2015 年 8 月 19 日
How to get each plane of a 24 bit plane image in matlab?

回答 (3 件)

Titus Edelhofer
Titus Edelhofer 2015 年 6 月 15 日
編集済み: Titus Edelhofer 2015 年 6 月 15 日
Hi,
maybe this function could help?
function p = getPlane(im, idx)
% look for planes 1..24
assert(idx>0 && idx<=24)
% make (more or less) sure it's RGB
assert(size(im,3)==3)
idxByte = floor((idx-1)/8) + 1;
idxBit = rem(idx-1, 8)+1;
p = logical(bitand(im(:,:,idxByte), idxBit));
In case you want another numbering (e.g. 8 being the highest bit of "R" instead of 1 as I have), simply replace
idxBit = 8 - rem(idx,8);
Titus
  6 件のコメント
Image Analyst
Image Analyst 2015 年 6 月 16 日
OK, maybe I just didn't understand your code. I saw 24 and thought you were considering it like a volumetric image with 24 planes or slices. I was thinking "plane" meant "color plane" since sometimes people use color plane and color channel interchangeably, and I thought she wanted one of the color planes. I wasn't thinking that, for example, he would specify 22 and would want to extract bitplane 6 of the blue channel. But maybe she does. Clarification by her would be good.
Anushka
Anushka 2015 年 8 月 18 日
Hi Image analyst and Titus Edelhofer,
Actually I want to extract 24 binary images from one RGB image which is of 24-bit/pixel color depth.

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


Image Analyst
Image Analyst 2015 年 6 月 15 日
Here are a bunch of useful snippets. The answer to your question is the first snippet, and the others are somewhat related that you may ask later.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
% Mask image must be converted to the same integer type
% as the integer image we want to mask.
mask = cast(binaryImage, class(rgbImage));
% Multiply the mask by each color channel individually.
maskedRed = redChannel .* mask;
maskedGreen = greenChannel .* mask;
maskedBlue = blueChannel .* mask;
% Recombine separate masked color channels into a single, true color RGB image.
maskedRgbImage = cat(3, maskedRed, maskedGreen, maskedBlue);
% An alternate method to multiplication channel by channel.
% Mask the image using bsxfun() function
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, class(rgbImage)));
  1 件のコメント
Image Analyst
Image Analyst 2015 年 6 月 15 日
Once you have one of the color channels, you can get one of the 8 bit planes using bitget(), like my attached demo.

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


Image Analyst
Image Analyst 2015 年 8 月 19 日
Extract the color planes like I showed you
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then extract each bitplane using bitget(), as shown in the attached demo. Here's a small snippet from it:
for bp = 0 : 7
% Compute the bit plane image.
bitPlaneImage = bitget(grayImage, bp+1);
grayImage will, of course, be either the red, green, or blue channel image and bp will be 0-7 for each one so if you want to specify 1-24 you'll have to figure out how to get that into the range 0-7 (not hard at all).

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by