The following steps are required for this recipe:
- Import all necessary modules, open an image, print its shape and data type, and display it on the screen:
import cv2, numpy as npimage = cv2.imread('../data/Lena.png')print('Shape:', image.shape)print('Data type:', image.dtype)cv2.imshow('image', image)cv2.waitKey()cv2.destroyAllWindows()
- Convert our image to one with floating data type elements:
image = image.astype(np.float32) / 255print('Shape:', image.shape)print('Data type:', image.dtype)
- Scale the elements of our image by 2 and clip the values to keep them in the [0, 1] range:
cv2.imshow('image', np.clip(image*2, 0, 1))cv2.waitKey()cv2.destroyAllWindows()
- Scale the elements of our image back to the [0, 255] range, ...