0

I want to calculate the luminance of image using RGB value but in the formula there is a constant k i didn't know what it is this is the formula from the document:

"In calculating luminance (L), CIE Y is multiplied by a constant value ‘k’, where k can be either aconstant for the camera or determined for a scene based on a measurement of a selected region in the scene.

L=k*(0,2127Red+0,7151Green+0,0722*Blue) (cd/m²)

this is the link to the document:https://faculty.washington.edu/inanici/Publications/LRTPublished.pdf emphasized text

  • You cannot do it, because you do not know `k`. An image cannot provide you 'k'. it depends on the brightness of the screen. And every person set screen with different brightness. You are asking a physical value (cd/m2), so you need to know the physical characteristic of a screen. In images you get just relative values, and usually the values of white (often 255,255,255). but white can have different luminance. Note: your formula is for a specific RGB colour space (probably sRGB) – Giacomo Catenazzi Mar 09 '22 at 14:49

1 Answers1

0

Short Answer

You are conflating something that is only for a specific piece of software called "Photosphere" and that math is not for general luminance use.

Complete Answer

You said:

calculate the luminance of image using RGB value

What do you mean? The luminance of some given pixel? Or the RMS average luminance? Or???

AND: What colorspace (profile) is your image in?

I am going to ASSUME your image is sRGB, and 8 bit per pixel. But it could be P3 or Adobe98, or any number of others... The math I am going to show you is for sRGB.

1) Convert to float

Each 8bit 0-255 sRGB color channel must be converted to 0.0-1.0

    let rF = sR / 255.0;
    let gF = sG / 255.0;
    let bF = sB / 255.0;

2) Convert to linear

The transfer curve aka "gamma" must be removed. For sRGB, the "accurate" method is:

    function sRGBtoLin(chan) {
       return (chan > 0.04045) ? Math.pow(( chan + 0.055) / 1.055, 2.4) : chan / 12.92
    }

3) Calculate Luminance

Now, multiply each linearized channel by the appropriate coefficient, and sum them to find luminance.

  let luminance = sRGBtoLin(rF) * 0.2126 + sRGBtoLin(gF) * 0.7152 + sRGBtoLin(bF) * 0.0722;

BONUS: Andy's Down and Dirty Version

Here's an alternate that is still usefully accurate, but simpler for better performance. Raise each channel to the power of 2.2, then multiply the coefficients, and sum:

  let lum = (sR/255.0)**2.2*0.2126+(sG/255.0)**2.2*0.7152+(sB/255.0)**2.2*0.0722;

Let me know if you have additional questions...

Myndex
  • 3,952
  • 1
  • 9
  • 24
  • thank you Myndex this informations were very usefull but after several recherches I discovered that, that k was the calibration factor some camera has a constant k for example Nikkon cameras has k= 12.5 but I am using raspberry camera I don't know how to determin the calibration factor k – Ameni Kaabi Mar 25 '22 at 10:48
  • Hi @AmeniKaabi again, you are not clear in your question—what is the SOURCE of the RGB data? Where is it coming from, exactly? Does it have a profile, such as sRGB? Does the image data display properly on a monitor? The k factor you mention may or may not be relevant, but you have not provided enough information regarding your data and data source. Thank you. – Myndex Mar 26 '22 at 19:46
  • Also @AmeniKaabi it should be noted that the k factor as you are mentioning relates to the camera's light meter relative to the actual sensor's ISO rating (I'm over simplifying). Are you trying to determine the absolute luminance of the original scene? Here is a PDF that explains exposure metering and how the k factor is relevant to scene reflectance: https://www.largeformatphotography.info/articles/conrad-meter-cal.pdf – Myndex Mar 26 '22 at 19:56
  • hello@Myndex I'll try to explain what I'm trying to do so you can help me properly am trying to determin the luminance of LED based on it's image I'm using high quality camera to picture the led in dark optic room and and then contour the light source and try to calculate the luminance out of RGB and that's when I found that formula – Ameni Kaabi Mar 31 '22 at 07:47
  • Hi @AmeniKaabi contact the camera manufacturer for the relevant data, and the pdf I linked above describes it in detail. The formula though is only relevant for linearized sRGB values, and that is not going to be the case for raw sensor values. Knowing the xy values for the bayer filter/camera sensor and the sensor ISO, an appropriate set of coefficients for Y can be determined. – Myndex Mar 31 '22 at 11:01