Mean luminance Values of an Image

65 Ansichten (letzte 30 Tage)
M@lik Ali
M@lik Ali am 1 Feb. 2013
Beantwortet: Rodrigo Souza am 28 Jan. 2019
Hi ALL,
I want to calculate the means luminance value of an image block
i found the formula is..
luminance= 0.3 R + 0.59 G + 0.11 B
but how i can calculate the R, G and B values.
i know that
R=rgb_img(:,:,1)
G=rgb_img(:,:,2)
B=rgb_img(:,:,3)
but it give in the shape of matrix, i think i need only a single value of R,G and B, to use above luminance formula.
please help me out.
Thanks in Advance

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 1 Feb. 2013
mean2(rgb2gray(rgb_img))
provided you have the toolbox installed.
Otherwise, calculate a luminance array using the R, G, B arrays, and then mean2() the luminance array.
  4 Kommentare
Walter Roberson
Walter Roberson am 1 Jul. 2017
rgb2gray converts RGB values to grayscale values by forming a weighted sum of the R, G, and B components:
0.2989 * R + 0.5870 * G + 0.1140 * B
[...] First convert the gamma-compressed RGB values to linear RGB, and then
Y = 0.2126 R + 0.7152 G + 0.0722 B
Do you mean brightness? Perceived brightness? Luminance?
Luminance (standard for certain colour spaces): (0.2126*R + 0.7152*G + 0.0722*B)
Luminance (perceived option 1): (0.299*R + 0.587*G + 0.114*B)
Luminance (perceived option 2, slower to calculate): sqrt( 0.299*R^2 + 0.587*G^2 + 0.114*B^2 )
So we see that the "Rleative luminance" given in the Wikipedia article is "for certain colour spaces", and the "Perceived option 1" is what is used by rgb2gray. If I recall correctly, the second perceived one is considered slightly more correct in terms of theory.
So... you have to decide which colorspace you are working in, and which variety of "luminance" you want.
Maria Hernandez
Maria Hernandez am 6 Jul. 2017
Thanks for taking the time to answer, Walter =)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rodrigo Souza
Rodrigo Souza am 28 Jan. 2019
Hi all,
I have put together three scripts for calculating (mean and SD), matching or normalizing luminance of colored images (using HSV and CIE Lab color spaces).
They may be specially useful for pupillometry measures of infant research.
The scripts and their descriptions are available at my OSF page: https://osf.io/auzjy/
Hope it helps.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by