What’s the best way to get a PNG image out of a matrix of signed integers, with Images.jl
?
I converted the signed integers to Fixed
in the range [-1, 1)
(e.g., Int64
to Fixed{Int64, 63}
), but when I try to create a PNG image (for example, when doing this in a Jupyter notebook) I get an error.
Single-line recipe to reproduce the issue:
julia> using Images
julia> reprmime("image/png", Gray.(reinterpret.(Fixed{Int8, 7}, rand(Int8, 5, 5))))
WARNING: Mapping to the storage type failed; perhaps your data had out-of-range values?
Try `map(clamp01nan, img)` to clamp values to a valid range.
Errors encountered while saving "Nullable{String}()".
All errors:
InexactError()
ErrorException("function save does not accept keyword arguments")
Fatal error:
ERROR: InexactError()
Stacktrace:
[1] kwfunc(::Any) at ./boot.jl:237
[2] eval(::Module, ::Any) at ./boot.jl:235
[3] #save#21(::Array{Any,1}, ::Function, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}}, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}, ::Vararg{Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2},N} where N) at /home/mose/.julia/v0.6/FileIO/src/loadsave.jl:115
[4] (::FileIO.#kw##save)(::Array{Any,1}, ::FileIO.#save, ::FileIO.Stream{FileIO.DataFormat{:PNG},IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}}, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}) at ./<missing>:0
[5] #show#93(::Int64, ::Int64, ::Function, ::Function, ::IOContext{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}) at /home/mose/.julia/v0.6/Images/src/showmime.jl:35
[6] verbose_show(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}) at ./multimedia.jl:42
[7] _binreprmime at ./multimedia.jl:71 [inlined]
[8] reprmime(::MIME{Symbol("image/png")}, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}) at ./multimedia.jl:61
[9] reprmime(::String, ::Array{ColorTypes.Gray{FixedPointNumbers.Fixed{Int8,7}},2}) at ./multimedia.jl:98
No problem with Matrix{Gray{Normed{T,N}}}
, for unsigned integers, nor with Matrix{Gray{AbstractFloat}}
for plain floating numbers (including negative values)