How to get luminance and chrominance value from image?
22 views (last 30 days)
Show older comments
How can i separate luminance and chrominance value from image?
0 Comments
Accepted Answer
Image Analyst
on 4 Oct 2013
Use the rgb2hsv function:
hsv = rgb2hsv(rgbImage);
luminance = value channel = hsv(:,:,3), and chrominance = saturation channel = hsv(:,:,2).
4 Comments
Image Analyst
on 29 Nov 2016
It certainly could, unless you have a uniform image. If the RGB values are different, then the luminance and chroma values will be different too, or at least they most likely will be different. It is possible for two pixels with different RGB values to have the same luminance or chroma though. However in that case the hue would have to be different. All three can't be the same for different RGB values, though 1 or 2 could be the same. For example if you make up V and S channels and have varying hues, and convert to rgb with hsv2rgb, you will have different RGB values despite the V and S channels being uniform and the same for all pixels. But this is not a typical case and will never find it with real world snapshots, just with synthetic computer graphic images.
More Answers (1)
DGM
on 5 Jul 2023
Edited: DGM
on 5 Jul 2023
You want "luminance". Let's assume we have an sRGB image.
Luma (Y') would be
factors = permute([0.2126 0.7152 0.0722],[1 3 2]); % BT709 constants
Y709 = sum(bsxfun(@times,rgbpict,factors),3); % bsxfum() since we're living in 2013
Luminance (Y) would be the same thing, but using linear RGB
Yl709 = sum(bsxfun(@times,rgb2lin(rgbpict),factors),3);
... or maybe you mean something else. Are there more clues?
You want "chrominance" ... which could be interpreted as any number of things, many of which might have nothing to do with Y or Y'. If you expect "chrominance" to represent all of the remaining color information not described by "luminance", then that's a different answer than if you expect it to be a single channel, which is what's implied by the comments.
If we're left to guess intent a decade after a vague question is asked, we might as well just presume. So what's most likely? I'm going to guess that we're looking for some luma-chroma model. If pressed, I imagine that the response would be "i want YUV", which means they actually want YCbCr and not YUV. In that case:
[Y Cb Cr] = imsplit(rgb2ycbcr(rgbpict)); % imsplit() wasn't available in 2013, but i don't care
Here, Y is luma, and Cb and Cr together represent chroma. The three components describe the position of color points in a three dimensional volume.
If you expect "chrominance" to be a single channel, then you're probably asking for something completely different. Another usage of the word "chroma" or "chrominace" describes a points distance from some contextually-equivalent gray value -- i.e. roughly equivalent to its radial position in some cylindrical (or quasi-cylindrical) coordinate system. Note that in this interpretation, Y and C alone do not unambiguously describe the location of points in a three dimensional volume.
While I often use cylindrical versions of luma-chroma models, I don't think many other people do, so I have to doubt that's what's intended. I also wouldn't see any point in using YCbCr as the parent space. If it were me, I'd do it this way:
[Y C H] = imsplit(rgb2lch(rgbpict,'ypbpr')); % cylindrical YPbPr (MIMT-only)
... but let's not go down that road.
While it's unclear whether we're after Y or Y' or which luma constants should be used, it's difficult to interpret V as being equivalent. I know I have a bad habit of using terminology loosely and not putting primes and stars where they go, but I wouldn't go that far.
Likewise, HSV saturation isn't chroma. Even if we wanted to operate in HSV, chroma would merely be
C = range(rgbpict,3); % this is not the answer to the question
... which is related to, but distinct from S.
V = max(rgbpict,[],3); % well, we'd calculate that anyway
S = C./V; % don't actually do this
The concepts of chroma and saturation apply to various color models, and their relationship is roughly analogous.
So all this is to say that I sure hope that the ~30 people a month who read this thread actually know what they want, because OP probably didn't. If everyone is content to use V as a replacement for Y or Y', I guess that's just the way the world is. I have to wonder if this thread is why I see people using rgb2hsv() to decompose their images when they do their JPG encoder projects for school.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!