Refactor to avoid stack overflow
This commit is contained in:
parent
58fda5eab8
commit
b8eea0e7b4
|
@ -95,21 +95,20 @@ end
|
||||||
|
|
||||||
function growcolour!(cmat::Matrix{Union{Colorant, Missing}}, metric::Colors.DifferenceMetric,
|
function growcolour!(cmat::Matrix{Union{Colorant, Missing}}, metric::Colors.DifferenceMetric,
|
||||||
refmat::Matrix{<:Colorant}, cnearest::Colorant, safethreshold::Float64,
|
refmat::Matrix{<:Colorant}, cnearest::Colorant, safethreshold::Float64,
|
||||||
pos::CartesianIndex{2})
|
initalpos::CartesianIndex{2})
|
||||||
# @info "Growing $(pos.I)"
|
seeds = [initalpos]
|
||||||
surrounding = Ref(pos) .+ CartesianIndex{2}.([(0, 1), (0, -1), (1, 0), (-1, 0)])
|
while !isempty(seeds)
|
||||||
filter!(s -> all((1,1) .<= s.I .<= size(refmat)), surrounding)
|
pos = pop!(seeds)
|
||||||
reseed = Vector{CartesianIndex{2}}()
|
surrounding = Ref(pos) .+ CartesianIndex{2}.([(0, 1), (0, -1), (1, 0), (-1, 0)])
|
||||||
for spos in surrounding
|
filter!(s -> all((1,1) .<= s.I .<= size(refmat)), surrounding)
|
||||||
# @info " @ $(spos.I)"
|
for spos in surrounding
|
||||||
if ismissing(cmat[spos]) && colordiff(cnearest, refmat[spos]; metric) < safethreshold
|
if ismissing(cmat[spos]) &&
|
||||||
cmat[spos] = cnearest
|
colordiff(cnearest, refmat[spos]; metric) < safethreshold
|
||||||
push!(reseed, spos)
|
cmat[spos] = cnearest
|
||||||
|
push!(seeds, spos)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for spos in reseed
|
|
||||||
growcolour!(cmat, metric, refmat, cnearest, safethreshold, spos)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function colour_grid_hsl(xs, ys, saturation=1)
|
function colour_grid_hsl(xs, ys, saturation=1)
|
||||||
|
|
Loading…
Reference in New Issue