我正在尝试使用 python 将原始图像数据转换为 png。我对python很陌生,尤其是对图像处理...
原始文件是 16 位灰度图像。
因为我已经扫描了论坛,所以我想出了以下解决方案:
from PIL import Image, ImageFilter
import numpy as np
from scipy import ndimage, misc
rawfile = np.fromfile('test.raw', dtype=np.int16)
rawfile.shape = (1025,1025)
imgSize = (1025,1025)
img = Image.fromstring('L', imgSize, rawfile, 'raw', 'F;16')
img.save("rawData.png")
但我不断收到以下错误:
Traceback (most recent call last):
File "****\Programs\Python 2.7.6\readraw\readraw.py", line 11, in <module>
img = Image.fromstring('L', imgSize, rawfile, 'raw', 'F;16')
File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 1835, in fromstring
return frombytes(*args, **kw)
File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 1822, in frombytes
im.frombytes(data, decoder_name, args)
File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 608, in frombytes
d = _getdecoder(self.mode, decoder_name, args)
File "****\Programs\Python 2.7.6\lib\site-packages\PIL\Image.py", line 390, in _getdecoder
return decoder(mode, *args + extra)
ValueError: unknown raw mode
有人可以向我解释为什么原始模式未知吗?我检查了文档,据我了解该主题,枕头库应该附带这个?!
最好的祝福
谢谢你们的帮助!
我改变了我的代码,现在它似乎工作了:
from PIL import Image, ImageFilter
import numpy as np
from scipy import ndimage, misc
rawfile = np.fromfile('test.raw', "uint16")
rawfile.shape = (1025,1025)
misc.imsave("test.png", rawfile)