ImageTransformations.jl icon indicating copy to clipboard operation
ImageTransformations.jl copied to clipboard

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

Open jc211 opened this issue 6 years ago • 1 comments

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.

jc211 avatar Jan 11 '19 04:01 jc211

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/

johnnychen94 avatar May 19 '21 14:05 johnnychen94