ImageTransformations.jl
ImageTransformations.jl copied to clipboard
Can warp also be used as a remap like in opencv?
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.
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

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/