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

4 Ansichten (letzte 30 Tage)
Anushka
Anushka am 15 Jun. 2015
Beantwortet: Image Analyst am 19 Aug. 2015
How to get each plane of a 24 bit plane image in matlab?

Antworten (3)

Titus Edelhofer
Titus Edelhofer am 15 Jun. 2015
Bearbeitet: Titus Edelhofer am 15 Jun. 2015
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 Kommentare
Image Analyst
Image Analyst am 16 Jun. 2015
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 am 18 Aug. 2015
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.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 15 Jun. 2015
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 Kommentar
Image Analyst
Image Analyst am 15 Jun. 2015
Once you have one of the color channels, you can get one of the 8 bit planes using bitget(), like my attached demo.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 19 Aug. 2015
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).

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by