Image filtering and correction

Tasks

  • Substract from the original image its filtered copy
  • Filter Lena from salt and pepper
  • Make intensity correction by R(x, y, sigma) = log[I(x, y)] — log[I(x, y)G(x, y, sigma)] ,where G - gaussian, sigma - coef of blurring, - convolution remapping of image from (-1,1) to (0,255) with I = 255*I + 127

In [1]:
import matplotlib.pyplot as plt
import matplotlib.image as img
%matplotlib inline
imbyc = img.imread('./bycicle.png')
imlen = img.imread('./lena.jpg')
imfru = img.imread('./unnamed.png')
imbook = img.imread('./book.png')
fig = plt.figure(figsize=(15,10))
plt.subplot(221)
plt.imshow(imbyc,cmap='gray')
plt.subplot(222)
plt.imshow(imfru)
plt.subplot(223)
plt.imshow(imlen)
plt.subplot(224)
plt.imshow(imbook)


Out[1]:
<matplotlib.image.AxesImage at 0x1f2ab64bda0>

In [2]:
from scipy import ndimage
import numpy as np
k = np.array([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]])
flt = ndimage.convolve(imbyc, k, mode='nearest', cval=0.0)
fig = plt.figure(figsize=(15,10))
plt.subplot(131)
plt.imshow(flt,cmap='gray')
plt.subplot(132)
plt.imshow(imbyc,cmap='gray')
plt.subplot(133)
plt.imshow((imbyc-flt),cmap='gray')


Out[2]:
<matplotlib.image.AxesImage at 0x1f2a9120a20>

In [4]:
from scipy import ndimage as nimg
import numpy as np
gflt = nimg.gaussian_filter(imbyc, sigma=5)
fig = plt.figure(figsize=(15,10))
plt.subplot(131)
plt.imshow(gflt,cmap='gray')
plt.subplot(132)
plt.imshow(imbyc,cmap='gray')
plt.subplot(133)
plt.imshow((imbyc-gflt),cmap='gray')


Out[4]:
<matplotlib.image.AxesImage at 0x1f2adbce7f0>

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: