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...