| Total Complexity | 5 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # pylint: disable=import-outside-toplevel |
||
| 2 | from pathlib import Path |
||
| 3 | |||
| 4 | import typer |
||
| 5 | |||
| 6 | app = typer.Typer() |
||
| 7 | |||
| 8 | |||
| 9 | @app.command() |
||
| 10 | def main( |
||
| 11 | input_path: Path = typer.Argument( # noqa: B008 |
||
| 12 | ..., |
||
| 13 | exists=True, |
||
| 14 | file_okay=True, |
||
| 15 | dir_okay=True, |
||
| 16 | readable=True, |
||
| 17 | ), |
||
| 18 | plot: bool = typer.Option( # noqa: B008 |
||
| 19 | False, |
||
| 20 | '--plot/--no-plot', |
||
| 21 | '-p/-P', |
||
| 22 | help='Plot the image using Matplotlib or Pillow.', |
||
| 23 | ), |
||
| 24 | show: bool = typer.Option( # noqa: B008 |
||
| 25 | False, |
||
| 26 | '--show/--no-show', |
||
| 27 | '-s/-S', |
||
| 28 | help='Show the image using specialized visualisation software.', |
||
| 29 | ), |
||
| 30 | label: bool = typer.Option( # noqa: B008 |
||
| 31 | False, |
||
| 32 | '--label/--scalar', |
||
| 33 | '-l/-s', |
||
| 34 | help='Use torchio.LabelMap to instantiate the image.', |
||
| 35 | ), |
||
| 36 | load: bool = typer.Option( # noqa: B008 |
||
| 37 | False, |
||
| 38 | help=( |
||
| 39 | 'Load the image from disk so that information about data type and memory ' |
||
| 40 | 'can be displayed. Slower, especially for large images.' |
||
| 41 | ), |
||
| 42 | ), |
||
| 43 | ) -> None: |
||
| 44 | """Print information about an image and, optionally, show it. |
||
| 45 | |||
| 46 | Example: |
||
| 47 | $ tiohd input.nii.gz |
||
| 48 | """ |
||
| 49 | # Imports are placed here so that the tool loads faster if not being run |
||
| 50 | import torchio as tio |
||
| 51 | |||
| 52 | class_ = tio.LabelMap if label else tio.ScalarImage |
||
| 53 | image = class_(input_path) |
||
| 54 | if load: |
||
| 55 | image.load() |
||
| 56 | print(image) # noqa: T201 |
||
| 57 | if plot: |
||
| 58 | image.plot() |
||
| 59 | if show: |
||
| 60 | image.show() |
||
| 61 | |||
| 62 | |||
| 63 | if __name__ == '__main__': |
||
| 64 | app() |
||
| 65 |