MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ImageDataset

Class ImageDataset

monai/data/image_dataset.py:26–155  ·  view source on GitHub ↗

Loads image/segmentation pairs of files from the given filename lists. Transformations can be specified for the image and segmentation arrays separately. The difference between this dataset and `ArrayDataset` is that this dataset can apply transform chain to images and segs and retu

Source from the content-addressed store, hash-verified

24
25
26class ImageDataset(Dataset, Randomizable):
27 """
28 Loads image/segmentation pairs of files from the given filename lists. Transformations can be specified
29 for the image and segmentation arrays separately.
30 The difference between this dataset and `ArrayDataset` is that this dataset can apply transform chain to images
31 and segs and return both the images and metadata, and no need to specify transform to load images from files.
32 For more information, please see the image_dataset demo in the MONAI tutorial repo,
33 https://github.com/Project-MONAI/tutorials/blob/master/modules/image_dataset.ipynb
34 """
35
36 def __init__(
37 self,
38 image_files: Sequence[str],
39 seg_files: Sequence[str] | None = None,
40 labels: Sequence[float] | None = None,
41 transform: Callable | None = None,
42 seg_transform: Callable | None = None,
43 label_transform: Callable | None = None,
44 image_only: bool = True,
45 transform_with_metadata: bool = False,
46 dtype: DtypeLike = np.float32,
47 reader: ImageReader | str | None = None,
48 *args,
49 **kwargs,
50 ) -> None:
51 """
52 Initializes the dataset with the image and segmentation filename lists. The transform `transform` is applied
53 to the images and `seg_transform` to the segmentations.
54
55 Args:
56 image_files: list of image filenames.
57 seg_files: if in segmentation task, list of segmentation filenames.
58 labels: if in classification task, list of classification labels.
59 transform: transform to apply to image arrays.
60 seg_transform: transform to apply to segmentation arrays.
61 label_transform: transform to apply to the label data.
62 image_only: if True return only the image volume, otherwise, return image volume and the metadata.
63 transform_with_metadata: if True, the metadata will be passed to the transforms whenever possible.
64 dtype: if not None convert the loaded image to this data type.
65 reader: register reader to load image file and metadata, if None, will use the default readers.
66 If a string of reader name provided, will construct a reader object with the `*args` and `**kwargs`
67 parameters, supported reader name: "NibabelReader", "PILReader", "ITKReader", "NumpyReader"
68 args: additional parameters for reader if providing a reader name.
69 kwargs: additional parameters for reader if providing a reader name.
70
71 Raises:
72 ValueError: When ``seg_files`` length differs from ``image_files``
73
74 """
75
76 if seg_files is not None and len(image_files) != len(seg_files):
77 raise ValueError(
78 "Must have same the number of segmentation as image files: "
79 f"images={len(image_files)}, segmentations={len(seg_files)}."
80 )
81
82 self.image_files = image_files
83 self.seg_files = seg_files

Callers 3

run_testFunction · 0.90
test_use_caseMethod · 0.90
test_datasetMethod · 0.90

Calls

no outgoing calls

Tested by 3

run_testFunction · 0.72
test_use_caseMethod · 0.72
test_datasetMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…