-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Shear transformations are defined here https://en.wikipedia.org/wiki/Shear_mapping.
using Images, CoordinateTransformations, ImageTransformations, Plots
function vertical_shear(α) #vertical shear because it preserves the direction e₂=[0,1]
M=[1 0; tan(α) 1]
LinearMap(M)
end
img = load("xorimg.png")
imgw = warp(img, vertical_shear(π/9), fillvalue=1)

Surprise!! The vertical shear acted as an horizontal shear transformation:
function horizontal_shear(α) #preserves the horizontal direction, [1,0]
M =[1 tan(α); 0 1]
LinearMap(M)
end
I spent two hours to find out why this simple linear map led to an unexpected effect.
Since the shear transformation reversed the vertical to the horizontal preserved direction,
and conversely, I concluded that in the warp implementation, the image is referenced by default to the system
of coordinates with origin at the upper-left corner, the left side is xaxis, and the top side is yaxis,
i.e. for a pixel in the position (i, j), x=i, y=j.
This particular system of coordinates works well in the case of rotations, because the rotation has no invariant direction.
But it doesn't work for a vertical and horizontal shear, because xaxis isn't associated to the horizontal direction, and yaxis to the vertical one.
In order to get the right shear, as well as any linear or affine transformation of an image,
that image should be referenced to the orthonormal frame with origin D, as in the next figure, xaxis Dxₚ,
yaxis Dyₚ

To check my hypothesis I wrote the same code in Python, to performe the shear transformation
via scipy.ndimage, and got the right transformed image.
