JuliaImages / ImageDraw.jl

Drawing Package for JuliaImages
Other
27 stars 17 forks source link

idea: interpolate the fillvalue #68

Open johnnychen94 opened 3 years ago

johnnychen94 commented 3 years ago

It would be nice to allow fill the region with multiple fillvalues:

using Interpolations, ImageCore, OffsetArrays, ImageShow
make_circle(r, fillvalues; kwargs...) = make_circle(eltype(fillvalues), r, fillvalues; kwargs...)
function make_circle(T, r, fillvalues::Vector)
    etp = extrapolate(interpolate(fillvalues, BSpline(Linear())), Line())
    sz = (2r+1, 2r+1)
    canvas = OffsetArrays.centered(Array{T, 2}(undef, sz))

    for i in CartesianIndices(canvas)
        d = sqrt(mapreduce(abs2, +, i.I))
        canvas[i] = etp(d)
    end
    return canvas
end

img = mosaic(
    mosaic(
        make_circle(256, collect(0:0.005:0.8)),
        make_circle(256, repeat(collect(0:0.002:0.8))),
        make_circle(256, repeat(collect(0:0.05:0.8), inner=30));
        rowmajor=true, nrow=1
    ),
    mosaic(
        make_circle(256, colormap("Blues")),
        make_circle(256, colormap("Blues", 256)),
        make_circle(256, colormap("Blues", 512));
        rowmajor=true, nrow=1
    )
)

image