python PIL可以处理原始图像数据吗? [英] can the python PIL deal with raw image data?

查看:191
本文介绍了python PIL可以处理原始图像数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原始图像文件是.bin,由16位无符号整数组成。 python映像库可以采用这种类型的文件并进行处理吗?我的代码运行不正常并给我一个无效的文件类型错误,但我认为它可能是编码中的错误,而不仅仅是它不采用这种文件类型。

I have an raw image file that is .bin and is composed of 16 bits unsigned intergers. Can the python imaging library take this type of file and process it? My code is not running properly and giving me an invalid file type error but I think it may be an error in the coding rather than just that it doesn't take this file type.

有关于此的任何知识吗?

Any knowledge on this out there?

推荐答案

假设您的文件没有标题并且紧凑,请尝试以下内容:

Assuming your file doesn't have a header and is tightly packed, try the following:

with open('filename', 'rb') as f:
    im = Image.fromstring('L;16', (width, height), f.read()) # also try 'L;16B', 'I;16', and 'I;16B'
im.show()

'L'格式将从16截断每像素位数为8; '我'格式将保持每像素16位,但可能更难处理。

The 'L' formats will truncate from 16 bits per pixel to 8; the 'I' formats will keep it at 16 bits per pixel but might be harder to work with.

如果您的原始文件以某种方式编码,您必须在其上搜索文档,因为原始格式根本没有标准化。使用 .bin 扩展名,我怀疑是这种情况。

If your raw file is encoded in some way you'll have to search for documentation on it, since raw formats aren't standardized at all. With a .bin extension I doubt that's the case.

这篇关于python PIL可以处理原始图像数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆