Hi Sid

Sorry, I think you've been a victim of a known
inconsistency---unfortunately, one I'm not sure how to address.

The transforms module uses a (x, y) coordinate convention to be consistent
with most of the warping literature out there.  But the rest of
scikit-image uses  a (row, column) convention.

The following code works for me:

from skimage import io, transform
import numpy as np

image = io.imread('image.jpg')
h, w = image.shape[:2]

rng = np.random.RandomState(0)
xs = rng.randint(0, w - 1, 76)
ys = rng.randint(0, h - 1, 76)

src_pts = np.column_stack([xs, ys])
dst_pts = src_pts

tform = transform.PiecewiseAffineTransform()
tform.estimate(src_pts, dst_pts)

out = transform.warp(image, tform)

import matplotlib.pyplot as plt
plt.imshow(out)
plt.show()

Best regards
Stéfan


On 7 July 2016 at 00:37, Sid <sid.zid...@gmail.com> wrote:

> Hi
>
> I have two images of faces, the source image and the destination image.
> For each face, I have a set of x and y coordinates stored in two separate
> numpy arrays. These coordinates correspond to various facial features, as
> well as the four corners of the image, and points on half the length of the
> borders.
>
> I want to warp the features of the source image onto the destination, such
> that the corresponding control points in each image are aligned. I used the
> PiecewiseAffineTransform method, as in the example here
> <http://scikit-image.org/docs/dev/auto_examples/transform/plot_piecewise_affine.html>
> .
>
> My code is:
>
> src_pts = # numpy array of coordinates for the source image
> dst_pts = # numpy array of coordinates for the destination image
>
> image = # image of dimensions (550, 420, 3)
>
> tform = skimage.transform.PiecewiseAffineTransform()
> tform.estimate(src_pts, dst_pts)
>
> out = skimage.transform.warp(image, tform)
>
>
> I get an image that is warped but also cropped. To see if I could get the
> code to work (in case there were errors in my control points), I tried
> warping the image using the same control points for the source and
> destination.
>
> tform.estimate(src_pts, src_pts)
>
> The output is still cropped and is also warped slightly, as can be seen in
> the attached images. Logically, it doesn't make sense as there should not
> be any warping since I am using the same points. A big difference between
> the example and my implementation is that the example has uniformly spaced
> points, whereas I have 76 points which are much more sparse. Is this the
> right function to achieve what I want or should I be using something else?
>
>
> Thanks
>
> --
> Sid
>
>
>
>
>
>
> <https://lh3.googleusercontent.com/-noDhRC6CbkE/V34EvUCZgtI/AAAAAAAACFc/8-Q5D7-2EO0S_E0EVlFHxwTtusPd5wcDwCLcB/s1600/image.jpg>
>
> <https://lh3.googleusercontent.com/-7PTIVXGCCg8/V34E2M6yEUI/AAAAAAAACFg/z2zoGOPHTNss6n7hTaRRkiWToqlhwZtPgCLcB/s1600/out.jpg>
>
> <https://lh3.googleusercontent.com/-7PTIVXGCCg8/V34E2M6yEUI/AAAAAAAACFg/z2zoGOPHTNss6n7hTaRRkiWToqlhwZtPgCLcB/s1600/out.jpg>
>
> <https://lh3.googleusercontent.com/-7PTIVXGCCg8/V34E2M6yEUI/AAAAAAAACFg/z2zoGOPHTNss6n7hTaRRkiWToqlhwZtPgCLcB/s1600/out.jpg>
>
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scikit-image+unsubscr...@googlegroups.com.
> To post to this group, send email to scikit-image@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/scikit-image/e51ad552-af63-49e0-afbc-2d4b5597d5e4%40googlegroups.com
> <https://groups.google.com/d/msgid/scikit-image/e51ad552-af63-49e0-afbc-2d4b5597d5e4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"scikit-image" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to scikit-image+unsubscr...@googlegroups.com.
To post to this group, send an email to scikit-image@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/scikit-image/CABDkGQm%3D23n8J6Ys3ath2jWp%3DAHiFaAZvu2pmkrECGJxXT4s-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to