Resize an image with CVCUDA.
()
| 29 | |
| 30 | |
| 31 | def main() -> None: |
| 32 | """Resize an image with CVCUDA.""" |
| 33 | # docs_tag: begin_main |
| 34 | args: argparse.Namespace = parse_image_args("cat_resized.jpg") |
| 35 | # docs_tag: begin_read_image |
| 36 | input_image: cvcuda.Tensor = read_image(args.input) |
| 37 | # docs_tag: end_read_image |
| 38 | |
| 39 | # docs_tag: begin_resize |
| 40 | # 1. Resize the image to the specified width and height |
| 41 | # Since the image gets read as HWC format, |
| 42 | # we need to have the same number of dimensions in the output shape |
| 43 | # i.e. (height, width, 3) |
| 44 | output_image: cvcuda.Tensor = cvcuda.resize( |
| 45 | input_image, (args.height, args.width, 3) |
| 46 | ) |
| 47 | write_image(output_image, args.output) |
| 48 | |
| 49 | # 2. If we have a batch dimension, we can still resize the image |
| 50 | batched_image: cvcuda.Tensor = input_image.reshape((1, *input_image.shape), "NHWC") |
| 51 | batched_output_image: cvcuda.Tensor = cvcuda.resize( |
| 52 | batched_image, (1, args.height, args.width, 3) |
| 53 | ) |
| 54 | assert batched_output_image.shape == (1, args.height, args.width, 3) |
| 55 | # docs_tag: end_resize |
| 56 | # docs_tag: end_main |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |
no test coverage detected