【youcans 的 OpenCV 例程200篇】193.基于Gabor 滤波器的特征提取

OpenCV 例程200篇 总目录-202205更新


【youcans 的 OpenCV 例程200篇】193.基于Gabor 滤波器的特征提取


6.5 Gabor 滤波器

Gabor 变换是一种加窗短时傅里叶变换,以高斯函数作为短时傅里叶变换的窗函数,因此可以在频域不同尺度、不同方向上提取特征。

Gabor 函数对频率和方向表达与人类视觉响应非常类似,且对图像的亮度变化、对比度变化、姿态变化都具有较强鲁棒性。Gabor 滤波器常用于边缘提取,对纹理识别和分离的效果很好;可以用于表达图像局部特征, 在视觉领域中经常被用来作图像的预处理 。

在空间域将正弦函数与高斯函数进行卷积,就得到 Gabor 滤波器,其数学表达形式为:

g ( x , y ) = e x p [ − x ′ 2 + γ y ′ 2 2 σ 2 ] ⋅ e x p [ i ( 2 π x ′ λ + ψ ) ] g(x,y) = exp[- \frac{x'^2+\gamma y'^2}{2 \sigma ^2}] \cdot exp[i(2 \pi \frac{x'}{\lambda}+\psi)] g(x,y)=exp[2σ2x2+γy2]exp[i(2πλx+ψ)]

实数部分:
g ( x , y ) = e x p [ − x ′ 2 + γ y ′ 2 2 σ 2 ] ⋅ c o s [ ( 2 π x ′ λ + ψ ) ] g(x,y) = exp[- \frac{x'^2+\gamma y'^2}{2 \sigma ^2}] \cdot cos[(2 \pi \frac{x'}{\lambda}+\psi)] g(x,y)=exp[2σ2x2+γy2]cos[(2πλx+ψ)]

虚数部分:
g ( x , y ) = e x p [ − x ′ 2 + γ y ′ 2 2 σ 2 ] ⋅ s i n [ ( 2 π x ′ λ + ψ ) ] g(x,y) = exp[- \frac{x'^2+\gamma y'^2}{2 \sigma ^2}] \cdot sin[(2 \pi \frac{x'}{\lambda}+\psi)] g(x,y)=exp[2σ2x2+γy2]sin[(2πλx+ψ)]

式中各参数的含义为:
x ′ = x c o s θ + y s i n θ y ′ = − x s i n θ + y c o s θ x' = x cos \theta + y sin \theta\\y' = - x sin \theta + y cos \theta\\ x=xcosθ+ysinθy=xsinθ+ycosθ

λ \lambda λ,滤波器核函数中正弦函数的波长,像素数,大于2,小于图像尺寸的 1/5。
ψ \psi ψ,滤波器核函数中正弦函数的相位偏移,角度,-180~180度。0度时白条为中心,180度时黑条为中心。
θ \theta θ,滤波器核函数中平行条带的倾斜角度,0~360度。
γ \gamma γ,空间纵横比,核函数形状的椭圆率, γ = 1 \gamma=1 γ=1 时为圆形, γ < 1 \gamma<1 γ<1 时在条纹的平行方向伸长,通常取 0.5。
σ \sigma σ,滤波器核函数中高斯函数的标准差。
b b b,滤波器的半响应空间频率带宽,通常取 1.0,此时 σ / λ = 0.56 \sigma / \lambda = 0.56 σ/λ=0.56。带宽越小,标准差越大,平行条纹数量越多。

Gabor 滤波器的冲激响应是高斯函数与复指数函的乘积,达到时频测不准关系的下界,因此是兼顾信号在时频域的最优分辨率。

Gabor 滤波的基本思想是,不同纹理具有不同的中心频率及带宽,Gabor 滤波器是带通滤波器,只允许特定频率的纹理通过,因而可以分析和提取纹理特征。

扫描二维码关注公众号,回复: 14205940 查看本文章

Gabor 滤波器可以提取不同方向和不同尺度的特征,通常选择若干尺度和方向进行组,建立 Gabor 滤波器组。

基于 Gabor 滤波器的特征提取的实现步骤:
(1)将输入图像按空间位置分为 3×3(9块)和 4×4(16块)的图像块;
(2)选择若干尺度和方向,如 5尺度4方向,建立 Gabor 滤波器组;
(3)Gabor 滤波器组与每个图像块在空域卷积,每个图像块得到 20 个滤波器输出;
(4)将每个图像块的 24个Gabor 滤波输出,“浓缩” 为一个 24×1 的列向量作为该图像块的纹理特征。

OpenCV 中提供的 cv.getGaborKernel() 函数可以生成 Gabor 滤波器核。


1.95: Gabor 带通滤波器

    # 1.95: 基于 Gabor 带通滤波器的特征提取
    # 构造 Gabor 滤波器组
    GaborFilters = []
    size = [5, 7, 9, 11, 15]  # Gabor 滤波器尺寸
    lamda = np.pi / 2.0  # 正弦函数波长
    for i in range(4):
        theta = i * np.pi/4  # 平行条带倾斜角度,0°,45°,90°,135°
        for k in range(5):
            ksize = (size[k], size[k])  # Gabor 滤波器尺寸
            kernel = cv2.getGaborKernel(ksize, 1.0, theta, lamda, 0.5, 0, ktype=cv2.CV_32F)
            kernel /= kernel.sum()
            GaborFilters.append(kernel)

    # 读取图像
    img = cv2.imread("../images/Fractal02.png", flags=1)
    # Gabor 滤波
    plt.figure(figsize=(10, 7))
    res = []  # 滤波结果
    for i in range(len(GaborFilters)):
        accum = np.zeros_like(img)
        for kern in GaborFilters[i]:
            fimg = cv2.filter2D(img, cv2.CV_8UC1, kern)
            accum = np.maximum(accum, fimg, accum)
        res.append(np.asarray(accum))
        plt.subplot(4, 5, i + 1), plt.axis('off')
        plt.imshow(cv2.cvtColor(accum, cv2.COLOR_BGR2RGB))

    plt.tight_layout()
    plt.show()

在这里插入图片描述



(本节完)


版权声明:

OpenCV 例程200篇 总目录-202205更新
youcans@xupt 原创作品,转载必须标注原文链接:(https://blog.csdn.net/youcans/article/details/124970610)

Copyright 2022 youcans, XUPT
Crated:2022-5-25


欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列,持续更新中
欢迎关注 『youcans 的 OpenCV学习课』 系列,持续更新中

【youcans 的 OpenCV 例程200篇】147. 图像分割之孤立点检测
【youcans 的 OpenCV 例程200篇】148. 图像分割之线检测
【youcans 的 OpenCV 例程200篇】149. 图像分割之边缘模型
【youcans 的 OpenCV 例程200篇】150. 边缘检测梯度算子
【youcans 的 OpenCV 例程200篇】151. 边缘检测中的平滑处理
【youcans 的 OpenCV 例程200篇】152. 边缘检测之 LoG 算子
【youcans 的 OpenCV 例程200篇】153. 边缘检测之 DoG 算子
【youcans 的 OpenCV 例程200篇】154. 边缘检测之 Canny 算子
【youcans 的 OpenCV 例程200篇】155. 边缘连接的局部处理方法
【youcans 的 OpenCV 例程200篇】156. 边缘连接局部处理的简化算法
【youcans 的 OpenCV 例程200篇】157. 霍夫变换直线检测
【youcans 的 OpenCV 例程200篇】158. 阈值处理之固定阈值法
【youcans 的 OpenCV 例程200篇】159. 图像分割之全局阈值处理
【youcans 的 OpenCV 例程200篇】160. 图像处理之OTSU 方法
【youcans 的 OpenCV 例程200篇】161. OTSU 阈值处理算法的实现
【youcans 的 OpenCV 例程200篇】162. 全局阈值处理改进方法
【youcans 的 OpenCV 例程200篇】163. 基于边缘信息改进全局阈值处理
【youcans 的 OpenCV 例程200篇】164.使用 Laplace 边缘信息改进全局阈值处理
【youcans 的 OpenCV 例程200篇】165.多阈值 OTSU 处理方法
【youcans 的 OpenCV 例程200篇】166.自适应阈值处理
【youcans 的 OpenCV 例程200篇】167.基于移动平均的可变阈值处理
【youcans 的 OpenCV 例程200篇】168.图像分割之区域生长
【youcans 的 OpenCV 例程200篇】169.图像分割之区域分离
【youcans 的 OpenCV 例程200篇】170.图像分割之K均值聚类
【youcans 的 OpenCV 例程200篇】171.SLIC 超像素区域分割
【youcans 的 OpenCV 例程200篇】172.SLIC 超像素区域分割算法比较
【youcans 的 OpenCV 例程200篇】173.SEEDS 超像素区域分割
【youcans 的 OpenCV 例程200篇】174.LSC 超像素区域分割
【youcans 的 OpenCV 例程200篇】175.超像素区域分割方法比较
【youcans 的 OpenCV 例程200篇】176.图像分割之均值漂移算法
【youcans 的 OpenCV 例程200篇】177.图像分割之 GraphCuts 图割法
【youcans 的 OpenCV 例程200篇】178.图像分割之 GrabCut 图割法(框选前景)
【youcans 的 OpenCV 例程200篇】179.图像分割之 GrabCut 图割法(掩模图像)
【youcans 的 OpenCV 例程200篇】180.基于距离变换的分水岭算法
【youcans 的 OpenCV 例程200篇】181.基于 Sobel 梯度的分水岭算法
【youcans 的 OpenCV 例程200篇】182.基于形态学梯度的分水岭算法
【youcans 的 OpenCV 例程200篇】183.基于轮廓标记的分水岭算法
【youcans 的 OpenCV 例程200篇】184.鼠标交互标记的分水岭算法
【youcans 的 OpenCV 例程200篇】185.图像金字塔之高斯金字塔
【youcans 的 OpenCV 例程200篇】186.图像金字塔之拉普拉斯金字塔
【youcans 的 OpenCV 例程200篇】187.由拉普拉斯金字塔还原图像
【youcans 的 OpenCV 例程200篇】188.基于拉普拉斯金字塔的图像融合
【youcans 的 OpenCV 例程200篇】189.基于掩模的拉普拉斯金字塔图像融合
【youcans 的 OpenCV 例程200篇】190.基于图像分割的图像融合
【youcans 的 OpenCV 例程200篇】191.基于图像分割的金字塔图像融合
【youcans 的 OpenCV 例程200篇】192.Gabor 滤波器组的形状
【youcans 的 OpenCV 例程200篇】193.基于Gabor 滤波器的特征提取

猜你喜欢

转载自blog.csdn.net/youcans/article/details/124970610