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

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的阈值,就会好很多了。

相关推荐
king135987455010 分钟前
Clipstral 视频语义检索:FFmpeg PTS 验证、向量索引与端侧部署
人工智能·ffmpeg·音视频·大语言模型·llama·本地部署·llama.cpp
鬼手点金12 分钟前
事件驱动的异步 Agent
人工智能·安全·机器学习·缓存·prompt
_小许_16 分钟前
RNN 是怎么“读”文本的:从字符到隐藏状态,手写一个字符级语言模型
人工智能·rnn·语言模型
圆心角17 分钟前
AI 没有抢走你的工作,它拆了你的训练场
前端·人工智能·ai编程
Thomas.Sir24 分钟前
第028讲:AI模型开发|文本归一化:HTML、全角空格与标点塌缩:「退 款」和「退款」为什么必须变成同一个特征
人工智能·ai
_waylau31 分钟前
Spring AI开发从入门到实践-Spring AI的应用场景与未来展望
java·人工智能·后端·spring·llm·spring ai
Zldaisy3d33 分钟前
增材制造医用惰性金属假体修复四肢骨缺损临床诊疗指南(2026)
大数据·人工智能·制造
图欧学习资源库33 分钟前
人工智能领域、图欧科技、IMYAI智能助手2026年7~9月更新月报
人工智能·科技
Zldaisy3d34 分钟前
中国一汽增材制造实践 l 战略牵引·场景驱动
人工智能
捷焱GEO34 分钟前
用页面状态和回归样本排查 AI 错用旧预约公告
前端·软件测试·人工智能·数据挖掘·回归