# How to calculate the angle rotated of the cut out image?

## Question:

I have a 200*200 square image, now I draw a circle of 100 diameter with the center of this image as the center, cut this image into two parts along the circle, rotate this circle image by a certain angle and save it as circle.jpg and save the rest as background.jpg. Now what algorithm do I need to calculate How much angle do I need to rotate circle.jpg in order to combine it with background.jpg to form the original image? Is it possible to do this using opencv?

background.jpg: circle.jpg: I don’t know if there’s a algorithm ready to use. But it should be fun inventing your own.

Let your algorithm walk on the edge of pixels: Then let it walk the same way on the other image: The length (number of pixels) should be the same, so you can put them on top of each other and calculate the difference in color. Next, shift pixels to the right until you get the least difference in pixel color. Here are my code which solve the above problem perfectly. Thanks to Thomas Weller again.

``````import cv2
import numpy as np
import os

ARRAY_LENGTH = 785 # resolution

center = img.shape // 2, img.shape // 2
angles = np.linspace(0, 2 * np.pi, ARRAY_LENGTH, endpoint=False)
x = center + radius * np.cos(angles + offset)
y = center + radius * np.sin(angles + offset)
pixels = img[x.astype(int), y.astype(int)]
return pixels

def match(bg_path, cut_path):