I am trying to create a matrix whose elements are the distances to a curve that I have defined (code below):
I want to perform some manipulation on this image which gives me a matrix containing all of the minimum Euclidean distances between that point and any point on the spiral.
I have tried using scipy
's ndimage.distance_transform_edt
like so:
import scipy.ndimage as ndi
transformed = ndi.distance_transform_edt(spiral())
But the output does not give me what I'm looking for!
Does anyone know how to generate this matrix?
Code for spiral generation below:
import numpy as np
import matplotlib.pyplot as plt
def pol2cart(rho, phi):
# https://stackoverflow.com/questions/20924085/python-conversion-between-coordinates
x = rho * np.cos(phi)
y = rho * np.sin(phi)
return(y, x)
def spiral():
C = 0.15
phi = np.linspace(6, 540, 1000)
rho = (1 - C * np.log(phi - 5))
# Now convert back to x, y coordinates
y, x = pol2cart(rho, np.deg2rad(phi))
# Center the spiral so we can see it better.
x -= x.min()
y -= y.min()
x += 1
y += 1.5
m = np.zeros((100, 100))
for i in range(len(x)):
try:
# Include some scaling factor to increase the size of the curve
m[int(x[i]*30), int(y[i]*30)] = 1
except IndexError:
continue
return m
plt.imshow(spiral())