Image utils¶
SimplePreprocessor and
AspectAwarePreprocessor are directly
taked from the great series of Books `Deep Learning for Computer Vision
by Adrian. Therefore, all credit for the
code in the image_utils
module goes to Adrian Rosebrock.
AspectAwarePreprocessor ¶
Class to resize an image to a certain width and height taking into account the image aspect ratio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
output width |
required |
height
|
int
|
output height |
required |
inter
|
|
INTER_AREA
|
Source code in pytorch_widedeep/utils/image_utils.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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
preprocess ¶
preprocess(image)
Returns the resized input image taking into account the image aspect ratio
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image to be resized |
required |
Examples:
>>> import cv2
>>> from pytorch_widedeep.utils import AspectAwarePreprocessor
>>> img = cv2.imread("tests/test_data_utils/images/galaxy1.png")
>>> img.shape
(694, 890, 3)
>>> app = AspectAwarePreprocessor(width=224, height=224)
>>> resized_img = app.preprocess(img)
>>> resized_img.shape
(224, 224, 3)
Returns:
Type | Description |
---|---|
ndarray
|
Resized image according to its original image aspect ratio |
Source code in pytorch_widedeep/utils/image_utils.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
|
SimplePreprocessor ¶
Class to resize an image to a certain width and height
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
output width |
required |
height
|
int
|
output height |
required |
inter
|
|
INTER_AREA
|
Source code in pytorch_widedeep/utils/image_utils.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|
preprocess ¶
preprocess(image)
Returns the resized input image
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
Input image to be resized |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Resized image |
Source code in pytorch_widedeep/utils/image_utils.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
|