TypeError:无法将数据类型complex128的图像数据转换为浮点

2024-10-08 23:24:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码出现以下错误:

TypeError Traceback (most recent call ---> 71 image_frequency(path+"/"+folder

代码如下所示,但图像不会转换为文件夹中的频率:

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)

Tags: pathimagefftformatimgosnpback

热门问题