JuliaImages / ImageShow.jl

Inline graphical display of images in Julia graphical environments
MIT License
25 stars 9 forks source link

Support for Grays wrapping signed FixedPointNumbers #42

Closed tlnagy closed 3 years ago

tlnagy commented 3 years ago

Currently ImageShow breaks when trying to display images with signed FixedPointNumbers, e.g. Q0f31, etc

julia> using TiffImages, ImageShow

julia> img = TiffImages.load("example.tif")
┌ Info: For better quality inline display of large images or thumbnails, load the Images package.
└ @ ImageShow /home/tlnagy/.julia/packages/ImageShow/11zF7/src/showmime.jl:131
┌ Info: Precompiling ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1]
└ @ Base loading.jl:1317
┌ 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.
└ @ ImageMagick /home/tlnagy/.julia/packages/ImageMagick/b8swT/src/ImageMagick.jl:180
Errors encountered while save FileIO.Stream{FileIO.DataFormat{:PNG}, IOContext{Base64.Base64EncodePipe}, Nothing}(IOContext(Base64.Base64EncodePipe(IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1), 
All errors:
===========================================
ArgumentError: FixedPointNumbers.Q0f31 is a 32-bit type representing 4294967296 values from -1.0 to 1.0; cannot represent 1
===========================================
ArgumentError: FixedPointNumbers.Q0f31 is a 32-bit type representing 4294967296 values from -1.0 to 1.0; cannot represent 1
===========================================
FileIO.MimeWriter writer error: neither save nor fileio_save is defined
  due to 
...

example.tif is from https://github.com/tlnagy/TiffImages.jl/issues/56#issue-931734331

julia> eltype(img)
ColorTypes.Gray{FixedPointNumbers.Q0f31}

It would super nice to display these sorts of images properly, i.e. with one color for negative numbers and another for positive or even reinterpreted as normed FixedPointNumbers. The former is definitely preferable, but the current behavior isn't nice for the end user.

tlnagy commented 3 years ago

Accidental duplicate of #41