Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add content sniffing to utils.files.is_dicom #2

Open
jond01 opened this issue May 2, 2021 · 0 comments
Open

Add content sniffing to utils.files.is_dicom #2

jond01 opened this issue May 2, 2021 · 0 comments

Comments

@jond01
Copy link
Collaborator

jond01 commented May 2, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant