In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import cv2
In [2]:
im = plt.imread('testim3.png')
plt.imshow(im)
Out[2]:
In [3]:
im2 = cv2.GaussianBlur(im, (15, 15), 0)
print(im2.dtype, im2.shape)
plt.imshow(im2)
im3 = im - im2
rmin, rmax = np.min(im3, axis=(0, 1)), np.max(im3, axis=(0, 1))
im3 = (im3 - rmin) / (rmax - rmin)
plt.figure()
plt.imshow(im3)
Out[3]:
In [4]:
from PIL import Image
from PIL.ImageFilter import GaussianBlur
im4 = Image.open('testim3.png') # RGB 3-channel image
im5 = im4.filter(GaussianBlur(radius=2))
im4 = np.asarray(im4.getdata()).reshape(im4.size[::-1]+(3,)).astype('uint8')
im5 = np.asarray(im5.getdata()).reshape(im5.size[::-1]+(3,)).astype('uint8')
print(im4.dtype, im5.dtype)
plt.imshow(im5)
im6 = im4 - im5
rmin, rmax = np.min(im6, axis=(0, 1)), np.max(im6, axis=(0, 1))
im6 = (im6 - rmin) / (rmax - rmin)
plt.figure()
plt.imshow(im6)
Out[4]: