An Introduction to Adjust Image Contrast in Python OpenCV

There is no function to adjust image contrast in python opencv, however, we can add weight of image pixel to adjust contrast. In this tutorial, we will use an example to show you how to do.

Adjust Image Contrast Using cv2.addWeighted() in Python OpenCV

1.Read an image

import cv2
import numpy as np
img = cv2.imread("pyimg.jpg")

2.Create a contrast image using cv2.addWeighted()

contrast_img = cv2.addWeighted(img, 2.5, np.zeros(img.shape, img.dtype), 0, 0)
cv2.imshow('Original Image', img)
cv2.imshow('Contrast Image', contrast_img)
cv2.waitKey(0)

An Introduction to Adjust Image Contrast in Python OpenCV Example