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

Answers (3)

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 Comments

Anushka
Anushka on 15 Jun 2015
Edited: Anushka on 15 Jun 2015
Sir when I check the image it is 24 bitplane,but when idx is given as 24 it shows the error matrix out of dimensions.
You are right, I forgot the "-1" in the idxByte. It's corrected now.
I assumed the 24 bit plane image meant a true color RGB image with three 8-bit image planes. That's usually what 24 bit image means. In my experience 24 bit planes does not mean a hyper-spectral image with 24 gray level images. So to extract the 3 color channels corresponding to red, green, and blue, you'd use my answer to get the color channel(s) as a single 8-bit image. If you want just one of the 8 bit planes, you can use bitget(). The terminology and situation of the original poster needs to be clarified.
Hi Image Analyst,
I don't really understand: I think (!) I assumed the same, i.e., an image of size NxMx3 and uint8. idxByte should therefore be the channel (R=1, G=2, B=3)...? Then I extracted the corresponding bit (where admittedly bitget is simpler than to use bitand, thanks for that hint!).
Titus
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.
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.

Sign in to comment.

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 Comment

Once you have one of the color channels, you can get one of the 8 bit planes using bitget(), like my attached demo.

Sign in to comment.

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).

Categories

Find more on Convert Image Type in Help Center and File Exchange

Tags

No tags entered yet.

Asked:

on 15 Jun 2015

Answered:

on 19 Aug 2015

Community Treasure Hunt

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

Start Hunting!