Первый шаг:
создать изображение эллипса относительно угла, который должен быть зафиксирован (тета), и местоположения (x, y)
найти как можно больше местоположений (x, y)
Второе:
Вычислить пространственное расстояние между пикселями эллипса и абстрактным двоичным изображением для обоих изображений с одинаковыми размерами, поскольку они должны рассматриваться как массивы
Третье:
вернуть местоположение, которое дает наибольшее пространственное расстояние (может быть Jaccard, игральные кости, Chebyshev и т. д.)
import matplotlib.pyplot as plt
from PIL import Image
from scipy.spatial import distance
import scipy.misc
im = scipy.misc.imread(r'C:\Users\mbore\Pictures\irregular1.png', flatten=False, mode='L')
def ellipse(x, y):
value = (x*x) + (y*y)/3
if (value >= 600):
return 0
else:
return 1
coordinates = []
def combinations (x,y):
dx = 5
dy = 5
return x + dx, y + dy
for x in range(0, 10): #seeting lower range
for y in range(0, 10):
coordinates.append(combinations(x,y))
for each in coordinates:
coordinates [i] = dx,dy
def translate(x, y):
return (x- dx, y - dy)
def rotate(x, y):
theta = np.radians(45)
matrix = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
return np.dot(matrix, (x,y))
data = np.zeros((100,100))
for i in range(0, 100):
for j in range(0, 100):
(x, y) = translate(i,j)
(x, y) = rotate(x, y)
data[i,j] = ellipse(x, y)
#np.append(data,ellipse(x,y))
plt.imshow(data, cmap="gray")
plt.show()
plt.imshow(im)
plt.show()
counter = 0 #tracking white
counter1 = 0 #tracking black
#getting the dimensions of the image -> y
yDim = im.shape[0]
#getting the dimensions of the image -> x
xDim = im.shape[1]
for i in range(yDim):
for j in range (xDim):
if np.any(im[i,j]) == 0:
counter += 1
else:
counter1 += 1
#initialize empty array this array will receive all the white pixels
a = np.empty([100,100])
for i in range(yDim):
for j in range (xDim):
if np.any(im[i,j]) == 0:
np.append(a,im[i,j],axis=None)
#spatial distance
a = a.flatten()
data = data.flatten()
distances = []
distances.append(distance.hamming(data,a))
combinations = []
def points (x,y):
dx = 5
dy = 5
return x + dx, y + dy
for x in range(0, 10):
for y in range(0, 10):
combinations.append(points(x,y))
print(combinations)