How to do it...

Perform the following steps:

  1. Import the packages:
import cv2import numpy as npimport matplotlib.pyplot as plt
  1. Load an image, convert it to floating-point, and scale it down to the [0, 1] range:
image = cv2.imread('../data/Lena.png').astype(np.float32) / 255
  1. Create noise in the image by adding random values to each pixel, and display it:
noised = (image + 0.2 * np.random.rand(*image.shape).astype(np.float32))noised = noised.clip(0, 1)plt.imshow(noised[:,:,[2,1,0]])plt.show()
  1. Apply GaussianBlur to the noisy image and show the result:
gauss_blur = cv2.GaussianBlur(noised, (7, 7), 0)plt.imshow(gauss_blur[:, :, [2, 1, 0]])plt.show()
  1. Apply median filtering:
median_blur = cv2.medianBlur((noised * 255).astype(np.uint8), ...

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.