ImageView.jl
ImageView.jl copied to clipboard
ImageView's imshow incorrectly displays HSV images?
Hello,
the toy code below demonstrates the problem: a one-pixel green RGB image is displayed as green, but is displayed as red when converted to HSV:
# Activate a brand-new environment
import Pkg
Pkg.activate(temp=true)
Pkg.add(["Images", "ImageView"])
using Images
using ImageView
# Prepare one-pixel RGB image
x = zeros(RGB{N0f8}, (1,1))
x .= RGB(0, 1, 0) # green
imshow(x, name="RGB") # correctly displays green
# Convert to HSV
y = HSV.(x) # conversion seems to be correct, HSV{Float32}(120.0f0,1.0f0,1.0f0)
imshow(y, name="HSV") # diplays red instead of green!
Information for the troubleshooting:
using(Dates)
today()
versioninfo()
Pkg.status()
julia> today()
2023-06-27
julia> versioninfo()
Julia Version 1.9.1
Commit 147bdf428cd (2023-06-07 08:27 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
Threads: 4 on 8 virtual cores
Environment:
LD_LIBRARY_PATH = :/home/xxxx/.emacs.d/tree-sitter-julia/src/
JULIA_NUM_THREADS = 4
LD_ARGV0_REL = ../bin/vshd
JULIA_EDITOR = vim
JULIA_PKG_DEVDIR = /home/xxxx/juliadev
JULIA_CONDAPKG_BACKEND = Null
JULIA_PYTHONCALL_EXE = /home/xxxx/.julia/conda/3/bin/python
julia> Pkg.status()
Status `/tmp/jl_M9VHws/Project.toml`
[86fae568] ImageView v0.11.6
[916415d5] Images v0.25.3
I agree. This looks like a bug.
julia> using ImageView
julia> using ImageView, TestImages
julia> test = testimage("mandrill");
julia> imshow(HSV.(test))
Dict{String, Any} with 4 entries:
"gui" => Dict{String, Any}("window"=>GtkWindowLeaf(name="", parent, width-request=-1, height-request=-1, visi…
"roi" => Dict{String, Any}("redraw"=>ObserverFunction[ObserverFunction defined at C:\Users\kittisopikulm\.jul…
"annotations" => Observable(Dict{UInt64, Any}())
"clim" => nothing
We probably want something such as
julia> using Images, MappedArrays, TestImages
julia> import ImageView: imshow
julia> imshow(image::AbstractArray{<: Colorant}; kwargs...) = imshow(MappedArrays.mappedarray(RGB{N0f8}, image); kwargs...)
imshow (generic function with 23 methods)
julia> imshow(image::AbstractArray{RGB{N0f8}}; kwargs...) = invoke(imshow, Tuple{AbstractArray}, image; kwargs...)
imshow (generic function with 23 methods)
julia> test_hsv = HSV.(testimage("mandrill"));
julia> imshow(test_hsv)
Dict{String, Any} with 4 entries:
"gui" => Dict{String, Any}("window"=>GtkWindowLeaf(name="", parent, width-request=-1, height-request=-1, visi…
"roi" => Dict{String, Any}("redraw"=>ObserverFunction[ObserverFunction defined at C:\Users\kittisopikulm\.jul…
"annotations" => Observable(Dict{UInt64, Any}())
"clim" => Observable(CLim{RGB{Float64}}(RGB{Float64}(0.0,0.0,0.0), RGB{Float64}(1.0,1.0,1.0)))
For now, I suggest using MappedArrays directly.
julia> using Images, MappedArrays, TestImages, ImageView
julia> test_hsv = HSV.(testimage("mandrill"));
julia> imshow(mappedarray(RGB{N0f8}, test_hsv))