Skip to content

Commit

Permalink
BUG: Empty image support in image_from_xarray
Browse files Browse the repository at this point in the history
Required for map_blocks.
  • Loading branch information
thewtex committed Jul 13, 2020
1 parent 2121eed commit 3da4926
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Wrapping/Generators/Python/Tests/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ def custom_callback(name, progress):
assert False
except ValueError:
pass

empty_array = np.array([], dtype=np.uint8)
empty_array.shape = (0,0,0)
empty_image = itk.image_from_array(empty_array)
empty_da = itk.xarray_from_image(empty_image)
empty_image_round = itk.image_from_xarray(empty_da)
except ImportError:
print('xarray not imported. Skipping xarray conversion tests')
pass
6 changes: 4 additions & 2 deletions Wrapping/Generators/Python/itkExtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,10 @@ def image_from_xarray(data_array):
origin = [0.0]*spatial_dimension
spacing = [1.0]*spatial_dimension
for index, dim in enumerate(spatial_dims):
origin[index] = float(data_array.coords[dim][0])
spacing[index] = float(data_array.coords[dim][1]) - float(data_array.coords[dim][0])
coords = data_array.coords[dim]
if coords.shape[0] > 1:
origin[index] = float(coords[0])
spacing[index] = float(coords[1]) - float(coords[0])
spacing.reverse()
itk_image.SetSpacing(spacing)
origin.reverse()
Expand Down

0 comments on commit 3da4926

Please sign in to comment.