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

ImageView's imshow incorrectly displays HSV images? #283

Open
mgr327 opened this issue Jun 27, 2023 · 1 comment
Open

ImageView's imshow incorrectly displays HSV images? #283

mgr327 opened this issue Jun 27, 2023 · 1 comment

Comments

@mgr327
Copy link

mgr327 commented Jun 27, 2023

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:

rgb
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

@mkitti
Copy link
Member

mkitti commented Jun 28, 2023

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

image

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)))

image

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))

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