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

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

相关推荐
小蜜蜂爱编程12 小时前
卷积神经网络基础
深度学习·神经网络·cnn
老蒋新思维12 小时前
创客匠人 2025 高峰论谈(11.22-25):AI 智能体重构创始人 IP 打造与知识变现的管理逻辑
大数据·网络·人工智能·网络协议·tcp/ip·重构·知识付费
嵌入式-老费12 小时前
自己动手写深度学习框架(pytorch转ncnn)
人工智能·pytorch·深度学习
咚咚王者12 小时前
人工智能之数据分析 numpy:第八章 数组广播
人工智能·数据分析·numpy
工业机器视觉设计和实现12 小时前
我的第一个cudnn(cuda)人工智能程序(lenet)
人工智能
我叫侯小科12 小时前
PyTorch 实战:手写数字识别(MNIST)从入门到精通
人工智能·pytorch·python
Sirius Wu12 小时前
开源训练框架:MS-SWIFT详解
开发语言·人工智能·语言模型·开源·aigc·swift
Baihai_IDP12 小时前
当前的“LLM 智能”,是来自模型突破,还是工程堆砌?
人工智能·llm·aigc
Gitpchy12 小时前
Day 47 注意力热图可视化
python·深度学习·cnn
IT_陈寒12 小时前
Redis 性能提升30%的7个关键优化策略,90%开发者都忽略了第3点!
前端·人工智能·后端