1

I have a dataset of images for Key point detection. Each Image got labeled with one keypoint (x|y).

I use numpy to flip images for data augmentation.

I flip an Image horizontal with this code:

img = img[:, ::-1]

And vertical with this code

 img = img[::-1]

So far so good. But I have to also recalculate the keypoints (labels) ( [85 35]) I know its basic math but i havent campe up with a solution.

Thanks in Advance.

NexusHero
  • 59
  • 6

3 Answers3

0

Use the rotation matrix:

x_new = x_old * np.cos(alpha) - y_old * np.sin(alpha)
y_new = x_old * np.sin(alpha) + y_old * np.cos(alpha)

Alpha is a roatation angle in radians, but i don't know what gives img = img[:, ::-1])))

Eugene Trofimov
  • 169
  • 1
  • 2
  • 13
  • I found this solution for flipping in this stack overflow contribution: https://stackoverflow.com/questions/47006652/python-most-efficient-way-to-mirror-an-image-along-its-vertical-axis :/ I also have to possiblitly to work with openCV, if this fits better for this problem. – NexusHero Sep 03 '18 at 11:15
0

If you flip the image horizontally then the pixel that was 85 units from the left will be 85 units from the right. The same goes for the vertical flip, 35 units from the top will be 35 units from the bottom.

So now you can either calculate the location with the help of the size img.shape of your image or you use the fact that you can access the image with negative indexes. So point [85 35] will be point [-85 35] or [width_of_image-85 35]

0

If you are flipping 180° degrees (plain vertical or horizontical) there is no need for an rotation matrix. Just get the shape of your image.

X = img.shape[1]
y = img.shape[0]

Recompute X-Position when flipping horizontally.

X_Position_New = X - X_Position_Old

Recompute Y-Position when flipping vertically.

Y_Position_New = Y - Y_Position_Old
  • This did it for me! Thank youuu. I would like to give an up vote but my reputation is too low. If you vote up the question then my reputation should be enough to mark the answer. – NexusHero Sep 03 '18 at 13:02