开发者

Importing PPM images with python and PIL module

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'm working with Python Imaging Library (PIL) and I wa开发者_StackOverflow中文版nt to open a PPM image and display it as an image on the screen.

How can I do that using only PIL?

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


And if you like working with np.array objects, just do this:

>>> from scipy.misc import imread
>>> img = imread(path_to_ppm_file)
>>> img.shape
>>> (234, 555, 3)


Some background concept

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜