Convert ``data_array`` into 'channel-last' numpy ndarray. Args: data_array: input data array with the channel dimension specified by ``channel_dim``. channel_dim: channel dimension of the data array. Defaults to 0. ``None`` indicates data wit
(
self, data_array: NdarrayOrTensor, channel_dim: int | None = 0, squeeze_end_dims: bool = True, **kwargs
)
| 394 | ) |
| 395 | |
| 396 | def set_data_array( |
| 397 | self, data_array: NdarrayOrTensor, channel_dim: int | None = 0, squeeze_end_dims: bool = True, **kwargs |
| 398 | ): |
| 399 | """ |
| 400 | Convert ``data_array`` into 'channel-last' numpy ndarray. |
| 401 | |
| 402 | Args: |
| 403 | data_array: input data array with the channel dimension specified by ``channel_dim``. |
| 404 | channel_dim: channel dimension of the data array. Defaults to 0. |
| 405 | ``None`` indicates data without any channel dimension. |
| 406 | squeeze_end_dims: if ``True``, any trailing singleton dimensions will be removed. |
| 407 | kwargs: keyword arguments passed to ``self.convert_to_channel_last``, |
| 408 | currently support ``spatial_ndim`` and ``contiguous``, defaulting to ``3`` and ``False`` respectively. |
| 409 | """ |
| 410 | n_chns = data_array.shape[channel_dim] if channel_dim is not None else 0 |
| 411 | self.data_obj = self.convert_to_channel_last( |
| 412 | data=data_array, |
| 413 | channel_dim=channel_dim, |
| 414 | squeeze_end_dims=squeeze_end_dims, |
| 415 | spatial_ndim=kwargs.pop("spatial_ndim", 3), |
| 416 | contiguous=kwargs.pop("contiguous", True), |
| 417 | ) |
| 418 | self.channel_dim = -1 # in most cases, the data is set to channel last |
| 419 | if squeeze_end_dims and n_chns <= 1: # num_channel==1 squeezed |
| 420 | self.channel_dim = None |
| 421 | if not squeeze_end_dims and n_chns < 1: # originally no channel and convert_to_channel_last added a channel |
| 422 | self.channel_dim = None |
| 423 | self.data_obj = self.data_obj[..., 0] |
| 424 | |
| 425 | def set_metadata(self, meta_dict: Mapping | None = None, resample: bool = True, **options): |
| 426 | """ |