How to calculate the distance to a pixel


I have an image in numpy.ndarray. The aim is to calculate the distance from the center of image to a darkest pixel. Image shape = (717, 717), pixel range = (-0.812, 0.895).

P.s. It’s a normalized cross-correlation output.

enter image description here


If the darkest means the minimum then you can get the corrdinate of the minimum with x_min,y_min = np.unravel_index(np.argmin(array),array.shape) (found from this post)
then get the center coordinate with

x_c = array.shape[0] / 2 
y_c = array.shape[1] / 2

then you get the distance (in pixels) with

d = np.sqrt( (x_c-x_min)**2 + (y_c-y_min)**2 )

Answered By – Apo

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.