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


相关推荐
Rubin智造社1 分钟前
从“+AI”到“AI原生”:一场底层逻辑的思维革命
人工智能·ai-native
波动几何7 分钟前
个人信息脱敏的本人角色模板技能personal-self
人工智能
领麦微红外9 分钟前
MLX90614的国产替代方案——了解FW-D1红外测温传感器
人工智能·智能家居
回眸&啤酒鸭10 分钟前
【回眸】搞钱灵感——AI 数字人口播博主自动化运营
大数据·人工智能·自动化
想会飞的蒲公英11 分钟前
逻辑回归为什么叫回归,却用来做分类
人工智能·python·分类·回归·逻辑回归
ZZZMMM.zip15 分钟前
思维安检门-逻辑漏洞分析的HarmonyOS开发实践
人工智能·华为·harmonyos·鸿蒙·鸿蒙系统
B8017913Y18 分钟前
深圳学生语音识别APP解决方案对比听脑企业版更适配院校组织使用
人工智能·语音识别
KaMeidebaby21 分钟前
卡梅德生物技术快报|噬菌体筛选:噬菌体筛选工程化优化方案:基于侵染全链条参数调控与水环境应用验证
java·开发语言·人工智能·机器学习·spark
only_Klein34 分钟前
AI故障诊断工具—k8sGPT
人工智能·gpt·kubernetes
invicinble34 分钟前
使用ai工具提升开发效率(mcp工具)
人工智能