You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the 2D shearing transformation matrix is defined as: $\begin{pmatrix} 1 & S_x \\ S_y & 1 \end{pmatrix}$.
However, as shearing on the x-axis is defined as $\begin{pmatrix} 1 & S_x \\ 0 & 1 \end{pmatrix}$, on the y-axis as $\begin{pmatrix} 1 & 0 \\ S_y & 1 \end{pmatrix}$, their composition is either $\begin{pmatrix} 1 + S_xS_y & S_x \\ S_y & 1 \end{pmatrix}$ or $\begin{pmatrix} 1 & S_x \\ S_y & 1 + S_xS_y \end{pmatrix}$.
Firstly, this means that if a shearing is done on both axis at the same time, the resulting operation is not a real shearing, as it is not area-preserving. Secondly, if two separate shearings are done after each other, the end result is not the same as if the transformation was done in one step.
Expected behavior
I expect the output of the composed shearing to be the same when I first shear only one axis, and then in a succinct step on another.
Proposed solution
In monai/transforms/utils.py in the _create_shear function line 988 should be changed either to out[0, 1], out[1, 0], out[1, 1] = coefs[0], coefs[1], 1 + coefs[0] * coefs[1]
or to out[0, 0], out[0, 1], out[1, 0] = 1 + coefs[0] * coefs[1], coefs[0], coefs[1]
depening on the desired order of the shearing operations.
The 3D version is also wrong, however, I did not derive the correct matrix right now.
Environment
I tested it on MONAI 0.9.0 and on MONAI 1.4.0
Edit: changed the images to make the differences easier to see.
The text was updated successfully, but these errors were encountered:
Currently, the 2D shearing transformation matrix is defined as:$\begin{pmatrix} 1 & S_x \\ S_y & 1 \end{pmatrix}$ .$\begin{pmatrix} 1 & S_x \\ 0 & 1 \end{pmatrix}$ , on the y-axis as $\begin{pmatrix} 1 & 0 \\ S_y & 1 \end{pmatrix}$ , their composition is either $\begin{pmatrix} 1 + S_xS_y & S_x \\ S_y & 1 \end{pmatrix}$ or $\begin{pmatrix} 1 & S_x \\ S_y & 1 + S_xS_y \end{pmatrix}$ .
However, as shearing on the x-axis is defined as
Firstly, this means that if a shearing is done on both axis at the same time, the resulting operation is not a real shearing, as it is not area-preserving. Secondly, if two separate shearings are done after each other, the end result is not the same as if the transformation was done in one step.
Reproduction
A very minimal example:
Expected behavior
I expect the output of the composed shearing to be the same when I first shear only one axis, and then in a succinct step on another.
Proposed solution
In monai/transforms/utils.py in the _create_shear function line 988 should be changed either to
out[0, 1], out[1, 0], out[1, 1] = coefs[0], coefs[1], 1 + coefs[0] * coefs[1]
or to
out[0, 0], out[0, 1], out[1, 0] = 1 + coefs[0] * coefs[1], coefs[0], coefs[1]
depening on the desired order of the shearing operations.
The 3D version is also wrong, however, I did not derive the correct matrix right now.
Environment
I tested it on MONAI 0.9.0 and on MONAI 1.4.0
Edit: changed the images to make the differences easier to see.
The text was updated successfully, but these errors were encountered: