Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The reference frame associated to an image is not the best one to perform a shear transformation #162

Open
Open
The reference frame associated to an image is not the best one to perform a shear transformation#162

Description

Shear transformations are defined here https://en.wikipedia.org/wiki/Shear_mapping.

using Images, CoordinateTransformations, ImageTransformations, Plots

function vertical_shear(a) #vertical shear because it preserves the direction e2=[0,1]
M=[1 0; tan(a) 1]
LinearMap(M)
end
img = load("xorimg.png")

imgw = warp(img, vertical_shear(p/9), fillvalue=1)


Surprise!! The vertical shear acted as an horizontal shear transformation:

function horizontal_shear(a) #preserves the horizontal direction, [1,0]
M =[1 tan(a); 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 Dxp,
yaxis Dyp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions