Pregunta

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 
¿Fue útil?

Solución

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

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top