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()


相关推荐
碳基硅坊1 分钟前
Claude Mythos:Anthropic 最强模型的技术解析与安全评估
人工智能·claude·claude mythos
计算机毕设源码分享88888818 分钟前
中班幼儿户外体育游戏教师指导的现状及对策研究——以潍坊市A幼儿园为例
人工智能
AiTop10018 分钟前
商汤发布SenseNova 6.7 Flash-Lite:原生多模态架构打破“视觉转文本“瓶颈,Token消耗直降 60%
人工智能·ai·架构
阿星AI工作室1 小时前
为了听到代码的声音,我vibecoding了一架钢琴丨code piano
人工智能
我这一拳20年的功力1 小时前
剪不断,理还乱?从Vibe到Harness的这些名词
人工智能
茶马古道的搬运工1 小时前
AI 深度技能之-模型路由(一)-必要性
人工智能
现代野蛮人1 小时前
【深度学习】 —— VGG-16 网络实现猫狗识别
网络·人工智能·python·深度学习·tensorflow
aneasystone本尊1 小时前
让小龙虾分身:多 Agent 路由与 Sub-agents
人工智能
用户5191495848451 小时前
Camaleon CMS 认证本地文件包含 (LFI) 漏洞利用工具
人工智能·aigc
阿里云大数据AI技术1 小时前
PAI部署Hermes Agent全攻略,打造越用越懂你的AI助手
人工智能·agent