- 卷积简介
卷积(Convolution)是数学上的一种积分变换,主要作用是为了获取某个函数的局部信息,被广泛应用于信号、图像和机器学习等领域。本文给出了图像卷积的Python实现。
- 算法实现
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
class ImageCov( object ):
#image :原图像
#convImg :卷积图像
#mfilter :滤波器
def __init__( self, filename, filterArr ):
self.image = np.array( Image.open( filename ) )
[ mI, nI ] = np.shape( self.image )
self.convImg = np.zeros( (mI, nI) )
self.mfilter = filterArr
#显示图像
def showImg( self ):
plt.figure( )
plt.imshow( self.image )
plt.axis( 'off' )
plt.figure( )
plt.imshow( self.convImg )
plt.axis( 'off' )
#计算两个矩阵的内积
def Dot2D( self, a, b ):