Closed
Description
Currently it is not possible to invert a perspective transformation:
julia> inv(PerspectiveMap())
ERROR: Inverse transformation for PerspectiveMap has not been defined.
and composition is problematic when combined with a projective transformation (see on slack or on zulip).
The MWE in those links is detailed here as well:
using Images, CoordinateTransformations, Makie, TestImages, StaticArrays
using Makie.AbstractPlotting.MakieLayout
fliprotate(img) = rotr90(img)[:, end:-1:1] # images needed to be rotated and vertically flipped to show correctly on Makie
img = fliprotate(testimage("mandrill"))
point = SVector(175.0, 59.0) # the left eye
push1(x) = push(x, 1) # see Tim Holy's answer for why this is needed: https://stackoverflow.com/questions/45772848/perspective-warp-an-image-in-julia/45782741#45782741
T = Translation(SVector(-100,0,0)) # this is the additional correction I need
M = LinearMap(SMatrix{3,3}([1.3 0.1 0.4; 0.1 1.22 0.33; 0.001 0.0 1]))
tform = PerspectiveMap() ∘ inv(M) ∘ inv(T) ∘ push1
itform = PerspectiveMap() ∘ M ∘ T ∘ push1
indices = ImageTransformations.autorange(img, tform)
imgw = warp(img, itform, indices);
pointw = tform(point)
scene, layout = layoutscene(0)
ax1 = layout[1, 1] = LAxis(scene, aspect = DataAspect(), yreversed = true)
image!(ax1, img)
opts = (; color = :transparent, strokecolor = :white, markersize = 10px, strokewidth = 2)
scatter!(ax1, point; opts...)
ax2 = layout[1, 2] = LAxis(scene, aspect = DataAspect(), yreversed = true)
image!(ax2, UnitRange.(axes(imgw))..., parent(imgw))
scatter!(ax2, pointw; opts...) # note how the marker is a bit off
linkaxes!(ax1, ax2)
scene
Metadata
Metadata
Assignees
Labels
No labels