使用python和PIL模块导入PPM图像 [英] Importing PPM images with python and PIL module

查看:110
本文介绍了使用python和PIL模块导入PPM图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我需要一种方法来读取行并将像素信息提取到某种结构中,以便可以使用putpixel函数基于ppm p3文件创建图像.

Actually, I need a way I can read the lines and extract the pixel info into some structure so I can use the putpixel function to create an image based on the ppm p3 file.

我已经尝试了很久了,我不能只是做对了.

I've been trying this for so long and I can't just get it right.

我正在使用Python Imaging Library(PIL),我想打开一个PPM图像并将其作为图像显示在屏幕上.

I'm working with Python Imaging Library (PIL) and I want to open a PPM image and display it as an image on the screen.

如何仅使用PIL做到这一点?

How can I do that using only PIL?

这是我的ppm图像.这只是我创建的7x1图片.

this is my ppm image. it's just a 7x1 image that i created.

P3
# size 7x1
7 1
255
0
0
0
201
24
24
24
201
45
24
54
201
201
24
182
24
201
178
104
59
14

推荐答案

编辑:修改完问题并仅允许阅读以下内容后,请查看下面的链接.它说明了如何编写用于加载文件的包装器.我要亲自测试一下,它应该可以工作...

edit: After you modified your question and you allow just reading the lines, check the link below. It explains how to write a wrapper that loads the file. I am about to test this myself and it should work...

您当前(11/2010)无法使用PIL打开纯PPM图像.平原在这里表示ascii.二进制版本可以工作.这样做的主要原因是,ASCII文件每个像素的位数不恒定.这就是PIL中的图像加载器所假定的.我有一个相关的问题:

You currently (11/2010) cannot open plain PPM images with PIL. Plain here means ascii. Binary versions work however. The main reason for this is that ascii files do not have constant number of bits per pixel. And this is what the image loader in PIL assumes. I have a related question at:

如何写入PIL图像过滤为纯pgm格式?

我打算为普通的PPM编写一个PIL过滤器,但是我的时间很短.如果您想提供帮助,请告诉我.

I am planning to write a PIL-filter for plain PPM's but I am short on time. If you are interested to help, please let me know.

br,
Juha

br,
Juha

这篇关于使用python和PIL模块导入PPM图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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