相关疑难解决方法(0)

使用Python读取16位PNG图像文件

我正在尝试读取以16位数据类型编写的PNG图像文件.数据应转换为NumPy数组.但我不知道如何在'16位'中读取文件.我尝试使用PIL和SciPy,但是当它们加载时它们将16位数据转换为8位数据.谁能告诉我如何从16位PNG文件中提取数据并将其转换为NumPy数组而不更改数据类型?

以下是我使用的脚本.

from scipy import misc
import numpy as np
from PIL import Image
#make a png file    
a = np.zeros((1304,960), dtype=np.uint16)
a[:] = np.arange(960)
misc.imsave('16bit.png',a)

#read the png file using scipy
b = misc.imread('16bit.png')
print "scipy:" ,b.dtype

#read the png file using PIL
c = Image.open('16bit.png')   
d = np.array(c)
print "PIL:", d.dtype
Run Code Online (Sandbox Code Playgroud)

python png python-imaging-library

7
推荐指数
3
解决办法
1万
查看次数

标签 统计

png ×1

python ×1

python-imaging-library ×1