Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python在两个不同的图像中查找两个相同的像素(颜色值)_Python_Image_Dictionary - Fatal编程技术网

如何使用Python在两个不同的图像中查找两个相同的像素(颜色值)

如何使用Python在两个不同的图像中查找两个相同的像素(颜色值),python,image,dictionary,Python,Image,Dictionary,我的问题略有变化–请参阅下面的更新 我想用Python比较两个不同的图像。目的是找到两幅图像中存在的像素颜色值 我写了一个小程序来收集图像中所有的像素颜色值。现在我有一个dictionary/output.txt,它看起来像这样: {"pixels": [[232, 251, 255], [231, 250, 254], [230, 249, 253], [230, 249, 252], [230, 250, 251], [230, 249, 254], [230, 249, 255], [23

我的问题略有变化–请参阅下面的更新

我想用Python比较两个不同的图像。目的是找到两幅图像中存在的像素颜色值

我写了一个小程序来收集图像中所有的像素颜色值。现在我有一个dictionary/output.txt,它看起来像这样:

{"pixels": [[232, 251, 255], [231, 250, 254], [230, 249, 253], [230, 249, 252], [230, 250, 251], [230, 249, 254], [230, 249, 255], [230, 250, 255], [228, 250, 254], [228, 249, 254], [228, 249, 254], [229, 248, 252], [230, 249, 253], [230, 249, 253], [231…}
{
0: {'hex': ['#c3d6db', '#c7ccc0', '#9a8f6a', '#8a8e3e'], 'filename': 'imag0'}, 
1: {'hex': ['#705b3c', '#6a5639', '#442f1e', '#4a3d28'], 'filename': 'img-xyz'},
…
}
现在我的问题是:如何将这些值与其他图像的值进行比较,并查看其中是否有相同的颜色值

谢谢

更新

我想更新我的初始问题。我现在有两个(或多或少复杂的)列表。第一个包含十六进制的图像名称和图像像素颜色。看起来是这样的:

{"pixels": [[232, 251, 255], [231, 250, 254], [230, 249, 253], [230, 249, 252], [230, 250, 251], [230, 249, 254], [230, 249, 255], [230, 250, 255], [228, 250, 254], [228, 249, 254], [228, 249, 254], [229, 248, 252], [230, 249, 253], [230, 249, 253], [231…}
{
0: {'hex': ['#c3d6db', '#c7ccc0', '#9a8f6a', '#8a8e3e'], 'filename': 'imag0'}, 
1: {'hex': ['#705b3c', '#6a5639', '#442f1e', '#4a3d28'], 'filename': 'img-xyz'},
…
}
第二个字典包含大量十六进制值作为键,id作为值。它看起来像:

{'#b0a7aa': '9976', '#595f5b': '19367', '#9a8f6a': '24095'…}
现在我想做的是查看我的图像(第一个列表)中是否有一个颜色值与第二个列表中的一个匹配。如果是这样,那么我想知道第一个列表中的文件名,以及第二个列表中匹配键的值id


我怎样才能做到这一点

我首先尝试将列表列表转换为一组元组:

>>> t1 = {(r,g,b) for [r,g,b] in p1}
>>> t2 = {(r,g,b) for [r,g,b] in p2}
然后使用相交方法:

>>> t1.intersection(t2)
set([(231, 250, 254)])

与其从其他程序返回列表列表,不如返回一组元组

set.intersection(pixels(image1), pixels(image2))

查找两幅图像中存在的所有像素。

另一幅图像的列表在哪里?谢谢。我知道你已经把它转换成了一组元组。现在我认为最好将它们作为十六进制代码,而不是rgb值。如何轻松更改所有值?