473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to get each pixel value from a picture file!

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

Oct 23 '06 #1
10 12056
Lucas wrote:
I want to change some pixel value in the picture file. how to do it?
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 ?
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

Oct 23 '06 #2
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 wrote:
I want to change some pixel value in the picture file. how to do it?
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 ?
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
Oct 23 '06 #3
Lucas wrote:
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)
Yes, that's an RGB tuple.
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.?
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, 55] = value
my python cannt identify "[x,y]" ??
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

Oct 23 '06 #4
:)

1)I just copy the tutorial to run "print pix[44,55]". I really dont
know why they wrote that?!
2) i think putpixel((44, 55), (0, 0, 0)) and putpixel((44,55),0) is
same.

thank you again. I think I have solved my problem.

Steve Holden wrote:
Lucas wrote:
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)
Yes, that's an RGB tuple.
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.?
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, 55] = value
my python cannt identify "[x,y]" ??

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
Oct 23 '06 #5
Lucas wrote:
1)I just copy the tutorial to run "print pix[44,55]". I really dont
know why they wrote that?!
What tutorial? Where does it say that?
Oct 23 '06 #6
http://www.pythonware.com/library/pi...book/image.htm

im.load() said....

Leif K-Brooks wrote:
Lucas wrote:
1)I just copy the tutorial to run "print pix[44,55]". I really dont
know why they wrote that?!

What tutorial? Where does it say that?
Oct 23 '06 #7
At Monday 23/10/2006 21:02, Lucas wrote:
>http://www.pythonware.com/library/pi...book/image.htm

im.load() said....
1)I just copy the tutorial to run "print pix[44,55]". I really dont
know why they wrote that?!
It clearly states that this syntax applies only to version 1.1.6 -
and I presume you're using 1.1.5.
(And please, don't top post...!)
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
Oct 24 '06 #8
Steve Holden wrote:
>3) pix = im.load()
print pix[44,55]
pix[44, 55] = value
my python cannt identify "[x,y]" ??

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.
PIL 1.1.6 (still in beta) supports special pixel access objects.
earlier versions don't.

</F>

Oct 24 '06 #9
Dennis Lee Bieber wrote:
>2) i think putpixel((44, 55), (0, 0, 0)) and putpixel((44,55),0) is
same.

It shouldn't be... The former is three separate data values, the
latter is one.
the "putpixel" API is polymorphic; you can use either tuples or integers
for RGB pixels (the latter should have the form 0xAARRGGBB).

</F>

Oct 24 '06 #10
"Lucas" <Lu****@gmail.comwrote:
>
2) I want to put a number into the picture for encryption(replace least
significant bit (LSB) of image intensity with message bit).
What formats are your images? Remember that JPEG images are compressed
when they are written. It is rather unlikely that your low-order bit
changes will survive the compression process.

There is lots and lots of research on this subject. It's called
"steganography" and "digital watermarking". Google is your friend.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 26 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: CoreyMas | last post by:
Hello All, Here is what I would like to do I am creating a game program that displays a map (preferably in hexes but that is another matter) and whenever the user is over the "map" I want to...
4
by: grogerteal | last post by:
Hello, I am pretty new to programming and would like someone to help me get started on the program that I need to make. I hope it is not hard to do, but what I would like is a simple app that...
10
by: unknown | last post by:
some one can give me a portable source codes that color a pixel? (env *nix) -- unknown
2
by: fripper | last post by:
I want to generate a graphic in a picture box control where the color of each pixel is determined by particular values calculated for each pixel. These values are manipulated in such a way that I...
1
by: fripper | last post by:
In VB 2005ave a I have a picture control ("pix") on which I want to set each pixel color according to a variable, X, that has been calculated (I'm drawing fractals from the Mandelbrot Set). I use...
30
by: Chaos | last post by:
As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes...
4
by: cjstuttle | last post by:
Could anyone help me, I'm a python noob and need some help. im trying to find some code that will, given a screen co-ordinate, will give me the colour of that pixel in RGB. i have found a lot about...
8
by: ofiras | last post by:
Hi, I made a "Paint" program, but I couldn't find a method to paint 1 pixel using graphic state ("Graphics g = Graphics.FromHwnd(this.Handle);") How can I paint 1 pixel? I guess I can make a...
1
by: ofiras | last post by:
In bitmap, how can I find the nearest pixel (pixel 1) to a specific pixel (pixel 2) that has different color from pixel 2? Or how can I find a pixel in a specific distance from pixel 2 (like a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.