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

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

相关推荐
KaneLogger3 分钟前
一套系统,让 AI 写代码的速度变成生产力
人工智能·程序员·代码规范
眼泪划过的星空11 分钟前
LangChain 两大基础提示词模板:PromptTemplate 与 ChatPromptTemplate 详解
人工智能·python·langchain
小码哥哥15 分钟前
如何评价“构建企业级 AI 知识库“这一趋势?从技术架构到落地实践的完整分析
人工智能·架构
小罗水19 分钟前
第18章 接口回归、异常演练与轻量压测
人工智能·数据挖掘·回归
卷福同学27 分钟前
AI编程出海第二步:验证关键词能否做站
前端·人工智能·后端
逻辑君31 分钟前
ANNA 认知引擎 · Humanoid 机器人训练白皮书
人工智能·深度学习·机器学习·机器人
hans汉斯32 分钟前
计算机科学与应用|改进MeanShift算法在智能监控视频中的应用研究
图像处理·人工智能·功能测试·深度学习·算法·音视频
重庆传粉科技39 分钟前
AI推荐生态下品牌内容筛选标准重构与GEO优化路径
人工智能
CIO_Alliance1 小时前
2026年最新iPaaS选型核心关键指标整合
人工智能·ai·ai+ipaas·企业cio联盟·企业级ai化转型
nvvas1 小时前
AI 智能体架构全解:从记忆、工具到多智能体协作的硬核实践
人工智能