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

Overflow in ContrastStretching #58

Closed
timholy opened this issue Jul 23, 2023 · 0 comments · Fixed by #59
Closed

Overflow in ContrastStretching #58

timholy opened this issue Jul 23, 2023 · 0 comments · Fixed by #59

Comments

@timholy
Copy link
Member

timholy commented Jul 23, 2023

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.

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

Successfully merging a pull request may close this issue.

1 participant