How to do it ...

You need to perform the following steps to implement image restoration with dictionary learning using the scikit-learn library functions:

  1. Read the Lena image and degrade the lower half of the image with random Gaussian noise while keeping the upper half as it is:
lena = rgb2gray(imread('images/lena.png'))height, width = lena.shapeprint('Distorting the lower half of the image...')distorted = lena.copy()distorted[height // 2:, :] += 0.085 * \          np.random.randn(height // 2, width)
  1. Extract all 7x7 reference patches from the upper half of the image. Compute the mean and standard deviation of the extracted patches and normalize the extracted patches:
print('Extracting reference patches...')patch_size = (7, 7)data = extract_patches_2d(distorted[height ...

Get Python Image Processing 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.