本文整理汇总了Python中keras_preprocessing.image.apply_affine_transform方法的典型用法代码示例。如果您正苦于以下问题:Python image.apply_affine_transform方法的具体用法?Python image.apply_affine_transform怎么用?Python image.apply_affine_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keras_preprocessing.image
的用法示例。
在下文中一共展示了image.apply_affine_transform方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: random_zoom
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def random_zoom(image, label, zoom_range):
if np.ndim(label) == 2:
label = np.expand_dims(label, axis=-1)
assert np.ndim(label) == 3
if np.isscalar(zoom_range):
zx, zy = np.random.uniform(1 - zoom_range, 1 + zoom_range, 2)
elif len(zoom_range) == 2:
zx, zy = np.random.uniform(zoom_range[0], zoom_range[1], 2)
else:
raise ValueError('`zoom_range` should be a float or '
'a tuple or list of two floats. '
'Received: %s' % (zoom_range,))
image = keras_image.apply_affine_transform(image, zx=zx, zy=zy, fill_mode='nearest')
label = keras_image.apply_affine_transform(label, zx=zx, zy=zy, fill_mode='nearest')
return image, label
示例2: random_rotate
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def random_rotate(img, mask, rotate_limit=(-20, 20), u=0.5):
if np.random.random() < u:
theta = np.random.uniform(rotate_limit[0], rotate_limit[1])
img = image.apply_affine_transform(img, theta=theta)
mask = image.apply_affine_transform(mask, theta=theta)
return img, mask
示例3: shift
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def shift(x, wshift, hshift, row_axis=0, col_axis=1, channel_axis=2, fill_mode='nearest', cval=0.):
h, w = x.shape[row_axis], x.shape[col_axis]
tx = hshift * h
ty = wshift * w
x = image.apply_affine_transform(x, ty=ty, tx=tx)
return x
示例4: random_zoom
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def random_zoom(img, mask, zoom_range=(0.8, 1), u=0.5):
if np.random.random() < u:
zx, zy = np.random.uniform(zoom_range[0], zoom_range[1], 2)
img = image.apply_affine_transform(img, zx=zx, zy=zy)
mask = image.apply_affine_transform(mask, zx=zx, zy=zy)
return img, mask
示例5: random_shear
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def random_shear(img, mask, intensity_range=(-0.5, 0.5), u=0.5):
if np.random.random() < u:
sh = np.random.uniform(-intensity_range[0], intensity_range[1])
img = image.apply_affine_transform(img, shear=sh)
mask = image.apply_affine_transform(mask, shear=sh)
return img, mask
示例6: random_rotation
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def random_rotation(image, label, rotation_range):
if np.ndim(label) == 2:
label = np.expand_dims(label, axis=-1)
assert np.ndim(label) == 3
if rotation_range > 0.:
theta = np.random.uniform(-rotation_range, rotation_range)
# rotate it!
image = keras_image.apply_affine_transform(image, theta=theta, fill_mode='nearest')
label = keras_image.apply_affine_transform(label, theta=theta, fill_mode='nearest')
return image, label
示例7: keras
# 需要导入模块: from keras_preprocessing import image [as 别名]
# 或者: from keras_preprocessing.image import apply_affine_transform [as 别名]
def keras(self, img):
img = keras.apply_affine_transform(img, theta=45, channel_axis=2, fill_mode="reflect")
return np.ascontiguousarray(img)