Python keras_preprocessing.image.apply_affine_transform() Examples
The following are 12
code examples of keras_preprocessing.image.apply_affine_transform().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
keras_preprocessing.image
, or try the search function
.

Example #1
Source File: utils.py From Amazing-Semantic-Segmentation with Apache License 2.0 | 6 votes |
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
Example #2
Source File: aug_utils.py From medical_image_segmentation with MIT License | 5 votes |
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
Example #3
Source File: aug_utils.py From medical_image_segmentation with MIT License | 5 votes |
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
Example #4
Source File: aug_utils.py From medical_image_segmentation with MIT License | 5 votes |
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
Example #5
Source File: aug_utils.py From medical_image_segmentation with MIT License | 5 votes |
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
Example #6
Source File: utils.py From Amazing-Semantic-Segmentation with Apache License 2.0 | 5 votes |
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
Example #7
Source File: data_augmentation.py From IterNet with MIT License | 5 votes |
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
Example #8
Source File: data_augmentation.py From IterNet with MIT License | 5 votes |
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
Example #9
Source File: data_augmentation.py From IterNet with MIT License | 5 votes |
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
Example #10
Source File: data_augmentation.py From IterNet with MIT License | 5 votes |
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
Example #11
Source File: benchmark.py From albumentations with MIT License | 5 votes |
def keras(self, img): img = keras.apply_affine_transform(img, theta=45, channel_axis=2, fill_mode="reflect") return np.ascontiguousarray(img)
Example #12
Source File: benchmark.py From albumentations with MIT License | 5 votes |
def keras(self, img): img = keras.apply_affine_transform(img, theta=45, tx=50, ty=50, zx=0.5, zy=0.5, fill_mode="reflect") return np.ascontiguousarray(img)