算法的快速比较图像\矩阵矩阵、算法、图像、快速

2023-09-11 07:14:52 作者:丶上帝不曾偏爱我

有一个像(IMA)的大小10x10px多60 000图像(IMN)10×10

There is one image (imA) size 10x10px and more 60 000 images (imN) 10x10

所有图像都是黑白

找点与从所有其他人区别开的第一映像(IMA)的最低人数(IMN)的任务 - 对不起,我的英语不好,我加入IMG和评论

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

的第一件事,原来所有的图像在一个矩阵numpy的

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,颜色]颜色名单[255,255,255]

b[y,x,color] color its list [255,255,255]

A [1-60000,Y,X,颜色]

a[1-60000,y,x,color]

接下来我用一个嵌套比较,具有深度的非递归搜索在3点看起来是这样的:

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'

与此code中的问题是,它是很慢的。举例来说,我们第一个图像是从所有其他至少有五点不同:

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:

得到100! / 95! * 60 000对比 - 542,070,144,000,000

get 100! / 95! * 60 000 comparisons - 542,070,144,000,000

不错,我用一个稍微不同的算法,它可以让你把它变成: 40!/ 35!* 60000 = 4.737.657.600.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.

更新添加IMG

0线:3其他图像(IMN)4×4

0 line: 3 other image (imN) 4x4

1线:0模板图像(IMA)和1-3图像,其中红色的显着差异(IMA XOR IMN)

1 line: 0 template image (imA) and 1-3 image where the red marked difference (imA XOR imN)

2行:0图片其中蓝色标记两个点两个点进行比较,

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号线:像2号线的其他点

3 line: like line 2 the other dots

4行:我们选择了两个点,就足以说,IMA不同于IMN(1-3)

4 line: We chose two dots is enough to say that imA differs from imN(1-3)

推荐答案

如果我正确地理解你的问题,你需要计算的第一张照片,这是从不同的点的数量所有的其他的照片,而不考虑其他的图片彼此有何不同​​?

If I understand your question correctly, you need to calculate the number of points on the first picture, which is different from all the other pictures, irrespective of how the other pictures differ from each other?

如果这个情况下,除非我失去了一些东西,你能不能简单地做一些这样的:

If this is case, unless I'm missing something, can you not simply do something like the following:

boolean[10][10] DIFFS // all values set to TRUE
int[10][10] ORIGINAL  // store first pictures color values

foreach IMAGE in [IMAGES - FIRST IMAGE] {
    int[10][10] CURRENT <- IMAGE // store the current image's color values
    for (i : 0 -> 9) {
        for (j : 0 -> 9) {
            if (DIFFS[i][j]) {
                DIFFS[i][j] = ORIGINAL[i][j] != CURRENT[i][j]
            }
        }
    }
}

然后,只剩下一个2维矩阵 DIFFS 其中每个位置表示如果在原始图像中的对应像素不同于所有其他图像

Then you are left with a 2-dimensional matrix DIFFS where each position indicates if the corresponding pixel in the original image differs from all the other pictures.