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

조회 수: 5 (최근 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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by