is_dcm¶

is_dcm(file)[source]¶

Determines whether the given file is a DICOM file.

Checks if the first 128 bytes of the file contain the ‘DICM’ preamble. Returns True if it is a DCM file, False otherwise.

This intentionally does not parse the file with pydicom.dcmread() to avoid the overhead of parsing the entire file. Parsing .dcm files can be slow for VL Whole Slide Images in some cases (e.g. sparse tiling).

Parameters:

file (Union[str, Path, bytes, BytesIO]) – A string, Path, bytes, or BytesIO object representing the path or binary data of the file.

Returns:

A boolean indicating whether the file is a .dcm file or not.

Return type:

bool