JuliaImages / ImageView.jl

Interactive display of images and movies
MIT License
135 stars 34 forks source link

Improper `Normed` handling in the contrast GUI #310

Closed kimikage closed 2 months ago

kimikage commented 2 months ago

This is a little related to issue #308 and PR #309. The contrast GUI causes errors with the images using Normed, such as N0f8.

julia> using ImageView

julia> using ImageView.FixedPointNumbers

julia> VERSION
v"1.10.4"

julia> pkgversion(ImageView)
v"0.12.4"

julia> n0f8s = N0f8[0.2 0.8];

julia> imshow(n0f8s); # and then slide "slider_max" to the left

┌ Warning: Executing #14:
└ @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:122
ERROR: 0.2N0f8 is not within the span of 0.20000000298023224:0.002362204759609042:0.800000011920929
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:35
  [2] setindex!(s::GtkObservables.Slider{Float32}, ::Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, N0f8})
    @ GtkObservables C:\Users\username\.julia\packages\GtkObservables\gSI6s\src\widgets.jl:173
  [3] (::ImageView.var"#130#133"{Observables.Observable{CLim{N0f8}}, Dict{String, Any}, N0f8, DataType})(cmin::Float32, cmax::Float32)
    @ ImageView C:\Users\username\.julia\packages\ImageView\QLmQc\src\contrast_gui.jl:103
  [4] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base .\essentials.jl:892
  [5] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base .\essentials.jl:889
  [6] (::Observables.MapCallback)(value::Any)
    @ Observables C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:436
  [7] #invokelatest#2
    @ .\essentials.jl:892 [inlined]
  [8] invokelatest
    @ .\essentials.jl:889 [inlined]
  [9] notify
    @ C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:206 [inlined]
 [10] setindex!(observable::Observables.Observable, val::Any)
    @ Observables C:\Users\username\.julia\packages\Observables\YdEbO\src\Observables.jl:123
 [11] (::GtkObservables.var"#14#15"{Observables.Observable{Float32}})(w::Gtk4.GtkScaleLeaf)
    @ GtkObservables C:\Users\username\.julia\packages\GtkObservables\gSI6s\src\widgets.jl:155
 [12] (::Gtk4.GLib.var"#134#136"{Ptr{Gtk4.GLib.GValue}, UInt32, Ptr{Gtk4.GLib.GValue}, Vector{Any}, GtkObservables.var"#14#15"{Observables.Observable{Float32}}})()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:63
 [13] g_siginterruptible(f::Gtk4.GLib.var"#134#136"{Ptr{Gtk4.GLib.GValue}, UInt32, Ptr{Gtk4.GLib.GValue}, Vector{Any}, GtkObservables.var"#14#15"{Observables.Observable{Float32}}}, cb::Any)
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:244
 [14] GClosureMarshal(closuref::Ptr{Nothing}, return_value::Ptr{Gtk4.GLib.GValue}, n_param_values::UInt32, param_values::Ptr{Gtk4.GLib.GValue}, invocation_hint::Ptr{Nothing}, marshal_data::Ptr{Nothing})
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:57
 [15] (::Gtk4.GLib.var"#233#234")()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\loop.jl:83
 [16] g_sigatom(f::Any)
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\signals.jl:211
 [17] glib_main()
    @ Gtk4.GLib C:\Users\username\.julia\packages\Gtk4\pLBGK\src\GLib\loop.jl:80
kimikage commented 2 months ago

This may be directly due to the fact that the slider range is based on Float64 while the slider value can be Normed. This should be solved by converting the values to float.

https://github.com/JuliaImages/ImageView.jl/blob/27fb1926c86cfda6ac84f86f34f0b88195156a37/src/contrast_gui.jl#L101

https://github.com/JuliaImages/ImageView.jl/blob/27fb1926c86cfda6ac84f86f34f0b88195156a37/src/contrast_gui.jl#L115-L116

cc: @jwahlstrand

jwahlstrand commented 2 months ago

Thanks, your suggestion does prevent the error! I'll submit a PR (unless you'd like to?)

kimikage commented 2 months ago

I do not have merge privileges on this repository, so I would like to ask you to make a PR.