The steps for this recipe are as follows:
- Load the image as grayscale and convert every pixel value to the np.float32 data type in the [0, 1] range:
import cv2import numpy as npimage = cv2.imread('../data/Lena.png', 0).astype(np.float32) / 255
- Apply per-element exponentiation using the specified exponent value, gamma:
gamma = 0.5corrected_image = np.power(image, gamma)
- Display the source and result images:
cv2.imshow('image', image)cv2.imshow('corrected_image', corrected_image)cv2.waitKey()cv2.destroyAllWindows()