您好我编写了一个代码,用于使用归一化互相关来查找图像的相似性。我收到上述错误而无法得到它。可以有人找到我的错误。提前谢谢:)
from numpy import *
from PIL import Image
from scipy import misc
import sys
import math
import numpy as np
import scipy.signal
import cv2
from cv2 import cv
path1='D:/PROJECT/database/453.png'
path2='D:/PROJECT/database/453.png'
im1=Image.open('D:/PROJECT/database/453.png')
im2=Image.open('D:/PROJECT/database/453.png')
#numpart=0
#denpart=0
numpart=[0.0,0.0,0.0,0.0]
denpart=[0.0,0.0,0.0,0.0]
pix1 = im1.load()
pix2=im2.load()
width=181
height=256
x1= misc.imread(path1)
x2= misc.imread(path2)
m1=x1.mean()
m2=x2.mean()
#print m2
for i in range(0,width):
for j in range (0,height):
y1=pix1[i,j]
y2=pix2[i,j]
nump1z1=y1-m1
nump2z1=y2-m2
n=nump1z1*nump2z1
numpart+=n
denp1z1=(y1-m1)**2
denp2z1=(y2-m2)**2
d=(denp1z1*denp2z1)
e=map(math.sqrt,d)
denpart+=e
ncc=numpart/denpart
print ncc
答案 0 :(得分:1)
非常简单,
numpart=[0.0,0.0,0.0,0.0]
...
numpart += n
你试图将n添加到numpart列表中,它不是设计为像那样工作,你可能想看看.append(),numpart.append(n)
将n加到n的结尾列表或
for number in range(0, numpart):
numpart[number] += n
取决于您需要的 也:
ncc=numpart/denpart
也不会起作用,因为它们是列表
再次,使用与我刚才用于向列表中的每个条目添加n相同的技术将在那里工作,只需使用ncc[number] = numpart[number]/denpart[number]
而不是