-
Notifications
You must be signed in to change notification settings - Fork 17
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
WIP: Flood Fill Implementation #60
base: master
Are you sure you want to change the base?
Conversation
When I don't specify a kwarg in the algorithm( which will be really optional for FloodFill as it won't really need it unless we make it to be so), Ambiguity error is thrown. The draw in core.jl is very general, so there is that. julia> res = draw(img, verts, FloodFill(350,200,fill_value =RGB(0), current_value = img[200,350]))
ERROR: MethodError: draw(::Matrix{RGB{FixedPointNumbers.N0f8}}, ::Vector{CartesianIndex{2}}, ::FloodFill{RGB{FixedPointNumbers.N0f8}}) is ambiguous. Candidates:
draw(img::AbstractMatrix{T}, args...) where T<:Colorant in ImageDraw at /home/ashwani/julia-related/ImageDraw.jl/src/core.jl:385
draw(img::AbstractArray{var"#s36", N} where var"#s36"<:Colorant, verts::Array{CartesianIndex{N}, 1}, f::ImageDraw.AbstractPolyFillAlgorithm; kwargs...) where N in ImageDraw at /home/ashwani/julia-related/ImageDraw.jl/src/polygonfill2d.jl:118
Possible fix, define
draw(::AbstractMatrix{T}, ::Vector{CartesianIndex{2}}, ::ImageDraw.AbstractPolyFillAlgorithm) where T<:Colorant
Stacktrace:
res = draw(img, verts, FloodFill(350,200,fill_value =RGB(0), current_value = img[200,350]);closed=true) user need to specify the draw like this for current _value, otherwise it won't work. We are not able to set default value in constructor as it doesn't have access to img/res during object creation. It would be better if we set it internally though to avoid error. FloodFill(x::Int = 1, y::Int = 1; fill_value::Colorant = RGB(1), current_value::Colorant = res[y, x]) = FloodFill(x, y, fill_value, current_value)
FloodFill(p::CartesianIndex{2}; fill_value::Colorant = RGB(1), current_value::Colorant = res[y,x]) = FloodFill(p[1], p[2], fill_value, current_value)
julia> res = draw(img, verts, FloodFill(350,200,fill_value =RGB(0));closed=true)
ERROR: UndefVarError: res not defined
Stacktrace:
[1] top-level scope
@ REPL[42]:1
And we can't change it inside the program as it's immutable(with setfield we can) but it needs to specified at the start as it only needs initial color value of seed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I don't specify a kwarg in the algorithm( which will be really optional for FloodFill as it won't really need it unless we make it to be so), Ambiguity error is thrown.
It looks like the ambiguity is triggered because the type annotation of img
is not the same; so Julia can't figure out an order here.
Does this patch fix it?
- draw(img::AbstractArray{T,2}, args...) where {T<:Colorant} = draw!(copy(img), args...)
+ draw(img::AbstractArray{T}, args...; kwargs...) where {T<:Colorant} = draw!(copy(img), args...; kwargs...)
src/polygonfill2d.jl
Outdated
x::Int, | ||
y::Int, | ||
) where {T<:Colorant} | ||
if (res[y, x] != f.current_value || res[y, x] == f.fill_value) return end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get current_value
through something like res[x, y]
(or res[y,x]
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that can be done. We want to set the value of current_value at time when struct creation is called, but at that time res is not accessible to struct . There will be quick way to solve it 😄 , I need to lookup .
) where {T<:Colorant} | ||
if (res[y, x] != f.current_value || res[y, x] == f.fill_value) return end | ||
) where {T<:Colorant, N} | ||
if (res[y, x] != f.current_value || res[y, x] == f.fill_value) return res end | ||
if checkbounds(Bool, res, y, x) res[y, x] = f.fill_value end | ||
f(res, verts, x + 1, y) | ||
f(res, verts, x - 1, y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can still be {T, 2}
as the implementation is specified for matrix; this won't affect the method ambiguity on draw
so no need to change.
Initial Base
Tasks: