Skip to content

Allow homogeneous coordinate transforms in affine_transform #7182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 25, 2017

Conversation

jni
Copy link
Contributor

@jni jni commented Mar 15, 2017

There was some discussion in #2255 (comment) about including support for homogeneous coordinate transforms by detecting the shape of the transformation matrix as being 1 + the dimensionality of the image. This implements that change. Hopefully I haven't broken 50 things in the process. =P

@pv
Copy link
Member

pv commented Mar 21, 2017

Test failures.

The main change probably is OK, assuming the offset is applied in the correct order...
The documentation (and maybe examples) probably should also be updated.
In the extended call, maybe check if the last row is all 0 0 0 1.

@pv pv added the needs-work Items that are pending response from the author label Mar 21, 2017
@jni
Copy link
Contributor Author

jni commented Mar 22, 2017

@pv I think I've addressed your comments. I tested the functions manually for a translation -> rotation -> translation sequence to get a rotation about the center. Splitting the resulting homogeneous matrix as is done in the PR gave the correct result using affine_transform.

The scipy.special.orthogonal errors appear unrelated to this PR, am I right there?

@jni
Copy link
Contributor Author

jni commented Mar 22, 2017

Here's the code I used to check that the offset is used correctly in the PR:

import numpy as np
from scipy import ndimage as ndi
from skimage import data

camera = data.camera()
θ = np.deg2rad(30)
C = np.cos
S = np.sin

T0 = np.array([[1, 0, -256], [0, 1, -256], [0, 0, 1.]])
Rot = np.array([[C(θ), -S(θ), 0], [S(θ), C(θ), 0], [0, 0, 1]])
T1 = np.array([[1, 0, 256], [0, 1, 256], [0, 0, 1.]])

Forward = T1 @ Rot @ T0
Inverse = np.linalg.inv(Forward)

camera_rot = ndi.affine_transform(camera, Inverse[:2, :2], Inverse[:2, 2], order=1)

plt.imshow(camera_rot)

Result:

figure_1

@pv pv removed the needs-work Items that are pending response from the author label Mar 22, 2017
@pv
Copy link
Member

pv commented Mar 22, 2017

I think the change is fine, but there are some test failures on travis (test_affine_transform26, test_affine_transform27)

@pv
Copy link
Member

pv commented Mar 22, 2017

Also, the text The given matrix and offset are used ... in docstring probably should be moved to Notes, and adding a paragraph there about the extended affine transform matrices could be useful, even if this is a standard convention.

@jni
Copy link
Contributor Author

jni commented Mar 23, 2017

@pv Thanks for the review! Let's hope third time's the charm! =)

@jni
Copy link
Contributor Author

jni commented Mar 25, 2017

Oooh Travis is happy. That's a first. =P

@pv pv merged commit bcbb938 into scipy:master Mar 25, 2017
@pv pv added this to the 1.0 milestone Mar 25, 2017
@jni jni deleted the homogeneous branch March 25, 2017 18:14
@matthew-brett
Copy link
Contributor

Great - thanks for doing this - it's a very nice addition.

@stefanv
Copy link
Member

stefanv commented Mar 25, 2017

Thank you, Juan; this will certainly lead to more elegant SciPy use downstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants