MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _get_spatial_shape

Method _get_spatial_shape

monai/data/image_reader.py:1169–1191  ·  view source on GitHub ↗

Get the spatial shape of image data, it doesn't contain the channel dim. Args: img: a Nibabel image object loaded from an image file.

(self, img)

Source from the content-addressed store, hash-verified

1167 return np.array(img.affine, copy=True)
1168
1169 def _get_spatial_shape(self, img):
1170 """
1171 Get the spatial shape of image data, it doesn't contain the channel dim.
1172
1173 Args:
1174 img: a Nibabel image object loaded from an image file.
1175
1176 """
1177 # swap to little endian as PyTorch doesn't support big endian
1178 try:
1179 header = img.header.as_byteswapped("<")
1180 except ValueError:
1181 header = img.header
1182 dim = header.get("dim", None)
1183 if dim is None:
1184 dim = header.get("dims") # mgh format?
1185 dim = np.insert(dim, 0, 3)
1186 ndim = dim[0]
1187 size = list(dim[1:])
1188 if not is_no_channel(self.channel_dim):
1189 size.pop(int(self.channel_dim)) # type: ignore
1190 spatial_rank = max(min(ndim, 3), 1)
1191 return np.asarray(size[:spatial_rank])
1192
1193 def _get_array_data(self, img, filename):
1194 """

Callers 1

get_dataMethod · 0.95

Calls 5

is_no_channelFunction · 0.90
maxFunction · 0.85
minFunction · 0.85
getMethod · 0.80
popMethod · 0.80

Tested by

no test coverage detected