I am having trouble with dcmread()
on a DICOM file that does exists at given path. I'm not sure what went wrong. Here is my code:
import pydicom
f = "/exact/path/hi.dcm"
fn = get_testdata_file(f)
ds = pydicom.dcmread(fn)
ds.SOPClassUID = ds.MediaStorageSOPClassUID
I am getting below error:
Traceback (most recent call last):
File "addfields.py", line 14, in <module>
ds = pydicom.dcmread(fn)
File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py", line 871, in dcmread
force=force, specific_tags=specific_tags)
File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py", line 668, in read_partial
preamble = read_preamble(fileobj, force)
File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/pydicom/filereader.py", line 605, in read_preamble
preamble = fp.read(128)
AttributeError: 'NoneType' object has no attribute 'read'
But I am not sure why, because "hi.dcm" is a file that exists (path is correct) and has metadata inside. I do not know what is preamble and whether it present in the image I am dealing with.