-1
我在python中編寫代碼,Opencv用於在編譯時實現高斯低通濾波器,它給出了在第14行的錯誤'不能分配給函數調用'根 。不能分配給函數調用
`import cv2
import numpy as np
from math import sqrt
img = cv2.imread('polys.jpg',0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
magnitude_spectrum = 20*np.log(np.abs(fshift))
m, n = img.shape
m2,n2 = m/2 , n/2
d=np.zeros((m,n))
for u in range(m):
for v in range(n):
r=((u-m2)*(u-m2))+((v-n2)*(v-n2))
d(u,v)=sqrt(r)
d(u,v)=int(d(u,v))
if d(u,v)>10:
h(u,v)=0
elif d(u,v)<=10:
h(u,v)= math.exp(-(d(u,v)*d(u,v))/(2*10*10))
result=h*fshift
f_ishift = np.fft.ifftshift(result)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)
cv2.imshow('dft',img_back)
cv2.waitKey(0)
cv2.destroyAllWindows()
`
我猜它只是一個代碼粘貼問題,但我得到的,因爲沒有鋸齒的第二'for'環的縮進錯誤。 – cdarke