当我保存图像时,其格式为numpy.uint16
,在加载图像时,格式为numpy.uint8
,它为我弄乱了整个流程。如何防止这种情况发生?
我在打电话
from scipy.misc import imread, imsave
image = imread(path)
imread(image_path)
答案 0 :(得分:1)
不推荐使用foreach (Ellipse el in Halma.Children)
{
ellipsen.Add(el);
}
和imsave
方法,并将在以后的SciPy版本中将其删除。改用imread
和imageio.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” 。