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

EOFError: read end of file #33

Closed
jumerckx opened this issue Jul 17, 2019 · 2 comments
Closed

EOFError: read end of file #33

jumerckx opened this issue Jul 17, 2019 · 2 comments

Comments

@jumerckx
Copy link

I got some DICOM images from a Kaggle competition and tried parsing one of them in Julia but got this error:

EOFError: read end of file

Stacktrace:
 [1] unsafe_read at .\iostream.jl:413 [inlined]
 [2] unsafe_read at .\io.jl:585 [inlined]
 [3] macro expansion at .\gcutils.jl:87 [inlined]
 [4] read! at .\io.jl:597 [inlined]
 [5] element(::IOStream, ::Bool, ::Dict{Tuple{UInt16,UInt16},Any}, ::Dict{Tuple{UInt16,UInt16},String}) at C:\Users\jules\.julia\packages\DICOM\Tu30N\src\DICOM.jl:377
 [6] #dcm_parse#17(::Bool, ::UInt16, ::Dict{Tuple{UInt16,UInt16},String}, ::Function, ::String, ::Bool) at C:\Users\jules\.julia\packages\DICOM\Tu30N\src\DICOM.jl:524
 [7] dcm_parse at C:\Users\jules\.julia\packages\DICOM\Tu30N\src\DICOM.jl:501 [inlined] (repeats 2 times)
 [8] top-level scope at In[3]:1

Am I doing something wrong or is this reproducible?
sample images.zip

Versioninfo:

Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
@notZaki
Copy link
Member

notZaki commented Jul 18, 2019

I was able to reproduce the error.

There's two reasons why the files couldn't be parsed: (i) there was a bug in the package and (ii) the images are JPEG-compressed.

The pending pull request should resolve the bug.
In the mean time, the local package can be updated by

julia> ]dev DICOM

and then navigating to the dev directory and pulling the specifyLength_AS branch from my fork, e.g.

git pull https://github.com/notZaki/DICOM.jl.git specifyLength_AS

With the above fix, those DICOM files can be parsed, but the pixel data will be incorrect because this package does not support JPEG-compressed images. These can be decompressed by using an external tool.
I used GDCM (download). Once it is installed and in the system path, the DICOM files can be decompressed by running gdcmconv --raw compressed.dcm uncompressed.dcm.


For reference, I'm including the code that I used to test it out along with a screengrab of the plotted image. The pixel data will likely have to be flipped/transposed to get the right orientation.

# The folder containing the DICOM files
datafolder = joinpath(pwd(), "sample.images")

# Get the filenames of only the dicom files
datafiles = readdir(datafolder)
isDICOM = [splitext(file)[2]==".dcm" for file in datafiles]
dicomfiles = datafiles[isDICOM]

# Use GDCM to decompress the dicom files
outfolder = joinpath(pwd(), "samples.images.decompressed")
mkdir(outfolder) # [!] assumes outfolder doesn't exist
for file in dicomfiles
    inputfile = joinpath(datafolder, file)
    outputfile = joinpath(outfolder, file)
    run(`gdcmconv --raw $inputfile $outputfile`)
end

# Pick any of the decompressed files and parse it
using DICOM
chosenfile = joinpath(outfolder, dicomfiles[1])
dicomdata = dcm_parse(chosenfile)

# Display the pixel data from the parsed file
using Plots
gr()
pixeldata =  dicomdata[tag"Pixel Data"]
heatmap(pixeldata, aspect_ratio=1, color=:grays)

image

@jumerckx
Copy link
Author

WOW, thanks a lot!
This is really great!!!

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

2 participants