imagecorruptions函数详解

文章介绍了GitHub上的imagecorruptions库,用于在Python中对图像进行15种类型的增强,如噪声、模糊、失真等。提供了安装方法、函数用法和示例,演示了如何使用该库进行图像增强并保存结果。
部署运行你感兴趣的模型镜像

1.函数库安装

pip install imagecorruptions

2.函数介绍

def corrupt(image, severity=1, corruption_name=None, corruption_number=-1)
    """This function returns a corrupted version of the given image.
    
    Args:
        image (numpy.ndarray):      image to corrupt; a numpy array in [0, 255], expected datatype is np.uint8
                                    expected shape is either (height x width x channels) or (height x width); 
                                    width and height must be at least 32 pixels;
                                    channels must be 1 or 3;
        severity (int):             strength with which to corrupt the image; an integer in [1, 5]
        corruption_name (str):      specifies which corruption function to call, must be one of
                                        'gaussian_noise', 'shot_noise', 'impulse_noise', 'defocus_blur',
                                        'glass_blur', 'motion_blur', 'zoom_blur', 'snow', 'frost', 'fog',
                                        'brightness', 'contrast', 'elastic_transform', 'pixelate', 'jpeg_compression',
                                        'speckle_noise', 'gaussian_blur', 'spatter', 'saturate';
                                    the last four are validation corruptions
        corruption_number (int):    the position of the corruption_name in the above list; an integer in [0, 18]; 
                                        useful for easy looping; 15, 16, 17, 18 are validation corruption numbers
    Returns:
        numpy.ndarray:              the image corrupted by a corruption function at the given severity; same shape as input
    """

severity为图像增强的强度,强度区间为[1,5]
corruption_name为增强的类型:分别为是 ‘gaussian_noise’, ‘shot_noise’, ‘impulse_noise’, ‘defocus_blur’, ‘glass_blur’, ‘motion_blur’, ‘zoom_blur’, ‘snow’, ‘frost’, ‘fog’, ‘brightness’, ‘contrast’, ‘elastic_transform’, ‘pixelate’, ‘jpeg_compression’,‘speckle_noise’, ‘gaussian_blur’, ‘spatter’, ‘saturate’ 共15种类型

3.使用教程

from imagecorruptions import corrupt
import cv2
import numpy as np

image = cv2.imread('2.jpg')   #被处理的图片
corrupted_image = corrupt(image, corruption_name='snow', severity=5)
cv2.imshow('Image', image)
cv2.imshow('corrupted_image', corrupted_image)   #显示增强结果
cv2.imwrite('corrupted_image.jpg',corrupted_image)	#保存增强结果
cv2.waitKey(0)  

如果想处理多张图像,加个循环即可。

4.处理效果

15种增强方式的处理效果

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火星小哼哼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值