我想向一张之前调整过大小的图像添加AdditiveGaussianNoise
(链接:https://imgaug.readthedocs.io/en/latest/source/overview/arithmetic.html#additivegaussiannoise)。
这是我的代码:
from skimage.io import imreadfrom skimage.transform import resizeimport imgaug.augmenters as iaafile_name = "path/to/image.jpg"resized_img = resize(imread(file_name), (224, 224))aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))augmented_image = aug(resized_img)
我得到了这个错误信息:
---------------------------------------------------------------------------AssertionError Traceback (most recent call last)<ipython-input-20-e4a0b17d4ac4> in <module>()----> 1 augmented_image =aug(resized_img)1 frames/usr/local/lib/python3.6/dist-packages/imgaug/augmenters/meta.py in augment(self, return_batch, hooks, **kwargs) 1782 ("Expected boolean as argument for 'return_batch', got type %s. " 1783 + "Call augment() only with named arguments, e.g. "-> 1784 + "augment(images=<array>).") % (str(type(return_batch)),) 1785 ) 1786 AssertionError: Expected boolean as argument for 'return_batch', got type <class 'numpy.ndarray'>. Call augment() only with named arguments, e.g. augment(images=<array>).
我需要如何修改我的代码?
非常感谢!
回答:
这是使用随机图像的解决方案…您需要指定images
参数
import numpy as npimport imgaug.augmenters as iaaimg = np.random.randint(0,256, (1,224,224,3)).astype('float32')aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))augmented_image = aug(images=img)