如何从图片文件中获取每个像素值! [英] How to get each pixel value from a picture file!

查看:81
本文介绍了如何从图片文件中获取每个像素值!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改图片文件中的某些像素值。怎么做?


如果我以二进制模式读取文件,有点==一个像素?


谢谢

I want to change some pixel value in the picture file. how to do it?

If I read the file in binary mode, a bit == a pixel ?

Thanks

推荐答案

Lucas写道:
Lucas wrote:

我想改变图片中的一些像素值文件。怎么做?
I want to change some pixel value in the picture file. how to do it?



最流行的方式可能就是Python图像库,它的朋友称为
朋友为PIL:

http://www.pythonware.com/products/pil/


你会看到

http://www.pythonware.com/library/pi...book/image.htm


图像有.getpixel()和.putpixel()方法,如果你愿意,它们可以让你读取和设置单个像素。请注意,

即将发布的版本将使用名为

像素访问对象的内容提供更快的访问权限,我对此一无所知。

The most popular way is probably the Python Image Library, known to its
friends as PIL:

http://www.pythonware.com/products/pil/

You will see from

http://www.pythonware.com/library/pi...book/image.htm

that images have .getpixel() and .putpixel() methods that will allow you
to read and set individual pixels if you want. Be aware that the
forthcoming release will give faster access using something called
"pixel access objects", about which I know nothing.


如果我以二进制模式读取文件,有点==一个像素?
If I read the file in binary mode, a bit == a pixel ?



当然,仅适用于单色图像。灰度和彩色图像每个像素有更多的比特,有些格式使用调色板映射,允许每个像素点数更少的高色彩保真度(GIF就是这样一种格式) )。

下载PIL并玩它。我相信你会有很多乐趣,而且你可以在一个

的互动翻译会话中做一些惊人的处理。


问候

史蒂夫

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://holdenweb.blogspot.com

最近的Ramblings http://del.icio .us / steve.holden

Only for monochrome images, of course. Greyscale and color images have
more bits per pixel, and some formats use a palette mapping to allow
high color-fidelity with fewer bits per pixel (GIF is one such format).

Download PIL and play with it. I''m sure you''ll have a lot of fun, and
you can do a surprising amount of processing just noodling around in an
interactive interpreter session.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden


感谢您的回答。


我有一些新问题:


1)getpixel()的返回值是RGB数?

print im.getpixel((44,55)) - ---(160,160,160)


2)我想放一个数字r进入图片进行加密(用消息位替换最少
图像强度的有效位(LSB))。


如果我使用putpixel((44, 55),0),数字0将改变RGB

值或其他。?


3)pix = im.load()

打印pix [44,55]

pix [44,45] =值

我的python无法识别[x,y] ??
Steve Holden写道:
Thank you for your answer.

I have some new questions:

1) the value of return from getpixel() is a RGB number?
print im.getpixel((44,55)) ----(160,160,160)

2) I want to put a number into the picture for encryption(replace least
significant bit (LSB) of image intensity with message bit).

If i use putpixel((44,55),0) , the number 0 will be changed RGB
value or others.?

3) pix = im.load()
print pix[44,55]
pix[44, 55] = value
my python cannt identify "[x,y]" ??

Steve Holden wrote:

Lucas写道:
Lucas wrote:

我想改变图片文件中的一些像素值。怎么做?
I want to change some pixel value in the picture file. how to do it?



最受欢迎的方式可能是Python图像库,它的朋友称为
朋友为PIL:

http://www.pythonware.com/products/pil/


你会看到

http://www.pythonware.com/library/pi...book/image.htm


图片有。 getpixel()和.putpixel()方法将允许你

如果你想要读取和设置单个像素。请注意,

即将发布的版本将使用名为

像素访问对象的内容提供更快的访问权限,我对此一无所知。

The most popular way is probably the Python Image Library, known to its
friends as PIL:

http://www.pythonware.com/products/pil/

You will see from

http://www.pythonware.com/library/pi...book/image.htm

that images have .getpixel() and .putpixel() methods that will allow you
to read and set individual pixels if you want. Be aware that the
forthcoming release will give faster access using something called
"pixel access objects", about which I know nothing.


如果我以二进制模式读取文件,有点==一个像素?
If I read the file in binary mode, a bit == a pixel ?



当然,仅适用于单色图像。灰度和彩色图像每个像素有更多的比特,有些格式使用调色板映射,允许每个像素点数更少的高色彩保真度(GIF就是这样一种格式) )。

下载PIL并玩它。我相信你会有很多乐趣,而且你可以在一个

的互动翻译会话中做一些惊人的处理。


问候

史蒂夫

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://holdenweb.blogspot.com

最近的Ramblings http://del.icio .us / steve.holden


Lucas写道:
Lucas wrote:

感谢您的回答。


我有一些新问题:


1)getpixel()的返回值是一个RGB数字?

print im.getpixel( (44,55))----(160,160,160)
Thank you for your answer.

I have some new questions:

1) the value of return from getpixel() is a RGB number?
print im.getpixel((44,55)) ----(160,160,160)



是的,这是一个RGB元组。

Yes, that''s an RGB tuple.


2)我想在图片中添加一个数字进行加密(用消息位替换最少

图像强度的有效位(LSB))。


如果我使用putpixel((44,55),0),数字0将被改变RGB

值或其他。?
2) I want to put a number into the picture for encryption(replace least
significant bit (LSB) of image intensity with message bit).

If i use putpixel((44,55),0) , the number 0 will be changed RGB
value or others.?



我想你需要使用


putpixel((44,55),(0,0,0))


但是交互式尝试很容易......

I think you''d need to use

putpixel((44, 55), (0, 0, 0))

but it''s easy enough to try out interactively ...


3)pix = im.load()

print pix [44,55]

pix [44,45] = value

我的python无法识别[x,y] ??
3) pix = im.load()
print pix[44,55]
pix[44, 55] = value
my python cannt identify "[x,y]" ??



现在是什么让你认为图像可以这样解决?如果除了TypeError之外还有其他任何东西,那我就会感到非常惊讶。


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://holdenweb.blogspot.com

最近的Ramblings http://del.icio.us/steve.holden

Now what makes you think that an image can be addressed that way? I''d be
quite surprised if yo got anything other than a TypeError doing that.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden


这篇关于如何从图片文件中获取每个像素值!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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