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


相关推荐
醉卧考场君莫笑4 分钟前
NLP(正向,逆向,双向匹配法分词及代码实现)
人工智能·自然语言处理·easyui
拓朗工控11 分钟前
视觉革命:独立显卡工控机在医疗领域的深度应用
人工智能·智慧医疗·工控机
victory043114 分钟前
2026年4月22日 Malicious Finetuning for LLM via Steganography 解读 复现要点
人工智能
Python私教26 分钟前
Hermes Agent 技能系统:让 AI 学会自我进化
人工智能
小饕28 分钟前
RAG学习之- RAG 数据导入完整指南
人工智能·python·学习
黑客说30 分钟前
白日梦无限世界 各类型副本分析
人工智能·科技·游戏·娱乐
wearegogog12332 分钟前
基于和差波束法的单脉冲测角MATLAB实现
人工智能·算法·matlab
陈广亮41 分钟前
一个 CLAUDE.md 文件,一周涨了 44K Star:Karpathy 的 AI 编程四原则
人工智能
三秋树41 分钟前
豆包 Agent Harness 工程师入门 | 第 5 章 Skills 技能
人工智能·agent·ai编程
一线数智42 分钟前
从数字化到数智化: AI 赋能零售/餐饮高效运营
人工智能·零售