将 AdditiveGaussianNoise 添加到单个图像 - AssertionError: Expected boolean as argument for 'return_batch'

Posted

技术标签:

【中文标题】将 AdditiveGaussianNoise 添加到单个图像 - AssertionError: Expected boolean as argument for \'return_batch\'【英文标题】:Adding AdditiveGaussianNoise to a single image - AssertionError: Expected boolean as argument for 'return_batch'将 AdditiveGaussianNoise 添加到单个图像 - AssertionError: Expected boolean as argument for 'return_batch' 【发布时间】:2020-11-20 10:08:54 【问题描述】:

我想将AdditiveGaussianNoise(链接: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>).

如何修改我的代码?

非常感谢!

【问题讨论】:

【参考方案1】:

这是使用随机图像的解决方案...您需要指定 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)

【讨论】:

如果你想输入单个图像,你可以使用 aug(image=img) 而不是 images=

以上是关于将 AdditiveGaussianNoise 添加到单个图像 - AssertionError: Expected boolean as argument for 'return_batch'的主要内容,如果未能解决你的问题,请参考以下文章

如何以编程方式将 selectableItemBackground 添​​加到 ImageButton?

通过 Cloudformation 模板将 Lambda 函数添​​加到 Kinesis Firehose

将 lambda 函数添​​加到类的符号表中

2018新品系列之atom66,静电家族添一员“小”将

添加多项选择分数

怎么用java将获取的日期往后添加一天