本文整理汇总了Python中imgaug.augmenters.MedianBlur方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.MedianBlur方法的具体用法?Python augmenters.MedianBlur怎么用?Python augmenters.MedianBlur使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.MedianBlur方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zero_sized_axes
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_zero_sized_axes(self):
shapes = [
(0, 0),
(0, 1),
(1, 0),
(0, 1, 0),
(1, 0, 0),
(0, 1, 1),
(1, 0, 1)
]
for shape in shapes:
with self.subTest(shape=shape):
image = np.zeros(shape, dtype=np.uint8)
image_aug = iaa.MedianBlur(k=3)(image=image)
assert image_aug.shape == image.shape
示例2: __init__
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [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)
示例3: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def main():
image = data.astronaut()
image = ia.imresize_single_image(image, (64, 64))
print("image shape:", image.shape)
print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,))
k = [
1,
3,
5,
7,
(3, 3),
(1, 11)
]
cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64)
for ki in k:
aug = iaa.MedianBlur(k=ki)
img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)]
img_aug = np.hstack(img_aug)
print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1))))
title = "k=%s" % (str(ki),)
img_aug = ia.draw_text(img_aug, x=5, y=5, text=title)
cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr
cv2.waitKey(TIME_PER_STEP)
示例4: test_k_is_1
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_k_is_1(self):
# no blur, shouldnt change anything
aug = iaa.MedianBlur(k=1)
observed = aug.augment_image(self.base_img)
assert np.array_equal(observed, self.base_img)
示例5: test_k_is_3
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_k_is_3(self):
# k=3
aug = iaa.MedianBlur(k=3)
observed = aug.augment_image(self.base_img)
assert np.array_equal(observed, self.blur3x3)
示例6: test_k_is_5
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_k_is_5(self):
# k=5
aug = iaa.MedianBlur(k=5)
observed = aug.augment_image(self.base_img)
assert np.array_equal(observed, self.blur5x5)
示例7: test_k_is_tuple
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_k_is_tuple(self):
# k as (3, 5)
aug = iaa.MedianBlur(k=(3, 5))
seen = [False, False]
for i in sm.xrange(100):
observed = aug.augment_image(self.base_img)
if np.array_equal(observed, self.blur3x3):
seen[0] = True
elif np.array_equal(observed, self.blur5x5):
seen[1] = True
else:
raise Exception("Unexpected result in MedianBlur@1")
if all(seen):
break
assert np.all(seen)
示例8: test_more_than_four_channels
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_more_than_four_channels(self):
shapes = [
(1, 1, 4),
(1, 1, 5),
(1, 1, 512),
(1, 1, 513)
]
for shape in shapes:
with self.subTest(shape=shape):
image = np.zeros(shape, dtype=np.uint8)
image_aug = iaa.MedianBlur(k=3)(image=image)
assert image_aug.shape == image.shape
示例9: test_keypoints_not_changed
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_keypoints_not_changed(self):
kps = [ia.Keypoint(x=0, y=0), ia.Keypoint(x=1, y=1),
ia.Keypoint(x=2, y=2)]
kpsoi = [ia.KeypointsOnImage(kps, shape=(11, 11, 1))]
aug = iaa.MedianBlur(k=3)
aug_det = aug.to_deterministic()
observed = aug.augment_keypoints(kpsoi)
expected = kpsoi
assert keypoints_equal(observed, expected)
observed = aug_det.augment_keypoints(kpsoi)
expected = kpsoi
assert keypoints_equal(observed, expected)
示例10: test_pickleable
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def test_pickleable(self):
aug = iaa.MedianBlur((1, 11), seed=1)
runtest_pickleable_uint8_img(aug, iterations=10)
# TODO extend these tests
示例11: main
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def main():
image = data.astronaut()
image = ia.imresize_single_image(image, (64, 64))
print("image shape:", image.shape)
print("Press any key or wait %d ms to proceed to the next image." % (TIME_PER_STEP,))
k = [
1,
3,
5,
7,
(3, 3),
(1, 11)
]
cv2.namedWindow("aug", cv2.WINDOW_NORMAL)
cv2.resizeWindow("aug", 64*NB_AUGS_PER_IMAGE, 64)
#cv2.imshow("aug", image[..., ::-1])
#cv2.waitKey(TIME_PER_STEP)
for ki in k:
aug = iaa.MedianBlur(k=ki)
img_aug = [aug.augment_image(image) for _ in range(NB_AUGS_PER_IMAGE)]
img_aug = np.hstack(img_aug)
print("dtype", img_aug.dtype, "averages", np.average(img_aug, axis=tuple(range(0, img_aug.ndim-1))))
#print("dtype", img_aug.dtype, "averages", img_aug.mean(axis=range(1, img_aug.ndim)))
title = "k=%s" % (str(ki),)
img_aug = ia.draw_text(img_aug, x=5, y=5, text=title)
cv2.imshow("aug", img_aug[..., ::-1]) # here with rgb2bgr
cv2.waitKey(TIME_PER_STEP)
示例12: chapter_augmenters_medianblur
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def chapter_augmenters_medianblur():
aug = iaa.MedianBlur(k=(3, 11))
run_and_save_augseq(
"medianblur.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(16)], cols=4, rows=4,
quality=75
)
# median doesnt support this
#aug = iaa.MedianBlur(k=((5, 11), (1, 3)))
#run_and_save_augseq(
# "medianblur_mixed.jpg", aug,
# [ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2,
# quality=75
#)
示例13: _create_augment_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def _create_augment_pipeline():
from imgaug import augmenters as iaa
### augmentors by https://github.com/aleju/imgaug
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
aug_pipe = iaa.Sequential(
[
# apply the following augmenters to most images
#iaa.Fliplr(0.5), # horizontally flip 50% of all images
#iaa.Flipud(0.2), # vertically flip 20% of all images
#sometimes(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/width
sometimes(iaa.Affine(
#scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
#translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)}, # translate by -20 to +20 percent (per axis)
#rotate=(-5, 5), # rotate by -45 to +45 degrees
#shear=(-5, 5), # shear by -16 to +16 degrees
#order=[0, 1], # use nearest neighbour or bilinear interpolation (fast)
#cval=(0, 255), # if mode is constant, use a cval between 0 and 255
#mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)),
# execute 0 to 5 of the following (less important) augmenters per image
# don't execute all of them, as that would often be way too strong
iaa.SomeOf((0, 5),
[
#sometimes(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representation
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.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)), # sharpen images
#iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)), # emboss images
# search either for all edges or for directed edges
#sometimes(iaa.OneOf([
# iaa.EdgeDetect(alpha=(0, 0.7)),
# iaa.DirectedEdgeDetect(alpha=(0, 0.7), direction=(0.0, 1.0)),
#])),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5), # add gaussian noise to images
iaa.OneOf([
iaa.Dropout((0.01, 0.1), per_channel=0.5), # randomly remove up to 10% of the pixels
#iaa.CoarseDropout((0.03, 0.15), size_percent=(0.02, 0.05), per_channel=0.2),
]),
#iaa.Invert(0.05, per_channel=True), # invert color channels
iaa.Add((-10, 10), per_channel=0.5), # change brightness of images (by -10 to 10 of original value)
iaa.Multiply((0.5, 1.5), per_channel=0.5), # change brightness of images (50-150% of original value)
iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5), # improve or worsen the contrast
#iaa.Grayscale(alpha=(0.0, 1.0)),
#sometimes(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)), # move pixels locally around (with random strengths)
#sometimes(iaa.PiecewiseAffine(scale=(0.01, 0.05))) # sometimes move parts of the image around
],
random_order=True
)
],
random_order=True
)
return aug_pipe
示例14: get_augmentations
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import MedianBlur [as 别名]
def get_augmentations():
# applies the given augmenter in 50% of all cases,
sometimes = lambda aug: iaa.Sometimes(0.5, aug)
# Define our sequence of augmentation steps that will be applied to every image
seq = iaa.Sequential([
# execute 0 to 5 of the following (less important) augmenters per image
iaa.SomeOf((0, 5),
[
iaa.OneOf([
iaa.GaussianBlur((0, 3.0)),
iaa.AverageBlur(k=(2, 7)),
iaa.MedianBlur(k=(3, 11)),
]),
iaa.Sharpen(alpha=(0, 1.0), lightness=(0.75, 1.5)),
iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0)),
# search either for all edges or for directed edges,
# blend the result with the original image using a blobby mask
iaa.SimplexNoiseAlpha(iaa.OneOf([
iaa.EdgeDetect(alpha=(0.5, 1.0)),
iaa.DirectedEdgeDetect(alpha=(0.5, 1.0), direction=(0.0, 1.0)),
])),
iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.05*255), per_channel=0.5),
iaa.OneOf([
iaa.Dropout((0.01, 0.1), per_channel=0.5), # randomly remove up to 10% of the pixels
iaa.CoarseDropout((0.03, 0.15), size_percent=(0.02, 0.05), per_channel=0.2),
]),
iaa.Add((-10, 10), per_channel=0.5), # change brightness of images (by -10 to 10 of original value)
iaa.AddToHueAndSaturation((-20, 20)), # change hue and saturation
# either change the brightness of the whole image (sometimes
# per channel) or change the brightness of subareas
iaa.OneOf([
iaa.Multiply((0.5, 1.5), per_channel=0.5),
iaa.FrequencyNoiseAlpha(
exponent=(-4, 0),
first=iaa.Multiply((0.5, 1.5), per_channel=True),
second=iaa.ContrastNormalization((0.5, 2.0))
)
]),
iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5), # improve or worsen the contrast
sometimes(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)), # move pixels locally around (with random strengths)
],
random_order=True
)
],
random_order=True
)
return seq
### data transforms