What's the fastest way to increase color image contrast with OpenCV in python (cv2)?

后端 未结 3 1380
我在风中等你
我在风中等你 2020-12-13 07:50

I\'m using OpenCV to process some images, and one of the first steps I need to perform is increasing the image contrast on a color image. The fastest method I\'ve found so

3条回答
  •  误落风尘
    2020-12-13 08:20

    Use the cv::addWeighted function. It's design to work on two images

    dst = cv.addWeighted( src1, alpha, src2, beta, gamma[, dst[, dtype]] )

    But if you use the same image twice AND you set beta to zero, you can get the effect you want

    dst = cv.addWeighted( src1, alpha, src1, 0, gamma)

    The big advantage to using this function is that you will not have to worry about what happens when values go below 0 or above 255. In numpy, you have to figure out how to do all of the clipping yourself. Using the OpenCV function, it does all of the clipping for you and it's fast.

提交回复
热议问题