There is one image (imA) size 10x10px and more 60 000 images (imN) 10x10
All images are black and white
The task of finding the minimum number of points with which to distinguish the first image (imA) from all others (imN) - sorry for my bad English, I add img and comment
The first thing I did, it turned all the images in a matrix with numpy
q=0
for file in inputImages:
eachImage = os.path.join(generatorFolder, file)
a[q]=numpy.asarray(Image.open(eachImage))
q+=1
b=numpy.asarray(Image.open(templateimage))
b[y,x,color] color its list [255,255,255]
a[1-60000,y,x,color]
Next I use a nested comparison, non-recursive search with depth in 3-point looks something like this:
for y1 in range(b.shape[0]):
for x1 in range(b.shape[1]):
for y2 in range(b.shape[0]):
for x2 in range(b.shape[1]):
for y3 in range(b.shape[0]):
for x3 in range(b.shape[1]):
if y1==y2==y3 and x1==x2==x3:continue
check=0
for a_el in range(a.shape[0]):
if numpy.array_equal(b[y1,x1],a[a_el,y1,x1]) and \
numpy.array_equal(b[y2,x2],a[a_el,y2,x2]) and \
numpy.array_equal(b[y3,x3],a[a_el,y3,x3]):
check=1
break
if not check:return 'its unic dots'
The problem with this code is that it is very slow. For instance, we first image is different from all others at least five points:
get 100! / 95! * 60 000 comparisons - 542,070,144,000,000
True, I use a slightly different algorithm, which allows you to turn this into: 40!/35!*60000 = 4.737.657.600.000 that not too little.
Is there a way to solve my problem more beautiful, and not brute force.
UPDATE add img
0 line: 3 other image (imN) 4x4
1 line: 0 template image (imA) and 1-3 image where the red marked difference (imA XOR imN)
2 line: 0 image where the blue marked two dots two points for comparison,
1 image green its difference, red its compare - difference yes - NEXT
2 image red its compare - difference NO - Break (these two points is not enough to say that imA differs from imN(2))
3 line: like line 2 the other dots
4 line: We chose two dots is enough to say that imA differs from imN(1-3)