Python 检测运动模糊 源代码

目录

模拟运动模糊:

[Python 检测运动模糊 源代码](#Python 检测运动模糊 源代码)


模拟运动模糊:

https://blog.csdn.net/jacke121/article/details/109191473

Python 检测运动模糊 源代码

python 复制代码
import cv2
import numpy as np

def detect_motion_blur(img, blur_threshold=100, direction_threshold=0.8):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (3,3), 0)

    # Sobel 边缘
    gx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=3)
    gy = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=3)

    magnitude = np.sqrt(gx**2 + gy**2)
    angle = np.arctan2(gy, gx)

    # 模糊程度
    blur_score = cv2.Laplacian(gray, cv2.CV_64F).var()

    # 梯度方向分布统计
    hist, _ = np.histogram(angle, bins=36, range=(-np.pi, np.pi))
    hist = hist / np.sum(hist)

    # 如果梯度方向过于集中(说明只有一个方向清晰)
    concentration = np.max(hist)

    if blur_score < blur_threshold:
        if concentration > direction_threshold:
            return "运动模糊", blur_score, concentration
        else:
            return "普通模糊", blur_score, concentration
    else:
        return "清晰", blur_score, concentration
相关推荐
东隆科技3 小时前
PRIMES推出SFM 2D全扫描场分析仪革新航空航天LPBF激光增材制造
人工智能·制造
无风听海3 小时前
神经网络之计算图repeat节点
人工智能·深度学习·神经网络
刘晓倩3 小时前
在PyCharm中创建项目并练习
人工智能
Dev7z3 小时前
阿尔茨海默病早期症状影像分类数据集
人工智能·分类·数据挖掘
神码小Z3 小时前
DeepSeek再开源3B-MoE-OCR模型,视觉压缩高达20倍,支持复杂图表解析等多模态能力!
人工智能
maxruan3 小时前
PyTorch学习
人工智能·pytorch·python·学习
吃饭睡觉发paper3 小时前
Learning Depth Estimation for Transparent and Mirror Surfaces
人工智能·机器学习·计算机视觉
沃达德软件4 小时前
视频图像数据库基础服务
数据库·图像处理·人工智能·计算机视觉·视觉检测
jjjxxxhhh1234 小时前
【AI】-RNN/LSTM ,Transformer ,CNN 通俗介绍
人工智能·rnn·lstm