- pydicom.filereader.dcmread(fp: Union[str, bytes, PathLike, BinaryIO, DicomFileLike], defer_size: Optional[Union[int, float, str]] = None, stop_before_pixels: bool = False, force: bool = False, specific_tags: Optional[Union[List[int], List[str], List[Tuple[int, int]], List[BaseTag]]] = None) Union[FileDataset, 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
Read and return a dataset stored in accordance with the DICOM File Format:
>>> ds = pydicom.dcmread("CT_small.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
fp (str or PathLike or file-like) – Either a file-like object, a string containing the file name or the path to the file. The file-like object must have
tell()methods and the caller is responsible for closing it (if required).
defer_size (int, str or float, optional) – If not used then 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. Should be the number of bytes to be read as
intor as a
strwith units, e.g.
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 used the only the supplied tags will be returned. The supplied elements can be tags or keywords. Note that the element (0008,0005) Specific Character Set is always returned if present - this ensures correct decoding of returned text values.
- Return type