Closed GoogleCodeExporter closed 9 years ago
Thanks for entering this issue, and for providing a file -- I was able to
replicate
the Memory Error on my system. The "is d" near the start of the second line is
taken
as the length of a 'data element' to read, which translates (little endian) to
almost
2 GB. The read(<size>) function doesn't seem to like anything that large.
The pydicom read_file() function used to take an optional argument
'has_header', and
I removed that at some point (can't remember why). It's purpose was (if set to
False)
to _force_ pydicom to read a file even though the 'DICM' marker wasn't in the
file at
the correct position. I think this idea should be brought back, and in addition
to
that, even when forced there should be some heuristics (as mentioned in issue
24).
There is some discussion and code at [1] on how to approach this. But I'm
wondering
if something as simple as looking for the patient id tag (are all DICOM files
guaranteed to have this?) might work.
[1] http://www.dclunie.com/medical-image-
faq/html/part2.html#DICOMTransferSyntaxDetermination
Original comment by darcymason@gmail.com
on 20 Dec 2009 at 6:50
I think that just adding a simple test for syntactic validity would go a long
way. It
was one of the first things I added to my code. Something like this --
def is_dicom(filename):
"""Returns True if the file in question is a DICOM file, else False. """
# Per the DICOM specs, a DICOM file starts with 128 reserved bytes
# followed by "DICM".
# ref: http://dicom.nema.org/
f = open(filename, "rb")
s = f.read(132)
f.close()
return s.endswith("DICM")
Or is that too naive? Do DICOM files regularly violate that syntax?
If that code would cover most cases, it'd be useful to see pydicom integrate
that and
raise a custom error if it fails.
It doesn't preclude adding a 'force' param to read_file(); if reading a file
raises
an error the caller would be free to call read_file(force=True) and deal with
the
consequences.
Original comment by NikitaTh...@gmail.com
on 21 Dec 2009 at 3:36
This issue was closed by revision a7c9dce062.
Original comment by darcymason@gmail.com
on 26 Feb 2010 at 3:28
Original issue reported on code.google.com by
NikitaTh...@gmail.com
on 16 Dec 2009 at 2:18Attachments: