本文整理汇总了Python中imgaug.augmenters.MotionBlur方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.MotionBlur方法的具体用法?Python augmenters.MotionBlur怎么用?Python augmenters.MotionBlur使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.MotionBlur方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_augmentation_aug_non_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def _load_augmentation_aug_non_geometric():
return iaa.Sequential([
iaa.Sometimes(0.3, iaa.Multiply((0.5, 1.5), per_channel=0.5)),
iaa.Sometimes(0.2, iaa.JpegCompression(compression=(70, 99))),
iaa.Sometimes(0.2, iaa.GaussianBlur(sigma=(0, 3.0))),
iaa.Sometimes(0.2, iaa.MotionBlur(k=15, angle=[-45, 45])),
iaa.Sometimes(0.2, iaa.MultiplyHue((0.5, 1.5))),
iaa.Sometimes(0.2, iaa.MultiplySaturation((0.5, 1.5))),
iaa.Sometimes(0.34, iaa.MultiplyHueAndSaturation((0.5, 1.5),
per_channel=True)),
iaa.Sometimes(0.34, iaa.Grayscale(alpha=(0.0, 1.0))),
iaa.Sometimes(0.2, iaa.ChangeColorTemperature((1100, 10000))),
iaa.Sometimes(0.1, iaa.GammaContrast((0.5, 2.0))),
iaa.Sometimes(0.2, iaa.SigmoidContrast(gain=(3, 10),
cutoff=(0.4, 0.6))),
iaa.Sometimes(0.1, iaa.CLAHE()),
iaa.Sometimes(0.1, iaa.HistogramEqualization()),
iaa.Sometimes(0.2, iaa.LinearContrast((0.5, 2.0), per_channel=0.5)),
iaa.Sometimes(0.1, iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)))
])
示例2: test_simple_parameters
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_simple_parameters(self):
# simple scenario
aug = iaa.MotionBlur(k=3, angle=0, direction=0.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(10)
]
expected = np.float32([
[0, 1.0/3, 0],
[0, 1.0/3, 0],
[0, 1.0/3, 0]
])
for matrices_image in matrices:
for matrix_channel in matrices_image:
assert np.allclose(matrix_channel, expected)
示例3: test_simple_parameters_angle_is_90
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_simple_parameters_angle_is_90(self):
# 90deg angle
aug = iaa.MotionBlur(k=3, angle=90, direction=0.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(10)
]
expected = np.float32([
[0, 0, 0],
[1.0/3, 1.0/3, 1.0/3],
[0, 0, 0]
])
for matrices_image in matrices:
for matrix_channel in matrices_image:
assert np.allclose(matrix_channel, expected)
示例4: test_simple_parameters_angle_is_45
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_simple_parameters_angle_is_45(self):
# 45deg angle
aug = iaa.MotionBlur(k=3, angle=45, direction=0.0, order=0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(10)
]
expected = np.float32([
[0, 0, 1.0/3],
[0, 1.0/3, 0],
[1.0/3, 0, 0]
])
for matrices_image in matrices:
for matrix_channel in matrices_image:
assert np.allclose(matrix_channel, expected)
示例5: test_direction_is_1
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_direction_is_1(self):
# direction 1.0
aug = iaa.MotionBlur(k=3, angle=0, direction=1.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(10)
]
expected = np.float32([
[0, 1.0/1.5, 0],
[0, 0.5/1.5, 0],
[0, 0.0/1.5, 0]
])
for matrices_image in matrices:
for matrix_channel in matrices_image:
assert np.allclose(matrix_channel, expected, rtol=0, atol=1e-2)
示例6: test_direction_is_minus_1
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_direction_is_minus_1(self):
# direction -1.0
aug = iaa.MotionBlur(k=3, angle=0, direction=-1.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(10)
]
expected = np.float32([
[0, 0.0/1.5, 0],
[0, 0.5/1.5, 0],
[0, 1.0/1.5, 0]
])
for matrices_image in matrices:
for matrix_channel in matrices_image:
assert np.allclose(matrix_channel, expected, rtol=0, atol=1e-2)
示例7: test_k_is_3_angle_is_90_verify_results
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_k_is_3_angle_is_90_verify_results(self):
# test of actual augmenter
img = np.zeros((7, 7, 3), dtype=np.uint8)
img[3-1:3+2, 3-1:3+2, :] = 255
aug = iaa.MotionBlur(k=3, angle=90, direction=0.0)
img_aug = aug.augment_image(img)
v1 = (255*(1/3))
v2 = (255*(1/3)) * 2
v3 = (255*(1/3)) * 3
expected = np.float32([
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, v1, v2, v3, v2, v1, 0],
[0, v1, v2, v3, v2, v1, 0],
[0, v1, v2, v3, v2, v1, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]
]).astype(np.uint8)
expected = np.tile(expected[..., np.newaxis], (1, 1, 3))
assert np.allclose(img_aug, expected)
示例8: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def main():
image = ia.data.quokka(0.5)
height, width = image.shape[0], image.shape[1]
center_x = width // 2
center_y = height // 2
r = int(min(image.shape[0], image.shape[1]) / 3)
cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
cv2.imshow("aug", image[:, :, ::-1])
cv2.waitKey(TIME_PER_STEP)
for angle in cycle(np.arange(0, 360, DEG_PER_STEP)):
rad = np.deg2rad(angle-90)
point_x = int(center_x + r * np.cos(rad))
point_y = int(center_y + r * np.sin(rad))
aug = iaa.MotionBlur(k=35, angle=angle, direction=-1.0)
img_aug = aug.augment_image(image)
img_aug[
point_y-POINT_SIZE:point_y+POINT_SIZE+1,
point_x-POINT_SIZE:point_x+POINT_SIZE+1,
:] = np.array([0, 255, 0])
aug_inv = iaa.MotionBlur(k=35, angle=angle, direction=1.0)
img_aug_inv = aug_inv.augment_image(image)
img_aug_inv[
point_y - POINT_SIZE:point_y + POINT_SIZE + 1,
point_x - POINT_SIZE:point_x + POINT_SIZE + 1,
:] = np.array([0, 255, 0])
cv2.imshow("aug", np.hstack([img_aug[:, :, ::-1], img_aug_inv[:, :, ::-1]]))
cv2.waitKey(TIME_PER_STEP)
示例9: test_simple_parameters_angle_is_list
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_simple_parameters_angle_is_list(self):
# random angle
aug = iaa.MotionBlur(k=3, angle=[0, 90], direction=0.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(50)
]
expected1 = np.float32([
[0, 1.0/3, 0],
[0, 1.0/3, 0],
[0, 1.0/3, 0]
])
expected2 = np.float32([
[0, 0, 0],
[1.0/3, 1.0/3, 1.0/3],
[0, 0, 0],
])
nb_seen = [0, 0]
for matrices_image in matrices:
assert np.allclose(matrices_image[0], matrices_image[1])
assert np.allclose(matrices_image[1], matrices_image[2])
for matrix_channel in matrices_image:
if np.allclose(matrix_channel, expected1):
nb_seen[0] += 1
elif np.allclose(matrix_channel, expected2):
nb_seen[1] += 1
assert nb_seen[0] > 0
assert nb_seen[1] > 0
示例10: test_k_is_list_angle_90
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_k_is_list_angle_90(self):
# random k
aug = iaa.MotionBlur(k=[3, 5], angle=90, direction=0.0)
matrix_func = aug.matrix
matrices = [
matrix_func(
np.zeros((128, 128, 3), dtype=np.uint8),
3,
iarandom.RNG(i)
) for i in range(50)
]
expected1 = np.float32([
[0, 0, 0],
[1.0/3, 1.0/3, 1.0/3],
[0, 0, 0],
])
expected2 = np.float32([
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[1.0/5, 1.0/5, 1.0/5, 1.0/5, 1.0/5],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
])
nb_seen = [0, 0]
for matrices_image in matrices:
assert np.allclose(matrices_image[0], matrices_image[1])
assert np.allclose(matrices_image[1], matrices_image[2])
for matrix_channel in matrices_image:
if (matrix_channel.shape == expected1.shape
and np.allclose(matrix_channel, expected1)):
nb_seen[0] += 1
elif (matrix_channel.shape == expected2.shape
and np.allclose(matrix_channel, expected2)):
nb_seen[1] += 1
assert nb_seen[0] > 0
assert nb_seen[1] > 0
示例11: test_failure_on_continuous_kernel_sizes
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_failure_on_continuous_kernel_sizes(self):
# k with choice [a, b, c, ...] must error in case of non-discrete
# values
got_exception = False
try:
_ = iaa.MotionBlur(k=[3, 3.5, 4])
except Exception as exc:
assert "to only contain integer" in str(exc)
got_exception = True
assert got_exception
# TODO extend this to test sampled kernel sizes
示例12: test_k_is_tuple
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_k_is_tuple(self):
# no error in case of (a, b), checks for #215
aug = iaa.MotionBlur(k=(3, 7))
for _ in range(10):
_ = aug.augment_image(np.zeros((11, 11, 3), dtype=np.uint8))
示例13: test_pickleable
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def test_pickleable(self):
aug = iaa.MotionBlur((3, 11), seed=1)
runtest_pickleable_uint8_img(aug, iterations=10)
示例14: random_motion_blur
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def random_motion_blur(image, prob=.1):
"""
Random add motion blur on image
# Arguments
image: origin image for motion blur
PIL Image object containing image data
prob: probability for blur,
scalar to control the blur probability.
# Returns
image: adjusted PIL Image object.
"""
motion_blur = rand() < prob
if motion_blur:
img = np.array(image)
# random blur severity from 1 to 5
severity = np.random.randint(1, 6)
seq = iaa.Sequential([iaa.imgcorruptlike.MotionBlur(severity=severity)])
#seq = iaa.Sequential([iaa.MotionBlur(k=30)])
img = seq(images=np.expand_dims(img, 0))
image = Image.fromarray(img[0])
return image
示例15: build_augmentation_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MotionBlur [as 别名]
def build_augmentation_pipeline(self, height=None, width=None, apply_prob=0.5):
sometimes = lambda aug: iaa.Sometimes(apply_prob, aug)
pipeline = iaa.Sequential(random_order=False)
cfg = self.cfg
if cfg.get("fliplr", False):
opt = cfg.get("fliplr", False)
if type(opt) == int:
pipeline.add(sometimes(iaa.Fliplr(opt)))
else:
pipeline.add(sometimes(iaa.Fliplr(0.5)))
if cfg.get("rotation", False):
opt = cfg.get("rotation", False)
if type(opt) == int:
pipeline.add(sometimes(iaa.Affine(rotate=(-opt, opt))))
else:
pipeline.add(sometimes(iaa.Affine(rotate=(-10, 10))))
if cfg.get("hist_eq", False):
pipeline.add(sometimes(iaa.AllChannelsHistogramEqualization()))
if cfg.get("motion_blur", False):
opts = cfg.get("motion_blur", False)
if type(opts) == list:
opts = dict(opts)
pipeline.add(sometimes(iaa.MotionBlur(**opts)))
else:
pipeline.add(sometimes(iaa.MotionBlur(k=7, angle=(-90, 90))))
if cfg.get("covering", False):
pipeline.add(
sometimes(iaa.CoarseDropout((0, 0.02), size_percent=(0.01, 0.05)))
) # , per_channel=0.5)))
if cfg.get("elastic_transform", False):
pipeline.add(sometimes(iaa.ElasticTransformation(sigma=5)))
if cfg.get("gaussian_noise", False):
opt = cfg.get("gaussian_noise", False)
if type(opt) == int or type(opt) == float:
pipeline.add(
sometimes(
iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, opt), per_channel=0.5
)
)
)
else:
pipeline.add(
sometimes(
iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, 0.05 * 255), per_channel=0.5
)
)
)
if height is not None and width is not None:
pipeline.add(
iaa.Sometimes(
cfg.cropratio, iaa.CropAndPad(percent=(-0.3, 0.1), keep_size=False)
)
)
pipeline.add(iaa.Resize({"height": height, "width": width}))
return pipeline