本文整理汇总了Python中imgaug.augmenters.AddToHueAndSaturation方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.AddToHueAndSaturation方法的具体用法?Python augmenters.AddToHueAndSaturation怎么用?Python augmenters.AddToHueAndSaturation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.AddToHueAndSaturation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def main():
image = data.astronaut()
cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
cv2.imshow("aug", image)
cv2.waitKey(TIME_PER_STEP)
# for value in cycle(np.arange(-255, 255, VAL_PER_STEP)):
for value in np.arange(-255, 255, VAL_PER_STEP):
aug = iaa.AddToHueAndSaturation(value=value)
img_aug = aug.augment_image(image)
img_aug = iaa.pad(img_aug, bottom=40)
img_aug = ia.draw_text(img_aug, x=0, y=img_aug.shape[0]-38, text="value=%d" % (value,), size=30)
cv2.imshow("aug", img_aug)
cv2.waitKey(TIME_PER_STEP)
images_aug = iaa.AddToHueAndSaturation(value=(-255, 255), per_channel=True).augment_images([image] * 64)
ia.imshow(ia.draw_grid(images_aug))
image = ia.quokka_square((128, 128))
images_aug = []
images_aug.extend(iaa.AddToHue().augment_images([image] * 10))
images_aug.extend(iaa.AddToSaturation().augment_images([image] * 10))
ia.imshow(ia.draw_grid(images_aug, rows=2))
示例2: test_augment_images__value_hue__multi_image_sampling
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images__value_hue__multi_image_sampling(self):
base_img = self.create_base_image()
class _DummyParam(iap.StochasticParameter):
def _draw_samples(self, size, random_state):
return np.float32([10, 20, 30])
aug = iaa.AddToHueAndSaturation(value_hue=_DummyParam())
img_expected1 = self._add_hue_saturation(base_img, value_hue=10)
img_expected2 = self._add_hue_saturation(base_img, value_hue=20)
img_expected3 = self._add_hue_saturation(base_img, value_hue=30)
img_observed1, img_observed2, img_observed3 = \
aug.augment_images([base_img] * 3)
assert np.array_equal(img_observed1, img_expected1)
assert np.array_equal(img_observed2, img_expected2)
assert np.array_equal(img_observed3, img_expected3)
示例3: test_augment_images__value_saturation__multi_image_sampling
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images__value_saturation__multi_image_sampling(self):
base_img = self.create_base_image()
class _DummyParam(iap.StochasticParameter):
def _draw_samples(self, size, random_state):
return np.float32([10, 20, 30])
aug = iaa.AddToHueAndSaturation(value_saturation=_DummyParam())
img_expected1 = self._add_hue_saturation(base_img, value_saturation=10)
img_expected2 = self._add_hue_saturation(base_img, value_saturation=20)
img_expected3 = self._add_hue_saturation(base_img, value_saturation=30)
img_observed1, img_observed2, img_observed3 = \
aug.augment_images([base_img] * 3)
assert np.array_equal(img_observed1, img_expected1)
assert np.array_equal(img_observed2, img_expected2)
assert np.array_equal(img_observed3, img_expected3)
示例4: test_augment_images__value_hue_and_value_saturation
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images__value_hue_and_value_saturation(self):
base_img = self.create_base_image()
class _DummyParam(iap.StochasticParameter):
def _draw_samples(self, size, random_state):
return np.float32([10, 20, 30])
aug = iaa.AddToHueAndSaturation(value_hue=_DummyParam(),
value_saturation=_DummyParam()+40)
img_expected1 = self._add_hue_saturation(base_img, value_hue=10,
value_saturation=40+10)
img_expected2 = self._add_hue_saturation(base_img, value_hue=20,
value_saturation=40+20)
img_expected3 = self._add_hue_saturation(base_img, value_hue=30,
value_saturation=40+30)
img_observed1, img_observed2, img_observed3 = \
aug.augment_images([base_img] * 3)
assert np.array_equal(img_observed1, img_expected1)
assert np.array_equal(img_observed2, img_expected2)
assert np.array_equal(img_observed3, img_expected3)
示例5: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def __init__(self):
self.seq = iaa.Sequential([
iaa.Sometimes(0.5, iaa.OneOf([
iaa.GaussianBlur((0, 3.0)), # blur images with a sigma between 0 and 3.0
iaa.AverageBlur(k=(2, 7)), # blur image using local means with kernel sizes between 2 and 7
iaa.MedianBlur(k=(3, 11)), # blur image using local medians with kernel sizes between 2 and 7
])),
iaa.Sometimes(0.5, iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5)),
iaa.Sometimes(0.5, iaa.Add((-10, 10), per_channel=0.5)),
iaa.Sometimes(0.5, iaa.AddToHueAndSaturation((-20, 20))),
iaa.Sometimes(0.5, iaa.FrequencyNoiseAlpha(
exponent=(-4, 0),
first=iaa.Multiply((0.5, 1.5), per_channel=True),
second=iaa.LinearContrast((0.5, 2.0))
)),
iaa.Sometimes(0.5, iaa.PiecewiseAffine(scale=(0.01, 0.05))),
iaa.Sometimes(0.5, iaa.PerspectiveTransform(scale=(0.01, 0.1)))
], random_order=True)
示例6: create_augmenter
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def create_augmenter(stage: str = "train"):
if stage == "train":
return iaa.Sequential([
iaa.Fliplr(0.5),
iaa.CropAndPad(px=(0, 112), sample_independently=False),
iaa.Affine(translate_percent={"x": (-0.4, 0.4), "y": (-0.4, 0.4)}),
iaa.SomeOf((0, 3), [
iaa.AddToHueAndSaturation((-10, 10)),
iaa.Affine(scale={"x": (0.9, 1.1), "y": (0.9, 1.1)}),
iaa.GaussianBlur(sigma=(0, 1.0)),
iaa.AdditiveGaussianNoise(scale=0.05 * 255)
])
])
elif stage == "val":
return iaa.Sequential([
iaa.CropAndPad(px=(0, 112), sample_independently=False),
iaa.Affine(translate_percent={"x": (-0.4, 0.4), "y": (-0.4, 0.4)}),
])
elif stage == "test":
return iaa.Sequential([])
示例7: init_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def init_augmentations(self):
if self.transform_probability > 0 and self.use_imgaug:
augmentations = iaa.Sometimes(
self.transform_probability,
iaa.Sequential([
iaa.SomeOf(
(1, None),
[
iaa.AddToHueAndSaturation(iap.Uniform(-20, 20), per_channel=True),
iaa.GaussianBlur(sigma=(0, 1.0)),
iaa.LinearContrast((0.75, 1.0)),
iaa.PiecewiseAffine(scale=(0.01, 0.02), mode='edge'),
],
random_order=True
),
iaa.Resize(
{"height": (16, self.image_size.height), "width": "keep-aspect-ratio"},
interpolation=imgaug.ALL
),
])
)
else:
augmentations = None
return augmentations
示例8: amaugimg
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def amaugimg(image):
#数据增强
image = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR)
seq = iaa.Sequential([
# iaa.Affine(rotate=(-5, 5),
# shear=(-5, 5),
# mode='edge'),
iaa.SomeOf((0, 2), #选择数据增强
[
iaa.GaussianBlur((0, 1.5)),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.01 * 255), per_channel=0.5),
# iaa.AddToHueAndSaturation((-5, 5)), # change hue and saturation
iaa.PiecewiseAffine(scale=(0.01, 0.03)),
iaa.PerspectiveTransform(scale=(0.01, 0.1))
],
random_order=True
)
])
image = seq.augment_image(image)
image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
return image
示例9: test___init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test___init__(self):
aug = iaa.AddToHueAndSaturation((-20, 20))
assert is_parameter_instance(aug.value, iap.DiscreteUniform)
assert aug.value.a.value == -20
assert aug.value.b.value == 20
assert aug.value_hue is None
assert aug.value_saturation is None
assert is_parameter_instance(aug.per_channel, iap.Deterministic)
assert aug.per_channel.value == 0
示例10: test___init___value_none
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test___init___value_none(self):
aug = iaa.AddToHueAndSaturation(value_hue=(-20, 20),
value_saturation=[0, 5, 10])
assert aug.value is None
assert is_parameter_instance(aug.value_hue, iap.DiscreteUniform)
assert is_parameter_instance(aug.value_saturation, iap.Choice)
assert aug.value_hue.a.value == -20
assert aug.value_hue.b.value == 20
assert aug.value_saturation.a == [0, 5, 10]
assert is_parameter_instance(aug.per_channel, iap.Deterministic)
assert aug.per_channel.value == 0
示例11: test___init___per_channel
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test___init___per_channel(self):
aug = iaa.AddToHueAndSaturation(per_channel=0.5)
assert aug.value is None
assert aug.value_hue is not None
assert aug.value_saturation is not None
assert is_parameter_instance(aug.per_channel, iap.Binomial)
assert np.isclose(aug.per_channel.p.value, 0.5)
示例12: test__generate_lut_table
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test__generate_lut_table(self):
def _hue(v):
return np.mod(v, 180)
def _sat(v):
return np.clip(v, 0, 255)
tables = iaa.AddToHueAndSaturation._generate_lut_table()
table_hue, table_saturation = tables
intensity_values = [0, 1, 128, 254, 255] # = pixel values
for iv in intensity_values:
with self.subTest(intensity=iv):
assert table_hue[0, iv] == _hue(iv-255) # add value: -255
assert table_hue[1, iv] == _hue(iv-254) # add value: -254
assert table_hue[254, iv] == _hue(iv-1) # add value: -1
assert table_hue[255, iv] == _hue(iv-0) # add value: 0
assert table_hue[256, iv] == _hue(iv+1) # add value: 1
assert table_hue[509, iv] == _hue(iv+254) # add value: 254
assert table_hue[510, iv] == _hue(iv+255) # add value: 255
assert table_saturation[0, iv] == _sat(iv-255) # input: -255
assert table_saturation[1, iv] == _sat(iv-254) # input: -254
assert table_saturation[254, iv] == _sat(iv-1) # input: -1
assert table_saturation[255, iv] == _sat(iv+0) # input: 0
assert table_saturation[256, iv] == _sat(iv+1) # input: 1
assert table_saturation[509, iv] == _sat(iv+254) # input: 254
assert table_saturation[510, iv] == _sat(iv+255) # input: 255
示例13: test_augment_images
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images(self):
base_img = self.create_base_image()
gen = itertools.product([False, True], ["cv2", "numpy"])
for per_channel, backend in gen:
with self.subTest(per_channel=per_channel, backend=backend):
aug = iaa.AddToHueAndSaturation(0, per_channel=per_channel)
aug.backend = backend
observed = aug.augment_image(base_img)
expected = base_img
assert np.allclose(observed, expected)
aug = iaa.AddToHueAndSaturation(30, per_channel=per_channel)
aug.backend = backend
observed = aug.augment_image(base_img)
expected = self._add_hue_saturation(base_img, 30)
diff = np.abs(observed.astype(np.float32) - expected)
assert np.all(diff <= 1)
aug = iaa.AddToHueAndSaturation(255, per_channel=per_channel)
aug.backend = backend
observed = aug.augment_image(base_img)
expected = self._add_hue_saturation(base_img, 255)
diff = np.abs(observed.astype(np.float32) - expected)
assert np.all(diff <= 1)
aug = iaa.AddToHueAndSaturation(-255, per_channel=per_channel)
aug.backend = backend
observed = aug.augment_image(base_img)
expected = self._add_hue_saturation(base_img, -255)
diff = np.abs(observed.astype(np.float32) - expected)
assert np.all(diff <= 1)
示例14: test_augment_images__different_hue_and_saturation__no_per_channel
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images__different_hue_and_saturation__no_per_channel(self):
base_img = self.create_base_image()
class _DummyParam(iap.StochasticParameter):
def _draw_samples(self, size, random_state):
arr = np.float32([10, 20])
return np.tile(arr[np.newaxis, :], (size[0], 1))
aug = iaa.AddToHueAndSaturation(value=_DummyParam(), per_channel=False)
img_expected = self._add_hue_saturation(base_img, value=10)
img_observed = aug.augment_image(base_img)
assert np.array_equal(img_observed, img_expected)
示例15: test_augment_images__different_hue_and_saturation__per_channel
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import AddToHueAndSaturation [as 别名]
def test_augment_images__different_hue_and_saturation__per_channel(self):
base_img = self.create_base_image()
class _DummyParam(iap.StochasticParameter):
def _draw_samples(self, size, random_state):
arr = np.float32([10, 20])
return np.tile(arr[np.newaxis, :], (size[0], 1))
aug = iaa.AddToHueAndSaturation(value=_DummyParam(), per_channel=True)
img_expected = self._add_hue_saturation(
base_img, value_hue=10, value_saturation=20)
img_observed = aug.augment_image(base_img)
assert np.array_equal(img_observed, img_expected)