Resize the image.
| 102 | |
| 103 | |
| 104 | class ResizeTransform(Transform): |
| 105 | """ |
| 106 | Resize the image. |
| 107 | """ |
| 108 | def __init__(self, h, w, new_h, new_w, interp): |
| 109 | """ |
| 110 | Args: |
| 111 | h, w (int): |
| 112 | new_h, new_w (int): |
| 113 | interp (int): cv2 interpolation method |
| 114 | """ |
| 115 | super(ResizeTransform, self).__init__() |
| 116 | self._init(locals()) |
| 117 | |
| 118 | def apply_image(self, img): |
| 119 | assert img.shape[:2] == (self.h, self.w) |
| 120 | ret = cv2.resize( |
| 121 | img, (self.new_w, self.new_h), |
| 122 | interpolation=self.interp) |
| 123 | if img.ndim == 3 and ret.ndim == 2: |
| 124 | ret = ret[:, :, np.newaxis] |
| 125 | return ret |
| 126 | |
| 127 | def apply_coords(self, coords): |
| 128 | coords[:, 0] = coords[:, 0] * (self.new_w * 1.0 / self.w) |
| 129 | coords[:, 1] = coords[:, 1] * (self.new_h * 1.0 / self.h) |
| 130 | return coords |
| 131 | |
| 132 | |
| 133 | class CropTransform(Transform): |
no outgoing calls
no test coverage detected