How can I change the contrast of an image using OpenCV?

老子叫甜甜 提交于 2019-12-13 16:23:34

问题


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.


回答1:


Contrast is a bit of an imprecise term in image processing - but normally you would do this by stretching/compressing the histogram




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8680593/how-can-i-change-the-contrast-of-an-image-using-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!