Python torchvision.transforms.functional.affine() Examples
The following are 30
code examples of torchvision.transforms.functional.affine().
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
torchvision.transforms.functional
, or try the search function
.
Example #1
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #2
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #3
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #4
Source File: cvfunctional.py From opencv_transforms_torchvision with MIT License | 6 votes |
def pil_transform(img): # img = functional.resize(img, size=(100, 300)) # img = functional.to_tensor(img) # img = functional.normalize(img, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # img = functional.pad(img, padding=(10, 10, 20, 20), fill=(255, 255, 255), padding_mode='constant') # img = functional.pad(img, padding=(100, 100, 100, 100), padding_mode='symmetric') # img = functional.crop(img, -40, -20, 1000, 1000) # img = functional.center_crop(img, (310, 300)) # img = functional.resized_crop(img, -10.3, -20, 330, 220, (500, 500)) # img = functional.hflip(img) # img = functional.vflip(img) # tl, tr, bl, br, center = functional.five_crop(img, 100) # img = functional.adjust_brightness(img, 2.1) # img = functional.adjust_contrast(img, 1.5) # img = functional.adjust_saturation(img, 2.3) # img = functional.adjust_hue(img, 0.5) # img = functional.adjust_gamma(img, gamma=3, gain=0.1) # img = functional.rotate(img, 10, resample=PIL.Image.BILINEAR, expand=True, center=None) # img = functional.to_grayscale(img, 3) # img = functional.affine(img, 10, (0, 0), 1, 0, resample=PIL.Image.BICUBIC, fillcolor=(255,255,0)) return functional.to_tensor(img)
Example #5
Source File: augmentations.py From CAG_UDA with MIT License | 6 votes |
def __call__(self, img, mask): rotate_degree = random.random() * 2 * self.degree - self.degree return ( tf.affine(img, translate=(0, 0), scale=1.0, angle=rotate_degree, resample=Image.BILINEAR, fillcolor=(0, 0, 0), shear=0.0), tf.affine(mask, translate=(0, 0), scale=1.0, angle=rotate_degree, resample=Image.NEAREST, fillcolor=250, shear=0.0))
Example #6
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #7
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #8
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #9
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #10
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #11
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #12
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #13
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #14
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #15
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #16
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #17
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #18
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #19
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #20
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #21
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #22
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #23
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #24
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #25
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #26
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #27
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #28
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #29
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear
Example #30
Source File: transforms.py From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License | 6 votes |
def get_params(degrees, translate, scale_ranges, shears, img_size): """Get parameters for affine transformation Returns: sequence: params to be passed to the affine transformation """ angle = np.random.uniform(degrees[0], degrees[1]) if translate is not None: max_dx = translate[0] * img_size[0] max_dy = translate[1] * img_size[1] translations = (np.round(np.random.uniform(-max_dx, max_dx)), np.round(np.random.uniform(-max_dy, max_dy))) else: translations = (0, 0) if scale_ranges is not None: scale = np.random.uniform(scale_ranges[0], scale_ranges[1]) else: scale = 1.0 if shears is not None: shear = np.random.uniform(shears[0], shears[1]) else: shear = 0.0 return angle, translations, scale, shear