How to get each plane of a 24 bit plane image?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to get each plane of a 24 bit plane image in matlab?
0 Kommentare
Antworten (3)
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
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.
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
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.
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).
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!