@@ -1097,14 +1097,14 @@ def random_permute_spatial_axes(
10971097 "Argument 'axes' should contain unique values."
10981098 )
10991099
1100- if set (axes ) <= {0 , 1 , 2 }:
1100+ if not set (axes ) <= {0 , 1 , 2 }:
11011101 raise ValueError (
11021102 "Argument 'axes' should contain only 0, 1, and 2."
11031103 )
11041104
11051105 indices = np .random .permutation (axes ).tolist ()
11061106 if len (indices ) == 2 :
1107- missing_index = {0 , 1 , 2 } - set (indices )
1107+ missing_index = list ( {0 , 1 , 2 } - set (indices ))[ 0 ]
11081108 indices .insert (missing_index , missing_index )
11091109
11101110 return self .permute_spatial_axes (indices )
@@ -1289,7 +1289,7 @@ def random_flip_spatial(self, axes: Sequence[int] = (0, 1, 2)) -> Self:
12891289 "Argument 'axes' should contain unique values."
12901290 )
12911291
1292- if set (axes ) <= {0 , 1 , 2 }:
1292+ if not set (axes ) <= {0 , 1 , 2 }:
12931293 raise ValueError (
12941294 "Argument 'axes' should contain only 0, 1, and 2."
12951295 )
@@ -1692,9 +1692,9 @@ def match_geometry(
16921692
16931693 permute_indices = []
16941694 step_sizes = []
1695- for u , s in zip (self .unit_vectors (), self .spacing ):
1695+ for u , s in zip (other .unit_vectors (), other .spacing ):
16961696 for j , (v , t ) in enumerate (
1697- zip (other .unit_vectors (), other .spacing )
1697+ zip (self .unit_vectors (), self .spacing )
16981698 ):
16991699 dot_product = u @ v
17001700 if (
@@ -1703,7 +1703,7 @@ def match_geometry(
17031703 ):
17041704 permute_indices .append (j )
17051705
1706- scale_factor = t / s
1706+ scale_factor = s / t
17071707 step = int (np .round (scale_factor ))
17081708 if abs (scale_factor - step ) > tol :
17091709 raise RuntimeError (
@@ -1724,7 +1724,6 @@ def match_geometry(
17241724 requires_permute = permute_indices != [0 , 1 , 2 ]
17251725 if requires_permute :
17261726 new_volume = self .permute_spatial_axes (permute_indices )
1727- step_sizes = [step_sizes [i ] for i in permute_indices ]
17281727 else :
17291728 new_volume = self
17301729
@@ -2789,10 +2788,13 @@ def permute_spatial_axes(self, indices: Sequence[int]) -> Self:
27892788 """
27902789 new_affine = self ._permute_affine (indices )
27912790
2792- if self ._array .ndim == 3 :
2793- new_array = np .transpose (self ._array , indices )
2794- else :
2795- new_array = np .transpose (self ._array , [* indices , 3 ])
2791+ new_array = np .transpose (
2792+ self ._array ,
2793+ [
2794+ * indices ,
2795+ * [d + 3 for d in range (self .number_of_channel_dimensions )]
2796+ ]
2797+ )
27962798
27972799 return self .__class__ (
27982800 array = new_array ,
0 commit comments