clinicadl.data.structures.Sample2D¶
- class clinicadl.data.structures.Sample2D(image: ScalarImage | Path | str, participant_id: str, session_id: str, file_type: BidsFileType, image_path: Path, sample_position: int, slice_direction: int, squeeze: bool, **kwargs: Any)[source]¶
A
Samplecorresponding to a 2D slice.Here
sample_type="slice"andsample_positionis the position of the slice in the original image.Besides, there are two additional attributes:
- slice_directionint
The slicing direction (
0,1or2).- squeezebool
Whether the tensors will be later squeezed to work with 2D slice, or whether the slices will stay 3D (with one dummy dimension). The attribute is useful for some
ClinicaDLoperations.
- get_image_tensor(image_name: str) Tensor[source]¶
Returns a copy of the tensor associated to a field that is a
torchio.Image.If
squeeze=True, the output tensor will be squeezed.- Parameters:
image_name (str) – The name of the image in the
Sample2D.- Returns:
torch.Tensor – The tensor image.
- add_image(image: ScalarImage | Path | str | Tensor, image_name: str) None[source]¶
To add an image to the
Sample.- Parameters:
image (Union[tio.ScalarImage, PathType, torch.Tensor]) –
The image to add, as a
torchio.ScalarImage`, a path to the NIfTI file containing the image, or atorch.Tensor. In the latter case, it is expected to be a 4DTensor(including one channel dimension) ifsqueeze=False, or a 3DTensorifsqueeze=True.If a
Tensoris passed, the same affine matrix asself.imagewill be used.image_name (str) – The name that the image will take in the
Sample.
See also
- add_mask(mask: LabelMap | Path | str, mask_name: str) None[source]¶
To add a mask to the
Sample.- Parameters:
mask (Union[tio.ScalarImage, PathType, torch.Tensor]) –
The mask to add, as a
torchio.LabelMap, a path to the NIfTI file containing the mask, or atorch.Tensor. In the latter case, it is expected to be a 4DTensor(including one channel dimension) ifsqueeze=False, or a 3DTensorifsqueeze=True.If a
Tensoris passed, the same affine matrix asself.imagewill be used.mask_name (str) – The name that the image will take in the
Sample.
See also