3DGabor滤波器实现人脸特征提取

python 复制代码
import cv2
import numpy as np

# 定义 Gabor 滤波器的参数
kSize = 31  # 滤波器核的大小
g_sigma = 3.0  # 高斯包络的标准差
g_theta = np.pi / 4  # Gabor 函数的方向
g_lambda = 10.0  # 正弦波的波长
g_gamma = 0.5  # 空间纵横比
g_psi = np.pi / 2  # 相位偏移

# 生成 Gabor 滤波器核
kernel = cv2.getGaborKernel((kSize, kSize), g_sigma, g_theta, g_lambda, g_gamma, g_psi, ktype=cv2.CV_32F)

# 读取多波段图像
image = cv2.imread('1.png', cv2.IMREAD_UNCHANGED)

# 获取图像的波段数
num_bands = image.shape[2] if len(image.shape) == 3 else 1

# 初始化处理后的多波段图像
filtered_image = np.zeros_like(image, dtype=np.float32)

# 遍历每个波段
for band in range(num_bands):
    # 提取当前波段
    band_image = image[:, :, band] if len(image.shape) == 3 else image

    # 应用 Gabor 滤波器
    filtered_band_image = cv2.filter2D(band_image, cv2.CV_32F, kernel)

    # 将处理后的波段放回结果图像中
    if len(image.shape) == 3:
        filtered_image[:, :, band] = filtered_band_image
    else:
        filtered_image = filtered_band_image

# 将处理后的图像转换为合适的数据类型
filtered_image = np.clip(filtered_image, 0, 255).astype(np.uint8)

# 显示结果
if num_bands == 3:
    cv2.imshow('Original Image', image)
    cv2.imshow('Filtered Image', filtered_image)
else:
    for band in range(num_bands):
        cv2.imshow(f'Original Band {band + 1}', image[:, :, band] if len(image.shape) == 3 else image)
        cv2.imshow(f'Filtered Band {band + 1}', filtered_image[:, :, band] if len(image.shape) == 3 else filtered_image)

# 保存结果
cv2.imwrite('filtered_multiband_image.png', filtered_image)

# 等待按键,然后关闭所有窗口
cv2.waitKey(0)
cv2.destroyAllWindows()


相关推荐
Y1nhl40 分钟前
Pyspark学习一:概述
数据库·人工智能·深度学习·学习·spark·pyspark·大数据技术
简简单单做算法3 小时前
基于mediapipe深度学习和限定半径最近邻分类树算法的人体摔倒检测系统python源码
人工智能·python·深度学习·算法·分类·mediapipe·限定半径最近邻分类树
就决定是你啦!4 小时前
机器学习 第一章 绪论
人工智能·深度学习·机器学习
Wnq100725 小时前
智能巡检机器人在化工企业的应用研究
运维·计算机视觉·机器人·智能硬件·deepseek
有个人神神叨叨6 小时前
OpenAI发布的《Addendum to GPT-4o System Card: Native image generation》文件的详尽笔记
人工智能·笔记
林九生6 小时前
【Python】Browser-Use:让 AI 替你掌控浏览器,开启智能自动化新时代!
人工智能·python·自动化
liuyunshengsir7 小时前
AI Agent 实战:搭建个人在线旅游助手
人工智能·旅游
Shawn_Shawn7 小时前
大模型微调介绍
人工智能
TiAmo zhang7 小时前
DeepSeek-R1 模型现已在亚马逊云科技上提供
人工智能·云计算·aws
liruiqiang057 小时前
循环神经网络 - 简单循环网络
人工智能·rnn·深度学习·神经网络·机器学习