【深度学习】图片预处理,分辨出模糊图片

ref:https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/

论文 ref:https://www.cse.cuhk.edu.hk/leojia/all_final_papers/blur_detect_cvpr08.pdf

遇到模糊的图片,还要处理一下,把它挑出来,要么修复,要么弃用。否则影响后续效果。




根据模糊值排序即可,写在文件名中,自动排序,然后对模糊的去掉即可

python 复制代码
import os.path

from imutils import paths
import argparse
import cv2
import shutil


def variance_of_laplacian(image):
    # compute the Laplacian of the image and then return the focus
    # measure, which is simply the variance of the Laplacian
    return cv2.Laplacian(image, cv2.CV_64F).var()


# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", default=r"D:\dataset\imgs_bk\imgs_bk",
                help="path to input directory of images")
ap.add_argument("-t", "--threshold", type=float, default=400.0,
                help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())
count_num = 0
for imagePath in paths.list_images(args["images"]):
    # load the image, convert it to grayscale, and compute the
    # focus measure of the image using the Variance of Laplacian
    # method
    image = cv2.imread(imagePath)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    fm = variance_of_laplacian(gray)
    text = "Not Blurry"
    print("res:", imagePath, fm)
    # if the focus measure is less than the supplied threshold,
    # then the image should be considered "blurry"
    # for threshold in [100, 200, 300, 400, 500]:
    # if fm < threshold:
    # text = "Blurry"
    # # show the image
    # cv2.putText(image, "{}: {:.2f}".format(text, fm), (10, 30),
    #             cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
    # # cv2.imshow("Image", image)
    _, file_name = os.path.split(imagePath)
    # dst_dir = r"D:\code\baidu-spider\blur_img"
    # os.makedirs(dst_dir, exist_ok=True)
    # dst_path = os.path.join(dst_dir, str(fm) + "-" + file_name)
    # cv2.imwrite(dst_path, image)
    dst_path_blank = os.path.join(r"D:\dataset\blank-blur-order", str(fm) + '-' + file_name)
    shutil.copy(imagePath, dst_path_blank)

count_num += 1

# key = cv2.waitKey(0)

本质是一个拉普拉斯变换!!

还挺好用的。

我感觉300,400的阈值,就会好很多了。

相关推荐
weixin_4684668537 分钟前
Ava 2.0 智能应用场景落地指南
人工智能·自然语言处理·大模型·智能交互·ava
John_ToDebug39 分钟前
MCP 深度解析:大模型的“万能插头”
人工智能·经验分享·ai
浦信仿真大讲堂1 小时前
CST 仿真软件与 AI 融合的工程应用实战
人工智能·仿真软件·达索仿真·达索软件
mit6.8241 小时前
A Software Engineer‘s Apology | CODA
人工智能
chnyi6_ya1 小时前
论文阅读:CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer
论文阅读·深度学习·transformer
段一凡-华北理工大学1 小时前
2026 高炉炼铁智能化技术全景与演进路径~系列文章11:演进路径与行业未来
大数据·网络·人工智能·算法·工业智能体·高炉炼铁智能化
小脑斧1231 小时前
AI技能化落地:从对话式大模型到可生产、可复用的AI工程体系
人工智能·skills·openclaw·hermes·marvis
西陵1 小时前
Agent 为什么会陷入 Doom Loop?OpenClaw 的破解之道
前端·人工智能·ai编程
飞哥数智坊1 小时前
动动嘴皮子就把事干了,Mic Air + TRAE SOLO 让我越来越懒
人工智能
喜欢踢足球的老罗1 小时前
从移动开发转型 AI Agent 工程师:我做了一个开源学习系统
人工智能·学习