1️⃣作业需求
选取5个尺度,36个方向共180个二维模板对一幅图像(任取,可用作业(1)的图像)分别做二维卷积,得到180幅滤波结果图像,以此作为基准Gabor滤波结果。由于这个基准算法处理速度很慢,故请试着对该方法进行改进,改进方法在要求得到同样180个卷积的结果图像的前提下,尽量提高其处理速度。
2️⃣实现源码
# coding:utf-8 import cv2 import numpy as np import pylab as pl from PIL import Image #构建Gabor滤波器 from joblib.numpy_pickle_utils import xrange def build_filters(): filters = [] ksize = [7,9,11,13,15] #gabor尺度 5个 lamda = np.pi/2.0 # 波长 # 三个参数 默认起点为0,终点为360,步长为10 for theta in np.arange(0,360,10): #gabor方向 36个方向 for k in xrange(5): kern = cv2.getGaborKernel((ksize[k],ksize[k]),1.0,theta,lamda,0.5,0,ktype=cv2.CV_32F) kern /= 1.5*kern.sum() filters.append(kern) return filters #滤波过程 def process(img,filters): accum = np.zeros_like(img) for kern in filters: fimg = cv2.filter2D(img,cv2.CV_8UC3,kern) np.maximum(accum,fimg,accum) return accum #特征图生成并显示 def getGabor(img,filters): image = Image.open(img) img_ndarray = np.asarray(image) res = [] #滤波结果 for i in xrange(len(filters)): res1 = process(img_ndarray,filters[i]) res.append(np.asarray(res1)) pl.figure(2) for temp in xrange(len(res)): pl.subplot(36,5,temp+1) #画36*5的格子显示出来 pl.imshow(res[temp],cmap='gray') pl.show() return res if __name__ == '__main__': filters = build_filters() getGabor('./dataset/image.png',filters)
其中image.png是我们要进行Gabor滤波处理的图片,也就是这张图片:
3️⃣实验结果
实验结果是36x5的图片序列,每一列从左到右代表[7,9,11,13,15]五个尺度。每一行从上至下代表0、10、20…340、350共36个维度。一共180幅滤波结果图像,使用的cv2的getGaborKernel进行优化,滤波处理的速度非常快。
⭐实验源码+报告⭐
当我们递归地实现 DFS 时,似乎不需要使用任何栈。但实际上,我们使用的是由系统提供的隐式栈,也称为调用栈(Call Stack)。