Reputation: 34680
I'd like to look at the contrast of an image in a certain masked region, and reduce it if it is too great. Are there built-in functions that can help me with this? If not, what sort of algorithm should I be looking at? I assume I would be looking at/changing the value of pixels to bring them closer to the average, and perhaps average distance from the average is a good measure of initial contrast?
I am using EmguCV if that is relevant.
Upvotes: 2
Views: 8455
Reputation: 9899
If you are using OpenCV, you will not need to directly extract the histogram from the image.
If you want to adjust the contrast of an image by histogram equalization, OpenCV has the equalizeHist function.
Note however that histogram equalization is not always what you want when you are adjusting the contrast of an image. If you want to do contrast stretching (a very simple, yet effective algorithm), you only have to find the minimum and maximum gray level (pixel value) of the image and apply the following point operation to each image pixel:
newValue = 255 * (oldValue - minValue)/(maxValue - minValue)
I assume here that each pixel takes the values in the range 0-255. Also, minValue and maxValue correspond to the minimum and maximum gray level values in the input image.
Upvotes: 5
Reputation: 3568
Like Martin said, you want to modify the image by manipulating the distribution of gray respectively color values. A generic solution are curves you apply on the histogram, you can play around with such curves in The Gimp. For examples on how to apply basic image processing and histogram manipulation functions with OpenCV, you could have a look at mango
Upvotes: 1
Reputation: 96167
Contrast is a bit of an imprecise term in image processing - but normally you would do this by stretching/compressing the histogram
Upvotes: 2