How to do it...

Perform the following steps:

  1. Import all necessary modules:
import cv2import numpy as np
  1. Load an image and convert it to one with floating-point elements in range [0,1]:
image = cv2.imread('../data/Lena.png').astype(np.float32) / 255
  1. Subtract the mean value from each image pixel to get a zero-mean matrix. Then, divide each pixel value by its standard deviation to have a unit-variance matrix:
image -= image.mean()image /= image.std()

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.