dcmread(fp: Union[str, os.PathLike[AnyStr], BinaryIO], defer_size: Optional[Union[str, int]] = None, stop_before_pixels: bool = False, force: bool = False, specific_tags: Optional[List[Union[int, str, Tuple[int]]]] = None) → Union[pydicom.dataset.FileDataset, pydicom.dicomdir.DicomDir]¶
Read and parse a DICOM dataset stored in the DICOM File Format.
Read a DICOM dataset stored in accordance with the DICOM File Format. If the dataset is not stored in accordance with the File Format (i.e. the preamble and prefix are missing, there are missing required Type 1 File Meta Information Group elements or the entire File Meta Information is missing) then you will have to set force to
fp (str or PathLike or file-like) – Either a file-like object, or a string containing the file name. If a file-like object, the caller is responsible for closing it.
defer_size (int or str or None, optional) – If
None(default), all elements are read into memory. If specified, then if a data element’s stored value is larger than defer_size, the value is not read into memory until it is accessed in code. Specify an integer (bytes), or a string value with units, e.g. “512 KB”, “2 MB”.
stop_before_pixels (bool, optional) – If
False(default), the full file will be read and parsed. Set
Trueto stop before reading (7FE0,0010) Pixel Data (and all subsequent elements).
force (bool, optional) – If
False(default), raises an
InvalidDicomErrorif the file is missing the File Meta Information header. Set to
Trueto force reading even if no File Meta Information header is found.
specific_tags (list of (int or str or 2-tuple of int), optional) – If not
None, only the tags in the list are returned. The list elements can be tags or tag names. Note that the element (0008,0005) Specific Character Set is always returned if present - this ensures correct decoding of returned text values.
- Return type
Read and return a dataset stored in accordance with the DICOM File Format:
>>> ds = pydicom.dcmread("rtplan.dcm") >>> ds.PatientName
Read and return a dataset not in accordance with the DICOM File Format:
>>> ds = pydicom.dcmread("rtplan.dcm", force=True) >>> ds.PatientName
Use within a context manager:
>>> with pydicom.dcmread("rtplan.dcm") as ds: >>> ds.PatientName