How to do it...

The steps for this recipe are as follows:

  1. Load the image as grayscale and convert every pixel value to the np.float32 data type in the [0, 1] range:
import cv2
import numpy as np

image = cv2.imread('../data/Lena.png', 0).astype(np.float32) / 255
  1. Apply per-element exponentiation using the specified exponent value, gamma:
gamma = 0.5
corrected_image = np.power(image, gamma)
  1. Display the source and result images:
cv2.imshow('image', image)
cv2.imshow('corrected_image', corrected_image)
cv2.waitKey()
cv2.destroyAllWindows()