I have entry level question about camera feature in iOS . Working for app which have photo submission feature meanwhile I need to check the contrast of the photo to check the photo clarity. If is not in range of specified I'll pass an alert to take picture again. I am filtering Google from last few hours but still am on search bar, not yet found any useful thing to check the contrast of the photo.
-
i think this is not done before – Kumar Jul 22 '15 at 10:14
-
r u try to get the brightness or contrast – Anbu.Karthik Jul 22 '15 at 10:44
-
if possible i need both contrast and brightness – Code cracker Jul 22 '15 at 10:45
2 Answers
Since you are capturing photos, I guess you are looking for a way to detect over-/underexposed photos.
One common way of doing this is to calculate the image's histogram. If your image is underexposed, you should see that the lower (dark) end of the histogram looks "clipped", e.g.
If the image is overexposed, the light areas are clipped instead.
Ideally, the image contains very few pixels at the far ends of the histogram:
balanced
To calculate the histogram, you can use OpenCV or GPUImage.
Histogram equalization
If the histogram is clipped, the photo has suffered irreparable damage from under/over-exposure - too much image data may has been thrown away by the quantization. If not, however, you may use histogram equalization to normalize the contrast level of the image. Here is an good document using OpenCV. You will lose some color fidelity, but this is essentially what the "enhance image" filter in image editing software does.

- 31,081
- 7
- 77
- 119
-
particularly i need to get contrast of the photo. histogram can do this?. I verified GPUImage there is nothing about fetching contrast – Code cracker Jul 22 '15 at 11:20
-
First you have to *define* a measure for contrast. The width of the histogram is probably a good measure of the contrast, using some kind of width measure (gaussian fitting, maybe?). Note that if the histogram is not clipped, you can easily normalize it (no need to reject the image). – Krumelur Jul 22 '15 at 11:26
-
http://stackoverflow.com/questions/13397394/how-to-measure-contrast-in-opencv-visual-c – Krumelur Jul 22 '15 at 12:25
Hope using kCGImagePropertyExifDictionary with
const CFStringRef kCGImagePropertyExifContrast and - kCGImagePropertyExifContrast The contrast applied to the image.
const CFStringRef kCGImagePropertyExifBrightnessValue - The brightness value.
Available in iOS 4.0 and later with apple reference link
may help you to calculate brightness and contrast information from image
-
Interesting, I did not know that EXIF metadata held brightness and contrast. Do you know what the values mean? – Krumelur Jul 22 '15 at 11:23
-
Not much About these but extracting EXIF data from the image itself rather than banging it into a db. this requires jpg files as png’s didn’t seem to work. – soumya Jul 22 '15 at 11:32
-
"kCGImagePropertyExifDictionary" having only colorspace and pixel dimension in x and y not the brightness and contrast – Code cracker Jul 22 '15 at 12:00
-
Could it be that the values are post-processing hints, like orientation? To be able to adjust brightness/contrast non-destructively. – Krumelur Jul 22 '15 at 12:23