Overflow in ContrastStretching
timholy opened this issue · comments
Tim Holy commented
adjust_histogram(img, ContrastStretching())
is suggested as a deprecation for imstretch
; with --depwarn=yes
, we get
julia> using Images
julia> img = Gray{N0f8}.([1 0; 0 1])
2×2 Array{Gray{N0f8},2} with eltype Gray{N0f8}:
Gray{N0f8}(1.0) Gray{N0f8}(0.0)
Gray{N0f8}(0.0) Gray{N0f8}(1.0)
julia> imgs = imstretch(img, 0.3, 0.4)
┌ Warning: `imstretch` will be removed in a future release, please use `adjust_histogram(img, ContrastStretching())` instead.
│ caller = top-level scope at REPL[3]:1
└ @ Core REPL[3]:1
2×2 Array{Gray{Float64},2} with eltype Gray{Float64}:
Gray{Float64}(0.618123) Gray{Float64}(0.00274462)
Gray{Float64}(0.00274462) Gray{Float64}(0.618123)
(As pointed out in JuliaImages/Images.jl#865 (comment), it would have been nice if this had suggested "please use adjust_histogram(img, ContrastStretching(; t=0.3, slope=0.4))
instead so that it was copy/pastable.)
But if we follow the suggestion, we get:
julia> adjust_histogram(img, ContrastStretching(t=0.3, slope=0.4))
2×2 Array{Gray{N0f8},2} with eltype Gray{N0f8}:
Gray{N0f8}(0.0) Gray{N0f8}(0.149)
Gray{N0f8}(0.149) Gray{N0f8}(0.0)
which is very different. However:
julia> adjust_histogram(float.(img), ContrastStretching(t=0.3, slope=0.4))
2×2 Array{Gray{Float32},2} with eltype Gray{Float32}:
Gray{Float32}(0.618123) Gray{Float32}(0.00274462)
Gray{Float32}(0.00274462) Gray{Float32}(0.618123)
indicating that it's overflow at fault.