I have a grey scale image with a red contour scored ontop of it (all contained in one image file). I have searched for pixels in this red contour by defining some threshold and limiting r,g,b values to count as a red pixel. The search for these pixels happens left to right, top to bottom through the image array - so the points in the contour aren't listed in any meaningful order.
I would like to implement an alogrithm that finds the visually clear path through these contour points. My initial thought was to order the contour points by their polar angle from the centroid (blue) of the points, however if the contour slightly doubles back on itself then this doesn't make sense (pictured below).
Are there python libraries/functions for this kind of problem, or does anyone have insight as to a good algorithm to try and implement?
Here is an example image:
And my code to find red pixels:
r_thres = 0.39
g_lim = 0.25
b_lim = 0.25
red_pixels = np.where((cine_image[:,:,0] >= r_thres) &
(cine_image[:,:,1] <= g_lim) & (cine_image[:,:,2] <= b_lim))
red_pixels_y = [ red_pixels[0][i] for i in range(0,
len(red_pixels[0]))]
red_pixels_x = [ red_pixels[1][i] for i in range(0, len(red_pixels[1]))]
red_pixels_coords = [ [ red_pixels[1][i] , red_pixels[0][i]] for i in
range(0, len(red_pixels[1]))]