Skip to content

Commit 54e92bd

Browse files
authored
Replace np.copy with np.ascontiguousarray (#1356)
1 parent a84044a commit 54e92bd

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/torchio/transforms/augmentation/spatial/random_flip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ def _flip_image(image, axes):
127127
spatial_axes = np.array(axes, int) + 1
128128
data = image.numpy()
129129
data = np.flip(data, axis=spatial_axes)
130-
data = data.copy() # remove negative strides
130+
data = np.ascontiguousarray(data) # remove negative strides
131131
data = torch.as_tensor(data)
132132
image.set_data(data)

src/torchio/transforms/preprocessing/spatial/to_orientation.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import nibabel as nib
2+
import numpy as np
23
import torch
34
from einops import rearrange
45
from nibabel import orientations
@@ -96,11 +97,14 @@ def apply_transform(self, subject: Subject) -> Subject:
9697

9798
# Calculate the new affine matrix reflecting the reorientation
9899
reoriented_affine = nii.affine @ orientations.inv_ornt_aff(
99-
transform, nii.shape
100+
transform,
101+
nii.shape,
100102
)
101103

102104
# Update the image data and affine
103-
image.set_data(torch.from_numpy(reoriented_array.copy()))
105+
reoriented_array = np.ascontiguousarray(reoriented_array)
106+
tensor = torch.from_numpy(reoriented_array)
107+
image.set_data(tensor)
104108
image.affine = reoriented_affine
105109

106110
return subject

0 commit comments

Comments
 (0)