What formula for the mean pixel value is used in the {ia} variable?

Hello everyone,

if I have a color image (RGB), what formula is used to calculate the “mean” that is in the variable {ia}?
What formula is used to calculate the intensity (luminosity) from the values R, G, B?
How do I quick calculate the mean if I want to use my own formula to calculate the intensity?

Thank you.

The math variable ia is actually the mean of all values of your image, regardless it is a RGB, RGBA or a X-channels image. ia is always a scalar value.
There are several ways to get the average vector-value in G’MIC.
One solution is to use the average_vectors command that returns a list of values from one image :

sp colorful 
avg=${-average_vectors.}
echo $avg

If you want to compute this average vector-value directly from a math formula (e.g. in an eval command), then you can do something as:

sp colorful
eval "
  V = vector(#s);
  fill(V,k,avg(crop(#-1,0,0,0,k,w,h,d,1)));
 print(V);
"
2 Likes

Thanks @David_Tschumperle. If I understand correctly, this command

gmic sp colorful avg=[\${-average_vectors.}] echo "{0.299*\$avg[0]+0.587*\$avg[1]+0.114*\$avg[2]}"

gives the average luminosity.