Skip to content

Commit

Permalink
ENH: Be explicit about expected ordering of numpy data
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpa committed Feb 4, 2025
1 parent 54ed180 commit f22bf97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ants/core/ants_image_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def from_numpy(
if best_dtype != data.dtype:
data = data.astype(best_dtype)

img = _from_numpy(data.T.copy(), origin, spacing, direction, has_components, is_rgb)
# Be explicit about ordering of data - needs to be C-contiguous
img = _from_numpy(data.T.copy(order='C'), origin, spacing, direction, has_components, is_rgb)
return img


Expand Down
8 changes: 7 additions & 1 deletion src/readImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ AntsImage<ImageType> imageRead( std::string filename )
return myImage;
}


/**
* Create an ANTsImage from a numpy array
*
* The data array must be C-contiguous, and ordered correctly
* See "4.1.7 Importing Image Data from a Buffer"
* https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch4.html
*/
template <typename ImageType>
AntsImage<ImageType> fromNumpy( nb::ndarray<nb::numpy> data, nb::tuple datashape )
{
Expand Down

0 comments on commit f22bf97

Please sign in to comment.