Skip to content

Commit

Permalink
BUG: Use linspace for coords in xarray_from_image
Browse files Browse the repository at this point in the history
Prevent floating point precision issues from generating the incorrect
number of coords.
  • Loading branch information
thewtex committed Apr 21, 2020
1 parent 343cbf9 commit 67ddcde
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Wrapping/Generators/Python/itkExtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,10 @@ def xarray_from_image(image):
spatial_dims = ('x', 'y', 'z')
coords = {}
for index, dim in enumerate(spatial_dims[:spatial_dimension]):
coords[dim] = np.arange(origin[index],
origin[index] + size[index]*spacing[index],
spacing[index],
dtype=np.float64)
coords[dim] = np.linspace(origin[index],
origin[index] + (size[index]-1)*spacing[index],
size[index],
dtype=np.float64)

dims = list(reversed(spatial_dims[:spatial_dimension]))
components = image.GetNumberOfComponentsPerPixel()
Expand Down

0 comments on commit 67ddcde

Please sign in to comment.