-
Notifications
You must be signed in to change notification settings - Fork 9
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
Return value type from find_threshold
doesn't match image
#49
Comments
I tried to find a reason but I couldn't, I don't particularly think it even plagues Gray as such but by principle, it might have been better as Gray in output. It's contained as long as people just use it on Gray n Bool. It would be great if you can chime in sir @zygmuntszpak ? |
This issue was noticed before: JuliaImages/Images.jl#897 (comment). No resolution, apparently. I think we're going to release with it the way it is, but the deprecation warning will tell users to convert the output to |
When I first worked on the Revisiting the implementations, it looks like we always return an index from the function partition_interval(nbins::Integer, minval::Real, maxval::Real)
return range(minval, step=(maxval - minval) / nbins, length=nbins)
end So in a nutshell, this was the origin of returning a raw number and it wasn't specifically deliberate. Looking back at the conversation Tim linked to, I noticed that Johnny pointed out the key decision that needs to be made:
I don't mind either way. We could always convert the result to function find_threshold(data::AbstractArray, f::AbstractThresholdAlgorithm ; nbins::Union{Int,Nothing} = 256)
edges, counts = build_histogram(data, nbins)
#=
The `counts` array stores at index 0 the frequencies that were below the
first bin edge. Since we are seeking a threshold over the interval
partitioned by `edges` we need to discard the first bin in `counts`
so that the dimensions of `edges` and `counts` match.
=#
return f(view(counts, 1:lastindex(counts)), edges)
end to something like: function find_threshold(data::AbstractArray, f::AbstractThresholdAlgorithm ; nbins::Union{Int,Nothing} = 256)
edges, counts = build_histogram(data, nbins)
#=
The `counts` array stores at index 0 the frequencies that were below the
first bin edge. Since we are seeking a threshold over the interval
partitioned by `edges` we need to discard the first bin in `counts`
so that the dimensions of `edges` and `counts` match.
=#
T = eltype(data)
return T.(f(view(counts, 1:lastindex(counts)), edges)) |
That works. The only case I can imagine a potential problem is for methods that might, e.g., give meaning to non-eltype values. For example, in the case where all the data points are either 0 or 1 (aka, In any event, we made "safe" choices with the Images 0.26 release: it was backwards compatible, but that doesn't prevent us from changing it in the future. So I'd be comfortable with either outcome; we should just do whatever is best. |
Is the choice of returning a
Float32
rather than aGray{N0f8}
deliberate?We can do either one, but this arises in the context of replacing
otsu_threshold
with this package in the Images 0.26 release; the implementation in Images.jl returns an element of the same type.We just need a decision of whether this is an oversight or deliberate. If it's deliberate, in the depwarn we can add an explicit
eltype(img)(find_threshold...)
.The text was updated successfully, but these errors were encountered: