从 PIL 获取像素值列表 [英] Getting list of pixel values from PIL

查看:34
本文介绍了从 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 模块并试图调用内置函数:list(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

推荐答案

Python 不应在调用 getdata() 时崩溃.图像可能已损坏或您的 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 获取像素值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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