Scipy储存和读取变更格式

时间:2018-08-13 04:48:08

标签: python image-processing scipy image-formats

当我保存图像时,其格式为numpy.uint16,在加载图像时,格式为numpy.uint8,它为我弄乱了整个流程。如何防止这种情况发生?

我在打电话

from scipy.misc import imread, imsave
image = imread(path)
imread(image_path)

2 个答案:

答案 0 :(得分:1)

不推荐使用foreach (Ellipse el in Halma.Children) { ellipsen.Add(el); } imsave方法,并将在以后的SciPy版本中将其删除。改用imreadimageio.imsave应该可以解决这个问题。

imageio.imread

答案 1 :(得分:0)

我将像这样向TIFF读写16位灰度数据:

#!/usr/local/bin/python3

import numpy as np
from PIL import Image

# Make a greyscale image of random 16-bit ints in range 0..65535
arr = np.random.randint(0,65535,(320,240), dtype=np.uint16)

# Make PIL image from numpy array and save
im=Image.fromarray(arr).save("result.tif")

# Re-read from file
reloadedim  = Image.open("result.tif")
reloadedarr = np.array(reloadedim)

# Calculate difference
diff = arr - reloadedarr
print("Number of different pixels: {}".format(sum(diff.ravel())))

它打印“不同像素数:0”