Python TypeError:无法将数据类型complex128的图像数据转换为浮点
我的代码出现以下错误: 类型错误回溯(最近的 呼叫 --->71图像频率(路径+“/”+文件夹 代码如下所示,但图像不会转换为文件夹中的频率:Python TypeError:无法将数据类型complex128的图像数据转换为浮点,python,image,numpy,cnn,converters,Python,Image,Numpy,Cnn,Converters,我的代码出现以下错误: 类型错误回溯(最近的 呼叫 --->71图像频率(路径+“/”+文件夹 代码如下所示,但图像不会转换为文件夹中的频率: def image_frequency(folder): images = [] num_images = 0 location = folder for filename in os.listdir(folder): img = cv2.imread(os.path.join(folder, filena
def image_frequency(folder):
images = []
num_images = 0
location = folder
for filename in os.listdir(folder):
img = cv2.imread(os.path.join(folder, filename))
if img is not None:
img = np.fft.fft2(img)
fshift = np.fft.fftshift(img)
magnitude_spectrum = 20*np.log(np.abs(fshift))
images.append(fshift)
num_images += 1
cv2.imwrite("{}/{}".format(location, filename), magnitude_spectrum)
rows, cols = img.shape
crow,ccol = rows/2 , cols/2
#fshift[crow-30:crow+30, ccol-30:ccol+30] = 0
f_ishift = np.fft.ifftshift(fshift)
img_back = np.fft.ifft2(f_ishift)
img_back = np.abs(img_back)
print("_image:{0} complete".format(filename))
return None
path = os.getcwd()+"\\sar"
for folder in os.listdir(path):
print("image_frequency on folder: {0}".format(folder))
image_frequency(path+"/"+folder)