JuliaIO / NRRD.jl

Julia support for the Nearly Raw Raster Data (NRRD) image file format
Other
10 stars 9 forks source link

Load failure for big endian memory-mapped images #15

Closed Cody-G closed 7 years ago

Cody-G commented 7 years ago

Note that this example probably won't fail on a system that is natively big endian.

I'm also attaching a file that triggers the error. Maybe we can add the file to the test suite?

small_bigendian.zip


julia> load("small_bigendian.nrrd"; mmap=true)
myendian() = "little"
(Traw,need_bswap) = raw_eltype(header) = (UInt16,true)
T = UInt16
Tuser = Any
Error encountered while loading "/mnt/cody_005/brain_browser/small_bigendian.nrrd".
Fatal error:
ERROR: MethodError: no method matching reinterpret(::Type{UInt16}, ::MappedArrays.ReadonlyMappedArray{UInt16,3,Array{UInt16,3},Base.#bswap}, ::Tuple{Int64,Int64,Int64})
Closest candidates are:
  reinterpret{T,S,N}(::Type{T}, ::Array{S,N}, ::Tuple{Vararg{Int64,N}}) at array.jl:86
  reinterpret{T}(::Type{T}, ::Base.ReshapedArray{T,N,P<:AbstractArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N}}}, ::Tuple{Vararg{Int64,N}}) at reshapedarray.jl:102
  reinterpret{T,Tv,Ti,N}(::Type{T}, ::SparseMatrixCSC{Tv,Ti}, ::Tuple{Vararg{Int64,N}}) at sparse/sparsematrix.jl:167
  ...
 in #load#4(::String, ::Bool, ::Function, ::FileIO.Stream{FileIO.DataFormat{:NRRD},IOStream}, ::Type{T}) at /home/cody/v0.5_for_seg/v0.5/NRRD/src/NRRD.jl:254
 in (::NRRD.#kw##load)(::Array{Any,1}, ::NRRD.#load, ::FileIO.Stream{FileIO.DataFormat{:NRRD},IOStream}, ::Type{T}) at ./<missing>:0
 in open(::NRRD.##2#3{String,Bool,Tuple{}}, ::FileIO.File{FileIO.DataFormat{:NRRD}}, ::String) at ./iostream.jl:113
 in (::NRRD.#kw##load)(::Array{Any,1}, ::NRRD.#load, ::FileIO.File{FileIO.DataFormat{:NRRD}}) at ./<missing>:0
 in anonymous at ./<missing>:?
 in eval(::Module, ::Any) at ./boot.jl:234
 in #load#17(::Array{Any,1}, ::Function, ::FileIO.File{FileIO.DataFormat{:NRRD}}) at /home/cody/v0.5_for_seg/v0.5/FileIO/src/loadsave.jl:87
 in (::FileIO.#kw##load)(::Array{Any,1}, ::FileIO.#load, ::FileIO.File{FileIO.DataFormat{:NRRD}}) at ./<missing>:0
 in #load#13(::Array{Any,1}, ::Function, ::String) at /home/cody/v0.5_for_seg/v0.5/FileIO/src/loadsave.jl:45
 in (::FileIO.#kw##load)(::Array{Any,1}, ::FileIO.#load, ::String) at ./<missing>:0
timholy commented 7 years ago

Thanks! Very helpful test case.

See #16. I wanted to test more than "reading didn't throw an error," so I ended up constructing a test image where I knew what values I wanted to get from it.