Skip to content

Add content sniffing to utils.files.is_dicom #2

Description

@jond01

Inspired by contrib-pydicom:

https://github.com/pydicom/contrib-pydicom/blob/cbd27f1ac523863aeba820edf796bf040d63993f/input-output/dicom_model/dicom_dir.py#L43-L50

Looks like the following should complement medio's is_dicom function:

def is_dcm(filename):
    with open(filename, 'rb') as f:
        x = f.read(132)
    return x[128:] == b"DICM"

It is particularly useful since many times dicom files lack any extension.
I checked the above is_dcm on some data and it looks reliable.

With that, we can change the default dicom reader backend to pydicom (single and series).


Edit:
Even better, use pydicom's built-in is_dicom function (equivalent to the above is_dcm function).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions