Hi,

Ok, Johannes answer seemed to work, thank you! There’s a bit of brainstorming 
to find out how to reshape the coordinates etc… so below is my solution if this 
can help someone :

               import skimage.transform as tf

               # estimate the transformation matrix from control points before 
(pts2) and after (pts1) distortion
               M=tf.estimate_transform('polynomial',pts2,pts1,order=3)

                # subimage
                sub = im[yl:yr,xl:xr]

                # get new coordinates for the subset image
                coords=np.mgrid[yl:yr,xl:xr]

                # coords must be shape (2,N) + order (x,y) not (y,x) for 
passing to transformation matrix
                coords = np.array((coords[1].ravel(),coords[0].ravel())).T

                # new coordinates
                coords_out = M(coords)

                # now shift the coordinates to take into account image cropping
                yy = coords_out[:,1].reshape(sub.shape)
                xx = coords_out[:,0].reshape(sub.shape)
                xx -= xl
                yy -= yl
                transf_coords = np.array((yy,xx))

                # image warping
                out_sub=tf.warp(sub,transf_coords,preserve_range=True)


Robert, I didn’t know PyTables but I’ll have a look as it can always be useful.

Amaury



Below is the 
> On Oct 6, 2016, at 23:39, Johannes Schönberger <j...@demuc.de> wrote:
> 
> You can do this by iterating over windows of your image with the
> following (pseudo-)code:
> 
> M = tf.estimate_transform('polynomial',pts2,pts1,order=3)
> 
> for minr in range(0, image.shape[0], window_size):
>    for minc in range(0, image.shape[1], window_size):
>        coords = M(np.array(np.mgrid[minr:minr+window_size,
>        minc:minc+window_size]))
>        transformed_coords = M(coords)
>        # TODO: reshape transformed_coords into the correct size, refer
>        to tf.warp_coords for an example.
>        total_output_image[window_bbox] = warp(image,
>        transformed_coords, ...)
> 
> I hope it is clear what I mean here? I don't have more time at the
> moment...
> 
> On Fri, Oct 7, 2016, at 02:06 AM, Amaury Dehecq wrote:
>> Hello everyone,
>> 
>> I'm using skimage to correct distortions on an image, using a polynomial 
>> transformation. Basically, my commands can be summarized to:
>> 
>>         import skimage.transform as tf
>> 
>>         # estimate the transformation matrix from control points before 
>> (pts2) and after (pts1) distortion
>>         M=tf.estimate_transform('polynomial',pts2,pts1,order=3)
>> 
>>         # warp the initial image im
>>         warped=tf.warp(im,M)
>> 
>> This does exactly what I want, except that my image is very large (35000 
>> x 35000) and the script crashes if I try to run it for the whole image.
>> So I thought I could just cut my image into subimages and run warp for 
>> each subimage. But as the matrix indexes are shifted (e.g always in the 
>> interval [0-5000] instead of [0-350000]), I end up applying the same 
>> correction to each subimage.
>> Is there a way to take into account the fact that my matrix is a subset, 
>> for example by indicating the actual coordinates instead of using the 
>> matrix indexes? (Like in the MatLab function imwarp using argument RA if 
>> that helps understanding)
>> 
>> Thanks a lot,
>> 
>> Amaury
>> 
>> _______________________________________________
>> scikit-image mailing list
>> scikit-image@python.org
>> https://mail.python.org/mailman/listinfo/scikit-image
> _______________________________________________
> scikit-image mailing list
> scikit-image@python.org
> https://mail.python.org/mailman/listinfo/scikit-image

_______________________________________________
scikit-image mailing list
scikit-image@python.org
https://mail.python.org/mailman/listinfo/scikit-image

Reply via email to