'What kind of image restoration method that I need to apply to restore the image?

I struggled to restore the image using Python. I tried these types of filters which are listed below. Could you help me to overcome this problem, please?

Original Image

  • Gaussian Filter estimation for degredation function.

The code is;

import numpy as np
   from skimage import io, color
   import matplotlib.pyplot as plt

   def gaussian_filter(k=3, sigma=10):
      ''' Gaussian filter
      :param k: defines the lateral size of the kernel/filter, default 5
      :param sigma: standard deviation (dispersion) of the Gaussian distribution
      :return matrix with a filter [k x k] to be used in convolution operations
      '''
      arx = np.arange((-k // 2) + 1.0, (k // 2) + 1.0)
      x, y = np.meshgrid(arx, arx)
      filt = np.exp(-(1/2) * (np.square(x) + np.square(y)) / np.square(sigma))
      return filt / np.sum(filt)

   f = io.imread("q2.jpg")
   f = color.rgb2gray(f);
   io.imsave("deneme1.jpg",f)
   h = gaussian_filter(k=7, sigma=1)

   # computing the number of padding on one side
   hx = int(f.shape[0]//2 - h.shape[0]//2)
   hy = int(f.shape[1]//2 - h.shape[1]//2)
   print(f.shape[1]//2)
   print(h.shape[0]//2)
   print(f.shape)
   h_pad = np.pad(h, ((hx,hx-1),(hy,hy)), 'constant', constant_values=(0))

   # computing the Fourier transforms
   F = np.fft.fft2(f)
   H = np.fft.fft2(h_pad)
   #H[np.abs(H)<=] = 1

   plt.subplot(121)
   plt.imshow(np.fft.fftshift(np.log(np.abs(F)+1)), cmap="gray")
   plt.subplot(122)
   plt.imshow(np.fft.fftshift(np.log(np.abs(H)+1)), cmap="gray")
 
   # Filtering
   G = F/H

   # Inverse Transform
   # - we have to perform FFT shift before reconstructing the image in the space domain
   g = np.fft.ifftshift(np.fft.ifft2(G))

   plt.figure(figsize=(12,5))
   plt.subplot(121)
   plt.imshow(f, cmap="gray");
   plt.title("original image")
   plt.subplot(122)
   plt.imshow(abs(g), cmap="gray");
   plt.title("degraded/blurred image")

The output is;

Fourier domain of original image and gaussian filter

Orginal gray image and restored image

  • Global and Local histogram equalization.
#LOCAL AND GLOBAL EQUALIZATION

   import numpy as np
   import matplotlib.pyplot as plt
   from skimage import data,io,color, filters, exposure
   import skimage.morphology as morp

   # Original image
   img = io.imread("q2.jpg")
   img = color.rgb2gray(img)

   # Global equalize
   img_global = exposure.equalize_hist(img)

   # Local Equalization, disk shape kernel
   # Better contrast with disk kernel but could be different
   kernel = morp.disk(75)
   img_local = filters.rank.equalize(img, selem=kernel)

   fig, (ax_img, ax_global, ax_local) = plt.subplots(1, 3,figsize=(15,15))

   ax_img.imshow(img, cmap=plt.cm.gray)
   ax_img.set_title('Low contrast image')
   ax_img.set_axis_off()

   ax_global.imshow(img_global, cmap=plt.cm.gray)
   ax_global.set_title('Global equalization')
   ax_global.set_axis_off()
 
   ax_local.imshow(img_local, cmap=plt.cm.gray)
   ax_local.set_title('Local equalization')
   ax_local.set_axis_off()

The output is;

The output

I have also tried sobel filter to export edges, unsharpening filters. The result was not satisfied.

The noise might be gamma or rayleigh noise but I don't know how I assume degradation function and also how I implement these noise functions on Python.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source