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

RFC: a new API that plans algorithm with prior information before binarize #41

Closed
johnnychen94 opened this issue Jul 26, 2019 · 1 comment · Fixed by #29
Closed

RFC: a new API that plans algorithm with prior information before binarize #41

johnnychen94 opened this issue Jul 26, 2019 · 1 comment · Fixed by #29

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented Jul 26, 2019

In #30 we changed the usage of AdaptiveThreshold from

w = recommend_window_size(img)
f = AdaptiveThreshold(window_size = w, percentage = 15)
binarize(img, f)

to

f = AdaptiveThreshold(percentage = 15)
binarize(img, f)

By doing this, users no longer need to call recommend_window_size anymore, which is an improvement.

However, this isn't what we really want in the beginning, since we'd like to hold all parameters of AdaptiveThreshold inside of it.

a window_size is something that is intrinsic to an adaptive method since the existence of a window is what often differentiates global thresholding from adaptive local thresholding. A sensible choice of window_size does indeed depend on the size of the image.
-- @zygmuntszpak

As a solution, I’m keeping thinking of introducing another set of API that generate the algorithms with the “best” inferred parameters from prior information, for example, the usage could be:

# option 1
f = AdaptiveThreshold(img)
# option 2
f = algorithm_plan(:AdaptiveThreshold, img)

binarize(img, f)

The idea here is, use img to infer as much information as needed, and leave the others using the default value.

A toy implementation of option 1 could be:

AdaptiveThreshold(img::AbstractArray; kwargs...) = 
    AdaptiveThreshold(;window_size=default_AdaptiveThreshold_window_size(img), kwargs...)

P.S., a practical example of this design is used in my NonlocalMean, where we infer the best r_p (aka. window_size) using img.

@johnnychen94
Copy link
Member Author

closed by #45

johnnychen94 added a commit that referenced this issue Jul 31, 2019
Changes:

* refactor the codebase using the functor API discussed in #26
* enhance the API by introducing a submodule `BinarizationAPI`
* add in-place function `binarize!`
* support Color3 inputs
* add more test codes
* slightly enhance the documentation

Breaking changes (Deprecated in 0.3):

* swap the argument order discussed in #23 ( d1f8309)
* unexport `recommend_size` in favor of #41, i.e., `AdaptiveThreshold(img)` instead of `recommend_size(img)` ( PR: #30 #45)
* made `window_size` of `AdaptiveThreshold` not an optional argument. ( PR: #45 )
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