Data Module#

Data module.

class landmarker.data.HeatmapDataset[source]#

HeatmapDataset is a subclass of LandmarkDataset. It represents a dataset of images and landmarks. The images can be provided as a list of paths to the images or as a list of numpy arrays or as a numpy array/torch.Tensor. Th landmarks must be provided. The heatmaps are created from the landmarks using a Gaussian or Laplacian function. When using the HeatmapDataset, images are always stored in memory.

Parameters:
  • imgs (list[str] | list[np.array] | np.ndarray | torch.Tensor) – list of paths to the images or list of numpy arrays or numpy array/torch.Tensor.

  • landmarks (np.ndarray | torch.Tensor) – landmarks of the images. If the landmarks are 2D: y, x or 3D: z, y, x.

  • spatial_dims (int) – number of spatial dimensions of the images. (defaults: 2)

  • pixel_spacing (Optional[np.ndarray | torch.Tensor]) – pixel spacing of the images. (defaults: None)

  • class_names (Optional[list]) – names of the landmarks. (defaults: None)

  • transform (Optional[Callable]) – transformation to apply to the images and landmarks. (defaults: None)

  • sigma (float | list[float]) – sigma of the Gaussian or Laplacian function. (defaults: 5)

  • dim_img (Optional[tuple[int, int]]) – dimension of the images. (defaults: None)

  • batch_size (int) – batch size to use when creating the heatmaps. (defaults: 32)

  • background (bool) – whether to add a background channel or not. (defaults: False)

  • all_points (bool) – whether to add a channel for all points or not. (defaults: False)

  • gamma (Optional[float]) – gamma of the Gaussian or Laplacian function. (defaults: None)

  • heatmap_fun (str) – function to use to create the heatmaps. (defaults: β€œgaussian”)

  • heatmap_size (Optional[tuple[int, int]]) – size of the heatmaps. (defaults: None)

  • img_paths (Optional[list[str]]) – list of paths to the images. (defaults: None)

  • resize_pad (bool) – whether to resize the images and landmarks or not. (defaults: True)

__init__(imgs, landmarks, spatial_dims=2, pixel_spacing=None, class_names=None, transform=None, store_imgs=True, sigma=5, dim_img=None, batch_size=32, background=False, all_points=False, gamma=None, heatmap_fun='gaussian', heatmap_size=None, img_paths=None, resize_pad=True)[source]#
Parameters:
  • imgs (list[str] | list[ndarray] | ndarray | Tensor) –

  • landmarks (ndarray | Tensor) –

  • spatial_dims (int) –

  • pixel_spacing (ndarray | Tensor | None) –

  • class_names (list | None) –

  • transform (Callable | None) –

  • store_imgs (bool) –

  • sigma (float | list[float] | ndarray | Tensor) –

  • dim_img (tuple[int, ...] | None) –

  • batch_size (int) –

  • background (bool) –

  • all_points (bool) –

  • gamma (float | None) –

  • heatmap_fun (str) –

  • heatmap_size (tuple[int, ...] | None) –

  • img_paths (list[str] | None) –

  • resize_pad (bool) –

Return type:

None

class landmarker.data.LandmarkDataset[source]#

LandmarkDataset is a subclass of torch.utils.data.Dataset. It represents a dataset of images and landmarks. The images can be provided as a list of paths to the images or as a list of numpy arrays or as a numpy array/torch.Tensor.

Parameters:
  • imgs (list[str] | list[np.array] | np.ndarray | torch.Tensor) – list of paths to the images or list of numpy arrays or numpy array/torch.Tensor.

  • landmarks (np.ndarray | torch.Tensor) – landmarks of the images. If the landmarks are 2D: y, x or 3D: z, y, x.

  • spatial_dims (int) – number of spatial dimensions of the images. (defaults: 2)

  • pixel_spacing (Optional[np.ndarray | torch.Tensor]) – pixel spacing of the images. (defaults: None)

  • class_names (Optional[list]) – names of the landmarks. (defaults: None)

  • transform (Optional[Callable]) – transformation to apply to the images and landmarks. (defaults: None)

  • store_imgs (bool) – whether to store the images in memory or not. (defaults: True)

  • dim_img (Optional[tuple[int, int]]) – dimension of the images. (defaults: None)

  • img_paths (Optional[list[str]]) – list of paths to the images. (defaults: None)

  • resize_pad (bool) – whether to resize the images and landmarks or not. (defaults: True)

__init__(imgs, landmarks, spatial_dims=2, pixel_spacing=None, class_names=None, transform=None, store_imgs=True, dim_img=None, img_paths=None, resize_pad=True)[source]#
Parameters:
  • imgs (list[str] | ndarray | Tensor | list[ndarray] | list[Tensor]) –

  • landmarks (ndarray | Tensor) –

  • spatial_dims (int) –

  • pixel_spacing (list[int] | tuple[int, ...] | ndarray | Tensor | None) –

  • class_names (list | None) –

  • transform (Callable | None) –

  • store_imgs (bool) –

  • dim_img (tuple[int, ...] | None) –

  • img_paths (list[str] | None) –

  • resize_pad (bool) –

Return type:

None

class landmarker.data.MaskDataset[source]#

MaskDataset is a subclass of LandmarkDataset. It represents a dataset of images and landmarks. The images can be provided as a list of paths to the images or as a list of numpy arrays or as a numpy array/torch.Tensor. The landmarks can be provided as a list of paths to the masks or as a list of numpy arrays or as a numpy array/torch.Tensor. The masks must be grayscale images with the landmarks represented by different values. The landmarks can be extracted from the masks and stored as a torch.Tensor or they can be genererated from provided landmarks. Note that if mask paths are provide this can be only be grayscale images and thus the dataset can only contain one class of landmark per image.

Parameters:
  • imgs (list[str] | list[np.array] | np.ndarray | torch.Tensor) – list of paths to the images or list of numpy arrays or numpy array/torch.Tensor.

  • landmarks (np.ndarray | torch.Tensor) – landmarks of the images. If the landmarks are 2D: y, x or 3D: z, y, x.

  • spatial_dims (int) – number of spatial dimensions of the images. (defaults: 2)

  • pixel_spacing (Optional[np.ndarray | torch.Tensor]) – pixel spacing of the images. (defaults: None)

  • class_names (Optional[list]) – names of the landmarks. (defaults: None)

  • transform (Optional[Callable]) – transformation to apply to the images and landmarks. (defaults: None)

  • store_imgs (bool) – whether to store the images in memory or not. (defaults: True)

  • store_masks (bool) – whether to store the masks in memory or not. (defaults: False)

  • dim_img (Optional[tuple[int, int]]) – dimension of the images. (defaults: None)

  • mask_paths (Optional[list[str]]) – list of paths to the masks. (defaults: None)

  • nb_landmarks (int) – number of landmarks in the masks. (defaults: 1)

  • img_paths (Optional[list[str]]) – list of paths to the images. (defaults: None)

  • resize_pad (bool) – whether to resize the images and landmarks or not. (defaults: True)

__init__(imgs, landmarks=None, spatial_dims=2, pixel_spacing=None, class_names=None, transform=None, store_imgs=True, dim_img=None, mask_paths=None, nb_landmarks=1, img_paths=None, resize_pad=True)[source]#
Parameters:
  • imgs (list[str] | list[ndarray] | ndarray | Tensor) –

  • landmarks (ndarray | Tensor | None) –

  • spatial_dims (int) –

  • pixel_spacing (Tensor | None) –

  • class_names (list | None) –

  • transform (Callable | None) –

  • store_imgs (bool) –

  • dim_img (tuple[int, ...] | None) –

  • mask_paths (list[str] | None) –

  • nb_landmarks (int) –

  • img_paths (list[str] | None) –

  • resize_pad (bool) –

Return type:

None