def _get_pad(self, image: np.ndarray) -> Transform: # Compute the image scale and scaled size. input_size = image.shape[:2] output_size = self.crop_size # Add padding if the image is scaled down. pad_size = np.subtract(output_size, input_size) pad_size = np.maximum(pad_size, 0) original_size = np.minimum(input_size, output_size) return PadTransform(0, 0, pad_size[1], pad_size[0], original_size[1], original_size[0], self.pad_value)
def get_transform(self, image: np.ndarray) -> TransformList: # Compute the image scale and scaled size. input_size = image.shape[:2] output_size = self.crop_size # Add random crop if the image is scaled up. max_offset = np.subtract(input_size, output_size) max_offset = np.maximum(max_offset, 0) offset = np.multiply(max_offset, np.random.uniform(0.0, 1.0)) offset = np.round(offset).astype(int) crop_transform = CropTransform(offset[1], offset[0], output_size[1], output_size[0], input_size[1], input_size[0]) # Add padding if the image is scaled down. pad_size = np.subtract(output_size, input_size) pad_size = np.maximum(pad_size, 0) original_size = np.minimum(input_size, output_size) pad_transform = PadTransform(0, 0, pad_size[1], pad_size[0], original_size[1], original_size[0], self.pad_value) return TransformList([crop_transform, pad_transform])