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 ¶
AspectAwarePreprocessor(width, height, inter=cv2.INTER_AREA)
Class to resize an image to a certain width and height taking into account the image aspect ratio
Parameters:
-
width
(int
) –output width
-
height
(int
) –output height
-
inter
–opencv
interpolation method. Seeopencv
InterpolationFlags
.
Source code in pytorch_widedeep/utils/image_utils.py
32 33 34 35 |
|
preprocess ¶
preprocess(image)
Returns the resized input image taking into account the image aspect ratio
Parameters:
-
image
(ndarray
) –Input image to be resized
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:
-
ndarray
–Resized image according to its original image aspect ratio
Source code in pytorch_widedeep/utils/image_utils.py
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 |
|
SimplePreprocessor ¶
SimplePreprocessor(width, height, inter=cv2.INTER_AREA)
Class to resize an image to a certain width and height
Parameters:
-
width
(int
) –output width
-
height
(int
) –output height
-
inter
–opencv
interpolation method. Seeopencv
InterpolationFlags
.
Source code in pytorch_widedeep/utils/image_utils.py
97 98 99 100 |
|
preprocess ¶
preprocess(image)
Returns the resized input image
Parameters:
-
image
(ndarray
) –Input image to be resized
Returns:
-
ndarray
–Resized image
Source code in pytorch_widedeep/utils/image_utils.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|