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

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

相关推荐
数据与人工智能律师2 分钟前
解码Web3:DeFi、GameFi、SocialFi的法律风险警示与合规路径
大数据·网络·人工智能·云计算·区块链
Best_Me073 分钟前
理解AUROC,AP,F1-scroe,PRO
人工智能·机器学习
IT_陈寒6 分钟前
React 性能优化:5个实战技巧让首屏加载提升50%,开发者亲测有效!
前端·人工智能·后端
久未11 分钟前
Pytorch autoload机制自动加载树外扩展(Autoload Device Extension)
人工智能·pytorch·python
Apifox.13 分钟前
如何在 Apifox 中通过 AI 一键生成几十个测试用例?
人工智能·程序人生·ai·测试用例·ai编程
java1234_小锋26 分钟前
TensorFlow2 Python深度学习 - TensorFlow2框架入门 - 使用Keras.Model来定义模型
python·深度学习·tensorflow·tensorflow2
Learn Beyond Limits30 分钟前
TensorFlow Implementation of Content-Based Filtering|基于内容过滤的TensorFlow实现
人工智能·python·深度学习·机器学习·ai·tensorflow·吴恩达
java1234_小锋31 分钟前
TensorFlow2 Python深度学习 - 函数式API(Functional API)
python·深度学习·tensorflow·tensorflow2
是Yu欸35 分钟前
【AI视频】从单模型,到AI Agent工作流
人工智能·ai·ai作画·aigc·音视频·实时音视频
AI人工智能+1 小时前
发票识别技术:结合OCR与AI技术,实现纸质票据高效数字化,推动企业智能化转型
人工智能·nlp·ocr·发票识别