Bases: Subfunction_Base
A Resize Subfunction class which resizes an images according to a desired shape.
2D image
Shape have to be defined as tuple with x and y size: Resize(shape=(224, 224))
Resizing is done via albumentations resize transform which uses bi-linear interpolation by default.
https://albumentations.ai/docs/api_reference/augmentations/geometric/resize/
3D volume
Shape has to be defined as tuple with x, y and z size: Resize(shape=(128, 128, 128))
Resizing is done via volumentations resize transform which uses bi-linear interpolation by default.
https://github.com/muellerdo/volumentations
Source code in aucmedi/data_processing/subfunctions/resize.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 | class Resize(Subfunction_Base):
""" A Resize Subfunction class which resizes an images according to a desired shape.
???+ info "2D image"
Shape have to be defined as tuple with x and y size: `Resize(shape=(224, 224))`
Resizing is done via albumentations resize transform which uses bi-linear interpolation by default. <br>
https://albumentations.ai/docs/api_reference/augmentations/geometric/resize/
???+ info "3D volume"
Shape has to be defined as tuple with x, y and z size: `Resize(shape=(128, 128, 128))`
Resizing is done via volumentations resize transform which uses bi-linear interpolation by default. <br>
https://github.com/muellerdo/volumentations
"""
#---------------------------------------------#
# Initialization #
#---------------------------------------------#
def __init__(self, shape=(224, 224), interpolation=1):
""" Initialization function for creating a Resize Subfunction which can be passed to a
[DataGenerator][aucmedi.data_processing.data_generator.DataGenerator].
Args:
shape (tuple of int): Resizing shape consisting of a X and Y size. (optional Z size for Volumes).
interpolation (int): Interpolation mode for resizing. Using encoding from cv2:
https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html
"""
# Initialize parameter
params = {"p":1.0, "always_apply":True, "interpolation":interpolation}
# Select augmentation module and add further parameter depending on dimension
if len(shape) == 2:
params["height"] = shape[0]
params["width"] = shape[1]
mod = albumentations
elif len(shape) == 3:
params["shape"] = shape
mod = volumentations
else : raise ValueError("Shape for Resize has to be 2D or 3D!", shape)
# Initialize resizing transform
self.aug_transform = mod.Compose([mod.Resize(**params)])
# Cache shape
self.shape = shape
#---------------------------------------------#
# Transformation #
#---------------------------------------------#
def transform(self, image):
# Perform resizing into desired shape
image_resized = self.aug_transform(image=image)["image"]
# Return resized image
return image_resized
|
__init__(shape=(224, 224), interpolation=1)
Initialization function for creating a Resize Subfunction which can be passed to a
DataGenerator.
Parameters:
Name |
Type |
Description |
Default |
shape |
tuple of int
|
Resizing shape consisting of a X and Y size. (optional Z size for Volumes). |
(224, 224)
|
interpolation |
int
|
Interpolation mode for resizing. Using encoding from cv2:
https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html |
1
|
Source code in aucmedi/data_processing/subfunctions/resize.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 | def __init__(self, shape=(224, 224), interpolation=1):
""" Initialization function for creating a Resize Subfunction which can be passed to a
[DataGenerator][aucmedi.data_processing.data_generator.DataGenerator].
Args:
shape (tuple of int): Resizing shape consisting of a X and Y size. (optional Z size for Volumes).
interpolation (int): Interpolation mode for resizing. Using encoding from cv2:
https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html
"""
# Initialize parameter
params = {"p":1.0, "always_apply":True, "interpolation":interpolation}
# Select augmentation module and add further parameter depending on dimension
if len(shape) == 2:
params["height"] = shape[0]
params["width"] = shape[1]
mod = albumentations
elif len(shape) == 3:
params["shape"] = shape
mod = volumentations
else : raise ValueError("Shape for Resize has to be 2D or 3D!", shape)
# Initialize resizing transform
self.aug_transform = mod.Compose([mod.Resize(**params)])
# Cache shape
self.shape = shape
|