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)
| 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 | """ |