Skip to content

Affine transform xy - #1975

Closed
akuchibotla wants to merge 4 commits into
scikit-image:mainfrom
akuchibotla:affine_transform_XY
Closed

akuchibotla wants to merge 4 commits into
scikit-image:mainfrom
akuchibotla:affine_transform_XY

Conversation

@akuchibotla

Copy link
Copy Markdown

In efforts to address #1779

Here's a demo:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm

from skimage import transform

# Generating a square
im = np.zeros((128, 128))
im[32:-32, 32:-32] = 1

# Creating Affine Transform instances with different shearing factors
t1 = transform.AffineTransform(shear=(0, 0.25))
t2 = transform.AffineTransform(shear=(0.75, 0))
t3 = transform.AffineTransform(shear=(0.5, 0.25))

# Transform image with transform objects above
im1 = transform.warp(im, t1)
im2 = transform.warp(im, t2)
im3 = transform.warp(im, t3)

# Display results
fig, (ax1, ax2, ax3, ax4) = plt.subplots(nrows=1, ncols=4, figsize=(12, 3), sharex=True, sharey=True)

ax1.imshow(im, cmap=plt.cm.jet)
ax1.axis('off')
ax1.set_title('Original Image', fontsize=20)

ax2.imshow(im1, cmap=plt.cm.gray)
ax2.axis('off')
ax2.set_title('Shear $y=0.25$', fontsize=20)

ax3.imshow(im2, cmap=plt.cm.gray)
ax3.axis('off')
ax3.set_title('Shear $x=0.75$', fontsize=20)

ax4.imshow(im3, cmap=plt.cm.gray)
ax4.axis('off')
ax4.set_title('Shear $x=0.5 y=0.25$', fontsize=20)

fig.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9,
                    bottom=0.02, left=0.02, right=0.98)

plt.show()

figure_1

There seems to be some unwanted extra translation occurring though. Any ideas how to tackle this?

@akuchibotla

Copy link
Copy Markdown
Author

Just talked to @stefanv and the translation is expected because of the origin, so looks like it's a non-issue. I'll write up some tests for this.

@stefanv

stefanv commented Mar 3, 2016

Copy link
Copy Markdown
Member

The reason the shear goes in a slightly unintuitive direction is because the values are fractions -- if you set it to > 1, then I guess it will look as expected.


def test_matrix_transform():
tform = AffineTransform(scale=(0.1, 0.5), rotation=2)
tform = AffineTransform(scale=(0.1, 0.5), rotation=2, shear=(0.5, 2))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test both versions of shear, and make sure the pixels end up where they are supposed to. This can be done by, e.g., having a white pixel in an image, warping it, and making sure that white pixel ends up in the right place (use interpolation oder = 0)

@sciunto

sciunto commented Jul 14, 2016

Copy link
Copy Markdown
Member

@akuchibotla Did you have a chance to look at the tests?

The PR needs a rebase.

@Ethiral

Ethiral commented May 16, 2017

Copy link
Copy Markdown

Can you tell me the matrix being used in case of only shear?The code shows shear being used only in Y axis

@lagru

lagru commented Apr 7, 2023

Copy link
Copy Markdown
Member

Hey, I think this was addressed in the recently merged PR #6752. I am not sure why this stalled. Nevertheless thank you @akuchibotla for your contribution! Even though it wasn't merged in the end it is appreciated and might have informed later work. :)

@lagru lagru closed this Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Development

Successfully merging this pull request may close these issues.

6 participants