Adding AdditiveGaussianNoise to a single image - AssertionError: Expected boolean as argument for 'return_batch'

Adding AdditiveGaussianNoise to a single image - AssertionError: Expected boolean as argument for 'return_batch'

我想将 AdditiveGaussianNoise (link: https://imgaug.readthedocs.io/en/latest/source/overview/arithmetic.html#additivegaussiannoise) 添加到我之前调整大小的单个图像中。

这是我的代码:

from skimage.io import imread
from skimage.transform import resize
import imgaug.augmenters as iaa

file_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 np
import imgaug.augmenters as iaa

img = np.random.randint(0,256, (1,224,224,3)).astype('float32')

aug = iaa.AdditiveGaussianNoise(scale=(0, 0.2*255))
augmented_image = aug(images=img)