I am trying to find the locations of objects across 3 overlayed images. Essentially I take an image in 3 different spectrums and overlay them for data extraction of concentrations. I run a circle analysis on it and then compare each item to see if it is close enough to be overlapping. The below algorithm is working but the number of comparisons makes this algorithm run for around 2 mins each time and I need it to be something like 1-5 seconds each time as I have to do hundreds of the comparisons in the final product.
I am midway in trying more complex algorithms but thought I would ask since there may be a much simpler way and I am overthinking it.
My lists are on average 100-500 items long.
"Better" algorithms:
divide the images into multiple overlapping sectors and doing the same comparison in each region then filtering out the overlap. I have done something similar before but the final filter was exceedingly complicated.
Sort all 3 lists into a single list that is "diagonally" sorted and comparing each item to one or two away from its location. Currently, my sorting algorithm is to slow to be useful and I can't fix the "localization" problem.
(Currently the forerunner) I am taking the 3 images mixing them into one, overlaying my previous detection algorithm, taking the average color of the feature, and then running a clustering algorithm to separate it.
circles_array = [[circles_blue, len(circles_blue)], [circles_green, len(circles_green)], [circles_grey, len(circles_grey)]]
circles_array = sorted(circles_array, key=lambda x: x[1], reverse=True)
shortest = circles_array[2][0]
middle = circles_array[1][0]
longest = circles_array[0][0]
# CLASSIFYwhe
perfect_drops = 0
perfect_list = []
print("Running sort, please wait...")
for s in shortest:
for m in middle:
for l in longest:
if s[1] < m[1]+50 and s[1] > m[1]-50:
if s[1] < l[1]+50 and s[1] > l[1]-50:
if s[0] < m[0]+50 and s[0] > m[0]-50:
if s[0] < l[0]+50 and s[0] > l[0]-50:
perfect_drops += 1
perfect_list.append([s,m,l])
EXAMPLE INPUTS



