ValueError是什么?无法从<U76转换为float64。意思?

时间:2020-04-15 01:45:41

标签: python

我是Python的新手,正在尝试对图像进行灰度和去噪。图像文件最初是TIF图像。该程序的先前版本具有一个大循环灰度,然后进行去噪,并且没有错误。我正在尝试将其重组为灰度并保存为一个循环,然后启动一个新的循环进行降噪,但是现在出现错误:

ValueError: Can not convert from <U76 to float64

代码在下面。谁能告诉我该转换错误的含义,以便我可以尝试解决它?我不确定发生了什么。谢谢!

for subdir, dirs, files in os.walk(originalDir):
for file in files:
    path = subdir + os.sep + file

    original = io.imread(path, plugin = 'pil')
    grayscale = rgb2gray(original)


    filename = f"{grayDir}/{file}_gray.jpg"
    io.imsave (filename, grayscale)


for subdir, dirs, files in os.walk(grayDir):
for file in files:
    path = subdir + os.sep + file

    noisy = img_as_float(path)

    Bilateral = denoise_bilateral(noisy, sigma_color= colorValue, sigma_spatial=spatialValue,
                                      multichannel=False)
    plt.imshow(Bilateral)

1 个答案:

答案 0 :(得分:1)

好像您忘记加载图像。此方法需要RGB图像阵列,而不是路径。

img_as_float(image, force_copy=False)

参数 image : ndarray, shape (M, N[, 3])-输入图像,2D灰度或RGB。

尝试首先加载图像:

original = io.imread(path, plugin = 'pil')
noisy = img_as_float(original)
相关问题