Skip to content

Commit 67ddcde

Browse files
committed
BUG: Use linspace for coords in xarray_from_image
Prevent floating point precision issues from generating the incorrect number of coords.
1 parent 343cbf9 commit 67ddcde

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Wrapping/Generators/Python/itkExtras.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ def xarray_from_image(image):
405405
spatial_dims = ('x', 'y', 'z')
406406
coords = {}
407407
for index, dim in enumerate(spatial_dims[:spatial_dimension]):
408-
coords[dim] = np.arange(origin[index],
409-
origin[index] + size[index]*spacing[index],
410-
spacing[index],
411-
dtype=np.float64)
408+
coords[dim] = np.linspace(origin[index],
409+
origin[index] + (size[index]-1)*spacing[index],
410+
size[index],
411+
dtype=np.float64)
412412

413413
dims = list(reversed(spatial_dims[:spatial_dimension]))
414414
components = image.GetNumberOfComponentsPerPixel()

0 commit comments

Comments
 (0)