本文整理汇总了Python中imgaug.augmenters.CropAndPad方法的典型用法代码示例。如果您正苦于以下问题:Python augmenters.CropAndPad方法的具体用法?Python augmenters.CropAndPad怎么用?Python augmenters.CropAndPad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug.augmenters
的用法示例。
在下文中一共展示了augmenters.CropAndPad方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_augmenter
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import CropAndPad [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([])
示例2: _load_augmentation_aug_geometric
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import CropAndPad [as 别名]
def _load_augmentation_aug_geometric():
return iaa.OneOf([
iaa.Sequential([iaa.Fliplr(0.5), iaa.Flipud(0.2)]),
iaa.CropAndPad(percent=(-0.05, 0.1),
pad_mode='constant',
pad_cval=(0, 255)),
iaa.Crop(percent=(0.0, 0.1)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Crop(percent=(0.3, 0.5)),
iaa.Sequential([
iaa.Affine(
# scale images to 80-120% of their size,
# individually per axis
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)},
# translate by -20 to +20 percent (per axis)
translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-16, 16), # shear by -16 to +16 degrees
# use nearest neighbour or bilinear interpolation (fast)
order=[0, 1],
# if mode is constant, use a cval between 0 and 255
mode='constant',
cval=(0, 255),
# use any of scikit-image's warping modes
# (see 2nd image from the top for examples)
),
iaa.Sometimes(0.3, iaa.Crop(percent=(0.3, 0.5)))])
])
示例3: chapter_augmenters_cropandpad
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import CropAndPad [as 别名]
def chapter_augmenters_cropandpad():
aug = iaa.CropAndPad(percent=(-0.25, 0.25))
run_and_save_augseq(
"cropandpad_percent.jpg", aug,
[ia.quokka(size=(128, 128)) for _ in range(8)], cols=4, rows=2
)
aug = iaa.CropAndPad(
percent=(0, 0.2),
pad_mode=["constant", "edge"],
pad_cval=(0, 128)
)
run_and_save_augseq(
"cropandpad_mode_cval.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
aug = iaa.CropAndPad(
px=((0, 30), (0, 10), (0, 30), (0, 10)),
pad_mode=ia.ALL,
pad_cval=(0, 128)
)
run_and_save_augseq(
"cropandpad_pad_complex.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(32)], cols=8, rows=4
)
aug = iaa.CropAndPad(
px=(-10, 10),
sample_independently=False
)
run_and_save_augseq(
"cropandpad_correlated.jpg", aug,
[ia.quokka(size=(64, 64)) for _ in range(16)], cols=8, rows=2
)
示例4: processor
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import CropAndPad [as 别名]
def processor(self):
return iaa.CropAndPad(self.px, self.percent, self.pad_mode, self.pad_cval, self.keep_size)
示例5: build_augmentation_pipeline
# 需要导入模块: from imgaug import augmenters [as 别名]
# 或者: from imgaug.augmenters import CropAndPad [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