Open roey1rg opened 5 years ago
A tuple is expected to be of form (a, b)
and interpreted as the bounds of a uniform distribution. The RGB value will then be generated per image by sampling three values independently from uniform(a, b)
. E.g. (10, 30)
may result in RGB (15, 25, 17)
, but not in (10, 10, 255)
.
I think there is currently no predefined way to provide a constant RGB color, you can only provide a single integer value as the intensity, e.g. cval=255
will always sample RGB (255, 255, 255)
. However, you can rather easily create your own parameter which returns full RGB colors:
import numpy as np
import imgaug as ia
from imgaug import augmenters as iaa
from imgaug import parameters as iap
class DeterministicColor(iap.StochasticParameter):
def __init__(self, color):
self.color = np.uint8(color)
def _draw_samples(self, size, random_state):
assert size[-1] == 3
arr = np.zeros(size, dtype=np.uint8)
arr[..., :] = self.color
return arr
aug = iaa.Affine(rotate=45,
cval=DeterministicColor([0, 0, 255]),
mode="constant")
image_aug = aug.augment_image(ia.quokka(size=(128, 128)))
ia.imshow(image_aug)
Output:
Thanks a lot! Just wanted to share that I'm making affine augmentations to pictures taken with green screen as a background so it's quite necessary in my scenario.
A tuple is expected to be of form
(a, b)
and interpreted as the bounds of a uniform distribution. The RGB value will then be generated per image by sampling three values independently fromuniform(a, b)
. E.g.(10, 30)
may result in RGB(15, 25, 17)
, but not in(10, 10, 255)
.I think there is currently no predefined way to provide a constant RGB color, you can only provide a single integer value as the intensity, e.g.
cval=255
will always sample RGB(255, 255, 255)
. However, you can rather easily create your own parameter which returns full RGB colors:import numpy as np import imgaug as ia from imgaug import augmenters as iaa from imgaug import parameters as iap class DeterministicColor(iap.StochasticParameter): def __init__(self, color): self.color = np.uint8(color) def _draw_samples(self, size, random_state): assert size[-1] == 3 arr = np.zeros(size, dtype=np.uint8) arr[..., :] = self.color return arr aug = iaa.Affine(rotate=45, cval=DeterministicColor([0, 0, 255]), mode="constant") image_aug = aug.augment_image(ia.quokka(size=(128, 128))) ia.imshow(image_aug)
Output:
This is very interesting and very much needed. How should the DeterministicColor class be modified for Cutout augmenter?
from the documentation, the cval parameter is described as follows:
I read the comments from the following link: https://github.com/aleju/imgaug/blob/master/imgaug/augmenters/geometric.py (line 375)
so from the paragraph above I understand that it is possible to insert RGB value to the cval parameter if backend = 'cv2' is used, but I receive dimensions error.
here is the code I use:
seq = iaa.Sequential([iaa.Affine(rotate=30,cval=(0,0,255), backend='cv2')])
seq_det = seq.to_deterministic()
new_image = seq_det.augment_image(image)
and here is the error message:
Thank you friends