title: Find illuminance value of an image taken from a camera
body: <p>I got an application that should calculate the illuminance of an given photo.</p>
  
  <p>My problem is: <code>i can't find a way to calculate this illuminance index (in lux)</code></p>
  
  <p>i can get <code>luminosity</code> with this code:</p>
  
  <pre><code>UIImage* image = [UIImage imageNamed:@"image.png"];
  unsigned char* pixels = [image rgbaPixels];
  double totalLuminance = 0.0;
  for(int p=0;p&lt;image.size.width*image.size.height*4;p+=4) {
    totalLuminance += pixels[p]*0.299 + pixels[p+1]*0.587 + pixels[p+2]*0.114;
  }
  totalLuminance /= (image.size.width*image.size.height);
  totalLuminance /= 255.0;
  NSLog(@"Image.png = %f",totalLuminance);
  </code></pre>
  
  <p><a href="http://b2cloud.com.au/tutorial/obtaining-luminosity-from-an-ios-camera" rel="nofollow noreferrer">Source</a></p>
  
  <p>but the results are between <code>0 and 1</code>, witch i don't think i can use to calculate <code>illuminance</code> in <code>lux</code></p>
  
  <p>looking for an answer on stack overflow i found this answer <a href="https://stackoverflow.com/a/2720635/839049">https://stackoverflow.com/a/2720635/839049</a> witch gave me a direction, but i don't know how to proceed because i don't know what to do with exposure.</p>
  
  <blockquote>
    <p>.. you can just ignore the pixel data and just use the exposure information as a light meter. ...</p>
  </blockquote>
  
  <p>how? does anyone know how do i do that?
  or there is a better way to do it?</p>