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

idea: interpolate the fillvalue #68

Open
johnnychen94 opened this issue Jun 5, 2021 · 0 comments
Open

idea: interpolate the fillvalue #68

johnnychen94 opened this issue Jun 5, 2021 · 0 comments

Comments

@johnnychen94
Copy link
Member

johnnychen94 commented Jun 5, 2021

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

  • a constant value
  • interpolating/extrapolate a list of values
  • calling a custom function like the etp here
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

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

No branches or pull requests

1 participant