{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]}
這是一個包含 1、3、6、7、0、4 和 2 類影像的字典。每個鍵中的串列元素表示一個名為 x_data 的陣列中的影像索引,該陣列是一個影像陣列。
我試圖找到同一類中的影像以及其他類中的影像之間的結構相似性。
((例如將 1 類、索引 52896 影像與 1 類、索引 18945 以及與 3 類、索引 66831 等進行比較))
我想對每張圖片都這樣做
對于結構相似性,我想使用:
from skimage.metrics import structural_similarity as ssim
但是如何為Bold中的陳述句做python雜技。請幫忙。
uj5u.com熱心網友回復:
您必須遍歷每個類,并且在每個類中您必須遍歷每個 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/447791.html
上一篇:python中嵌套字典的規范化
