Home 我的代码 Python进行图像处理——开篇
formats

Python进行图像处理——开篇

Python是一个非常简洁优雅的语言,库非常的丰富。在图像处理方面,有个PIL(Python Imaging Library ),这个是一个应用上手非常简单的Python的图像处理库。

PIL的下载地址可以在 http://pypi.python.org/pypi/PIL 找到。

手册在 http://www.pythonware.com/library/pil/handbook/index.htm ,这里有非常详细的教程。

我们安装完PIL后,可以在Python交互解释器很中输入:  import Image

image

如果没有发生错误,这说明安装完成了。我们输入以下代码,将会打开一幅图像。

import Image

img = Image.open("yun.jpg")
print img.format, "%d * %d" % img.size, img.mode
new_img = img.rotate(45)
new_img.save("new_yun.jpg")
new_img.show()

可以看到如下效果:

(我很喜欢Photoshop和ACDSee,所以还是经常在Windows上,辅以cygwin)

图像旋转了45°,而且也打印了图像的信息。

image

最后输出了文件:

image

本文链接:http://everet.org/2012/01/pil-start.html

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© EverET.org