From 0773cc848bd57c15787bed64bbd105a5c5c58ae7 Mon Sep 17 00:00:00 2001 From: Chris van Run Date: Fri, 22 Dec 2023 11:36:25 +0100 Subject: [PATCH] Add support for reading and writing TIFF files --- .../example-algorithm{{cookiecutter._}}/inference.py.j2 | 7 +++++-- .../evaluate.py.j2 | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/grand_challenge_forge/partials/example-algorithm/example-algorithm{{cookiecutter._}}/inference.py.j2 b/grand_challenge_forge/partials/example-algorithm/example-algorithm{{cookiecutter._}}/inference.py.j2 index 7030a57..4906aa1 100644 --- a/grand_challenge_forge/partials/example-algorithm/example-algorithm{{cookiecutter._}}/inference.py.j2 +++ b/grand_challenge_forge/partials/example-algorithm/example-algorithm{{cookiecutter._}}/inference.py.j2 @@ -107,7 +107,7 @@ def write_json_file(*, location, content): def load_image_file_as_array(*, location): # Use SimpleITK to read a file - input_files = glob(str(location / "*")) + input_files = glob(str(location / "*.tiff")) + glob(str(location / "*.mha")) result = SimpleITK.ReadImage(input_files[0]) # Convert it to a Numpy array @@ -119,10 +119,13 @@ def load_image_file_as_array(*, location): def write_array_as_image_file(*, location, array): location.mkdir(parents=True, exist_ok=True) + # You may need to change the suffix to .tiff to match the expected output + suffix = ".mha" + image = SimpleITK.GetImageFromArray(array) SimpleITK.WriteImage( image, - location / "output.mha", + location / f"output{suffix}", useCompression=True, ) {%- endif %} diff --git a/grand_challenge_forge/partials/example-evaluation-method/example-evaluation-method{{cookiecutter._}}/evaluate.py.j2 b/grand_challenge_forge/partials/example-evaluation-method/example-evaluation-method{{cookiecutter._}}/evaluate.py.j2 index 1e37c42..96ecb7a 100644 --- a/grand_challenge_forge/partials/example-evaluation-method/example-evaluation-method{{cookiecutter._}}/evaluate.py.j2 +++ b/grand_challenge_forge/partials/example-evaluation-method/example-evaluation-method{{cookiecutter._}}/evaluate.py.j2 @@ -177,7 +177,7 @@ def load_json_file(*, location): def load_image_file(*, location): # Use SimpleITK to read a file - input_files = glob(str(location / "*")) + input_files = glob(str(location / "*.tiff")) + glob(str(location / "*.mha")) result = SimpleITK.ReadImage(input_files[0]) # Convert it to a Numpy array