Hello i have written a code to find similarity of images using normalized cross correlation. I am getting the above error and not able to get it.Could anyone find what s my error. Advance Thanks :)
你好,我已经写了一段代码,通过标准化的交叉关联来发现图像的相似性。我得到了上面的错误,无法得到它。谁能找到我的错误。提前谢谢:)
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
1 个解决方案
#1
1
quite simply,
很简单,
numpart=[0.0,0.0,0.0,0.0]
...
numpart += n
you are trying to add n to a list which is numpart, it is not designed to work like that, you may want to look at .append(), which numpart.append(n)
would add n to the end of the list or
您试图将n添加到一个列表中,该列表是numpart,它不是这样设计的,您可能想要查看.append(),它是numpart.append(n)将n添加到列表的末尾或。
for number in range(0, numpart):
numpart[number] += n
depending on which you need also:
取决于你需要什么:
ncc=numpart/denpart
will also not work as they are lists
也不会像列表一样工作?
again, using the same technique as i just used for adding n to each entry in the list will work there, just using ncc[number] = numpart[number]/denpart[number]
instead
同样,使用和我刚才在列表中的每个条目中添加n一样的技术,只需要使用ncc[number] = numpart[number]/denpart[number]。
#1
1
quite simply,
很简单,
numpart=[0.0,0.0,0.0,0.0]
...
numpart += n
you are trying to add n to a list which is numpart, it is not designed to work like that, you may want to look at .append(), which numpart.append(n)
would add n to the end of the list or
您试图将n添加到一个列表中,该列表是numpart,它不是这样设计的,您可能想要查看.append(),它是numpart.append(n)将n添加到列表的末尾或。
for number in range(0, numpart):
numpart[number] += n
depending on which you need also:
取决于你需要什么:
ncc=numpart/denpart
will also not work as they are lists
也不会像列表一样工作?
again, using the same technique as i just used for adding n to each entry in the list will work there, just using ncc[number] = numpart[number]/denpart[number]
instead
同样,使用和我刚才在列表中的每个条目中添加n一样的技术,只需要使用ncc[number] = numpart[number]/denpart[number]。