Get the raw array data of the image, converted to Numpy array. Following PyTorch conventions, the returned array data has contiguous channels, e.g. for an RGB image, all red channel image pixels are contiguous in memory. The last axis of the returned array is the ch
(self, img)
| 367 | return np.asarray(_size[:sr]) |
| 368 | |
| 369 | def _get_array_data(self, img): |
| 370 | """ |
| 371 | Get the raw array data of the image, converted to Numpy array. |
| 372 | |
| 373 | Following PyTorch conventions, the returned array data has contiguous channels, |
| 374 | e.g. for an RGB image, all red channel image pixels are contiguous in memory. |
| 375 | The last axis of the returned array is the channel axis. |
| 376 | |
| 377 | See also: |
| 378 | |
| 379 | - https://github.com/InsightSoftwareConsortium/ITK/blob/v5.2.1/Modules/Bridge/NumPy/wrapping/PyBuffer.i.in |
| 380 | |
| 381 | Args: |
| 382 | img: an ITK image object loaded from an image file. |
| 383 | |
| 384 | """ |
| 385 | np_img = itk.array_view_from_image(img, keep_axes=False) |
| 386 | if img.GetNumberOfComponentsPerPixel() == 1: # handling spatial images |
| 387 | return np_img if self.reverse_indexing else np_img.T |
| 388 | # handling multi-channel images |
| 389 | return np_img if self.reverse_indexing else np.moveaxis(np_img.T, 0, -1) |
| 390 | |
| 391 | |
| 392 | @require_pkg(pkg_name="pydicom") |