Python 图像处理基础 (七) 空域图像的卷积运算

空域图像的卷积运算

Python 图像处理基础 (七) 空域图像的卷积运算_第1张图片

# 空域图像的低通滤波卷积运算
import numpy as np
from PIL import Image
from scipy.signal import convolve2d,gaussian
import matplotlib.pylab as plt

im = np.mean(Image.open('images/vic.png'), axis=2) #np.mean(misc.face(), axis=2)
ker = np.outer(gaussian(11, 3), gaussian(11, 3)) # 2D Gaussian kernel of size 11x11 with σ = 3
im_blur = convolve2d(im, ker, 'same')


plt.figure(figsize=(12,8))
plt.subplot(121),plt.imshow(im,cmap='gray'),plt.axis('off')
plt.subplot(122),plt.imshow(im_blur,cmap='gray'),plt.axis('off')
plt.show()

Python 图像处理基础 (七) 空域图像的卷积运算_第2张图片

# x 方向上的 prewitt 算子
import numpy as np
from PIL import Image
from scipy.signal import convolve2d
import matplotlib.pylab as plt

im = np.mean(Image.open('images/vic.png'), axis=2) #np.mean(misc.face(), axis=2)
ker = np.array([[-1,-1,-1],[0,0,0],[1,0,1]])
im_blur = convolve2d(im, ker, 'same')

plt.figure(figsize=(12,8))
plt.subplot(121),plt.imshow(im,cmap='gray'),plt.axis('off')
plt.subplot(122),plt.imshow(im_blur,cmap='gray'),plt.axis('off')
plt.show()

Python 图像处理基础 (七) 空域图像的卷积运算_第3张图片

import numpy as np
from PIL import Image, ImageFilter
import matplotlib.pylab as plt

im = Image.open('images/vic.png').convert('L') #np.mean(misc.face(), axis=2)
im_blur = im.filter(ImageFilter.CONTOUR)

plt.figure(figsize=(12,8))
plt.subplot(121),plt.imshow(im,cmap='gray'),plt.axis('off')
plt.subplot(122),plt.imshow(im_blur,cmap='gray'),plt.axis('off')
plt.show()

Python 图像处理基础 (七) 空域图像的卷积运算_第4张图片

你可能感兴趣的:(Python,图像处理基础,python,图像处理,numpy)