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

Can warp also be used as a remap like in opencv? #64

Open
jc211 opened this issue Jan 11, 2019 · 1 comment
Open

Can warp also be used as a remap like in opencv? #64

jc211 opened this issue Jan 11, 2019 · 1 comment

Comments

@jc211
Copy link

jc211 commented Jan 11, 2019

Is it possible/recommended to add an overload to warp that takes a lookup table instead of a transform. The functionality would be similar to OpenCVs remap found here.

@johnnychen94
Copy link
Member

johnnychen94 commented May 19, 2021

Absolutely, tform can be any function or function-like object that accepts StaticArrays.SVector as input and also outputs an SVector.

The default range inference does not apply to generic function, so in this case you have to specify indices as well.

A quick example:

using ImageTransformations, ImageCore, ImageShow, TestImages
using StaticArrays

function shrink_to(R0)
    function _shrink(I)
        I_first, I_last = first(R0).I, last(R0).I
        ntuple(ndims(R0)) do n
            i, from, to = I[n], I_first[n], I_last[n]
            clamp(i, from, to)
        end |> SVector
    end
end

img = testimage("cameraman")

imgs = warp(img, shrink_to(CartesianIndices((64:448, 64:448))), axes(img))

mosaic(img, imgs; nrow=1)

which gives

demo

I just came up with this very "meaningless" demo, if you have a better showcase, please share it here, or add a demo card to https://juliaimages.org/dev/examples/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants