Skip to content

Commit

Permalink
Add support for reading and writing TIFF files
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvanrun committed Dec 22, 2023
1 parent bbc9a76 commit 0773cc8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0773cc8

Please sign in to comment.