-
Notifications
You must be signed in to change notification settings - Fork 8
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
Filter specification: an alternative to binarize
#26
Comments
I like that a lot! (Design B) |
I will work on refactoring the code incorporating all the suggestions from this and related issues. |
The idea behind design B is that we treat More generally, we can support both of the following two specifications -- I can't see a reason to support one and deprecate another one.
abstract type Filter end
abstract type Binarizer <: Filter end
struct Otsu <: Binarizer end
function (filter::Otsu)(img)
...
end
abstract type Algorithm end
abstract type BinarizationAlgorithm end
struct Otsu <: BinarizationAlgorithm end
function binarize(algo::Otsu, img)
...
end |
Based on current codebase, it would be quite trivial to support the other (filter::BinarizationAlgorithm)(img) = binarize(filter, img) But a more natural way to write code, IMO, is design B, # ImageBinarization.jl
abstract type Filter end
abstract type Binarizer <: Filter end
binarize(filter::Binarizer, img) = filter(img)
# otsu.jl
struct Otsu <: Binarizer end
function (filter::Otsu)(img)
...
end Mostly, it's just about how we start to think and build things up from the beginning. Except, there does exist a minor difference: |
I guess we should consider how many other image processing operations can be cast in this form. Ideally, we would like to have a consistent way of doing things for different operations, i.e. edge detection, contrast adjustment etc. |
binarize
binarize
Just came up with another difference:
So to be more accurate, binarize(some_name, img) is equivalent to if some_name isa BinarizationAlgorithm
some_name(img)
end For this reason, the filter specification might be slightly more bug-prone and slightly less-understandable to end-user. And it makes documenting easier, we don't need the workaround mentioned in JuliaImages/Images.jl#790 (comment) If we agree on this, then a better way of design might be:
|
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 )
closed by #29 |
The current design is
The usage is
Actually, there's an alternative design, which is commonly used in Flux.jl AFAIK
The usage is:
In design A, two different algorithms are connected in two ways:
BinarizationAlgorithm
andbinarize
. In design B, they're only connected byBinarizationAlgorithm
.According to the naming guide https://github.com/JuliaImages/Images.jl/issues/767, we should use
binarize
But I guess there would be some cases Design B is more natural.
Any ideas?
The text was updated successfully, but these errors were encountered: