比较存储在字典中的不同图像
Compare Different Images Stored Inside a Dictionary
{1: [52896, 34525, 13422, 18945, 55787],
3: [66831, 32906, 44984, 18537, 51682],
6: [49239, 53087, 59521, 3221, 11184],
7: [6628, 30861, 15325, 64671, 51520],
0: [47524, 12454, 42290, 5301, 16277],
4: [48736, 6874, 49780, 25624, 25399],
2: [16923, 30581, 42236, 6380, 9681]}
这是一个包含 classes 1,3,6,7,0,4 和 2 图像的字典。每个键中的列表元素表示名为 [=26= 的数组中的图像索引], 这是一个图像数组。
我试图找到同一 class 中的图像与其他 class 中的图像之间的结构相似性。
((比如比较 Class 1,索引 52896 图像与 Class 1,索引 18945 并且还比较 Class 3,索引 66831 等等))
我想对每张图片都这样做
对于结构相似性,我想过使用:
from skimage.metrics import structural_similarity as ssim
但是如何为粗体语句做 python 技巧。
请帮忙
您必须遍历每个 class 并且在每个 class 中您将必须遍历每个 id。现在,由于您想将此与所有其他图像进行比较,因此您将不得不再次重复此操作。
for c1 in img_classes:
for i1 in img_classes[c1]:
for c2 in img_classes:
for i2 in img_classes[c2]:
# Compare image i1 of class c1 with image i2 of class c2
val = ssim(images[i1], images[i2], multichannel=True)
print(f"Comparing image {i1:5d} of class {c1} with image {i2:5d} of class {c2} || SSIM :{val:.4f}")
输出
Comparing image 47524 of class 0 with image 47524 of class 0 || SSIM :1.0000
Comparing image 47524 of class 0 with image 12454 of class 0 || SSIM :0.0111
Comparing image 47524 of class 0 with image 42290 of class 0 || SSIM :0.0431
Comparing image 47524 of class 0 with image 5301 of class 0 || SSIM :0.0237
Comparing image 47524 of class 0 with image 16277 of class 0 || SSIM :0.0302
Comparing image 47524 of class 0 with image 52896 of class 1 || SSIM :0.0179
Comparing image 47524 of class 0 with image 34525 of class 1 || SSIM :0.0316
Comparing image 47524 of class 0 with image 13422 of class 1 || SSIM :0.0217
Comparing image 47524 of class 0 with image 18945 of class 1 || SSIM :0.0186
Comparing image 47524 of class 0 with image 55787 of class 1 || SSIM :0.0180
Comparing image 47524 of class 0 with image 16923 of class 2 || SSIM :0.0123
Comparing image 47524 of class 0 with image 30581 of class 2 || SSIM :0.0165
Comparing image 47524 of class 0 with image 42236 of class 2 || SSIM :0.0122
Comparing image 47524 of class 0 with image 6380 of class 2 || SSIM :0.0400
Comparing image 47524 of class 0 with image 9681 of class 2 || SSIM :0.0173
Comparing image 47524 of class 0 with image 66831 of class 3 || SSIM :0.0180
Comparing image 47524 of class 0 with image 32906 of class 3 || SSIM :0.0178
Comparing image 47524 of class 0 with image 44984 of class 3 || SSIM :0.0121
Comparing image 47524 of class 0 with image 18537 of class 3 || SSIM :0.0112
Comparing image 47524 of class 0 with image 51682 of class 3 || SSIM :0.0208
{1: [52896, 34525, 13422, 18945, 55787],
3: [66831, 32906, 44984, 18537, 51682],
6: [49239, 53087, 59521, 3221, 11184],
7: [6628, 30861, 15325, 64671, 51520],
0: [47524, 12454, 42290, 5301, 16277],
4: [48736, 6874, 49780, 25624, 25399],
2: [16923, 30581, 42236, 6380, 9681]}
这是一个包含 classes 1,3,6,7,0,4 和 2 图像的字典。每个键中的列表元素表示名为 [=26= 的数组中的图像索引], 这是一个图像数组。
我试图找到同一 class 中的图像与其他 class 中的图像之间的结构相似性。
((比如比较 Class 1,索引 52896 图像与 Class 1,索引 18945 并且还比较 Class 3,索引 66831 等等))
我想对每张图片都这样做
对于结构相似性,我想过使用:
from skimage.metrics import structural_similarity as ssim
但是如何为粗体语句做 python 技巧。 请帮忙
您必须遍历每个 class 并且在每个 class 中您将必须遍历每个 id。现在,由于您想将此与所有其他图像进行比较,因此您将不得不再次重复此操作。
for c1 in img_classes:
for i1 in img_classes[c1]:
for c2 in img_classes:
for i2 in img_classes[c2]:
# Compare image i1 of class c1 with image i2 of class c2
val = ssim(images[i1], images[i2], multichannel=True)
print(f"Comparing image {i1:5d} of class {c1} with image {i2:5d} of class {c2} || SSIM :{val:.4f}")
输出
Comparing image 47524 of class 0 with image 47524 of class 0 || SSIM :1.0000
Comparing image 47524 of class 0 with image 12454 of class 0 || SSIM :0.0111
Comparing image 47524 of class 0 with image 42290 of class 0 || SSIM :0.0431
Comparing image 47524 of class 0 with image 5301 of class 0 || SSIM :0.0237
Comparing image 47524 of class 0 with image 16277 of class 0 || SSIM :0.0302
Comparing image 47524 of class 0 with image 52896 of class 1 || SSIM :0.0179
Comparing image 47524 of class 0 with image 34525 of class 1 || SSIM :0.0316
Comparing image 47524 of class 0 with image 13422 of class 1 || SSIM :0.0217
Comparing image 47524 of class 0 with image 18945 of class 1 || SSIM :0.0186
Comparing image 47524 of class 0 with image 55787 of class 1 || SSIM :0.0180
Comparing image 47524 of class 0 with image 16923 of class 2 || SSIM :0.0123
Comparing image 47524 of class 0 with image 30581 of class 2 || SSIM :0.0165
Comparing image 47524 of class 0 with image 42236 of class 2 || SSIM :0.0122
Comparing image 47524 of class 0 with image 6380 of class 2 || SSIM :0.0400
Comparing image 47524 of class 0 with image 9681 of class 2 || SSIM :0.0173
Comparing image 47524 of class 0 with image 66831 of class 3 || SSIM :0.0180
Comparing image 47524 of class 0 with image 32906 of class 3 || SSIM :0.0178
Comparing image 47524 of class 0 with image 44984 of class 3 || SSIM :0.0121
Comparing image 47524 of class 0 with image 18537 of class 3 || SSIM :0.0112
Comparing image 47524 of class 0 with image 51682 of class 3 || SSIM :0.0208