本文介绍了从PIL获取像素值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我正在寻求一些帮助。我是一个新手程序员,我现在遇到的一个问题是试图转换黑色&白色 .jpg 将图像放入一个列表,然后我可以将其调制成音频信号。这是创建python SSTV程序的大项目的一部分。

Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black & white .jpg image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.

我已经导入了PIL模块并尝试调用内置函数:列表(im.getdata())。当我调用它时,python崩溃了。有没有办法将图像(总是320x240)分解为240行,以使计算更容易?或者我只是调用了错误的功能。

I have imported the PIL module and am trying to call the built-in function: list(im.getdata()). When I call it, python crashes. Is there some way of breaking down the image (always 320x240) into 240 lines to make the computations easier? Or am I just calling the wrong function.

如果有人有任何建议请开火。如果有人有使用python生成调制音频音调的经验,我很乐意接受他们愿意传授的任何智慧珍珠。
提前致谢

If anyone has any suggestions please fire away. If anyone has experience of generating modulated audio tones using python I would gladly accept any 'pearls of wisdom' they are willing to impart.Thanks in advance

推荐答案

调用getdata()时,Python不会崩溃。图像可能已损坏或PIL安装有问题。尝试使用其他图像或发布您正在使用的图像。

Python shouldn't crash when you call getdata(). The image might be corrupted or there is something wrong with your PIL installation. Try it with another image or post the image you are using.

这应该按照您想要的方式分解图像:

This should break down the image the way you want:

from PIL import Image
im = Image.open('um_000000.png')

pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]

这篇关于从PIL获取像素值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:31
查看更多