Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I mirror a polygon using Python?

Tags:

python

shapely

I have a set of images over which polygons are drawn. I have the points of those polygons and I draw these using Shapely and check whether certain points from an eye tracker fall into the polygons.

Now, some of those images are mirrored but I do not have the coordinates of the polygons drawn in them. How can I flip the polygons horizontally? Is there a way to do this with Shapely?

like image 517
Jancso Avatar asked Oct 21 '25 15:10

Jancso


1 Answers

by multiplying [[1,0], [0,-1]], You can get the vertically flipped shape.
(I tested this on jupyter notebook)

pts = np.array([[153, 347],
                [161, 323],
                [179, 305],
                [195, 315],
                [184, 331],
                [177, 357]])
display(Polygon(pts))
display(Polygon(pts.dot([[1,0],[0,-1]])))

jupyter_notebook_result

And If you multiply [[-1,0],[0,1]], you will get horizontally flipped shape.

Refer linear transformation to understand why this works.

like image 78
plhn Avatar answered Oct 26 '25 05:10

plhn