[Image-SIG] Writting ppm files??
Ashish Sethi
ashishbitsgoa at gmail.com
Tue Aug 19 13:01:03 CEST 2008
Hi all,.
I am working with PPM/PGM/PBM file formats
which have the basic format :-
P2
# feep.pgm
3 3
255
0 0 0 0 0 0 0 0 0
0 0 0 9 24 15 10 27 18
0 0 0 9 24 15 10 27 18
where line1= type of file(p1=PBM,p2=PGM,p3=PPM), line2=comment,
line3=dimension of the image (x and y length),line4=maximum value of
color( here 15 means 4 bit R,G,B data)
NOW, uptil now, I have written the following code:-
import Image
im="C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena.ppm"
i=Image.open(im)
x=list(i.getdata())
z=len(x)
xbar=[]
count=0
while (count<z-1):
q=[]
co=0
while(co<3):
y=x[count]
q.append(convert_r8_2_r4(y[co]))
co+=1
xbar.append(q)
count+=1
Here, x is a list of all 3 member tuples of R,G,B data of each and
every pixel. The tuples in x have RGB values in the range 0-255..i.e
8 bit binary. Using the function convert_r8_2_r4() I was able to
convert these values in the range 0-16...i.e 4 bit binary by clipping
the least significant 4 bits. By doing this I was able to create xbar
which is in the same format as x...i.e list of 3 member tuples of
R,G,B data. Now my problem is how do i create another image of the
same dimensions as the original in the same format as original using
this xbar list.
More information about the Image-SIG
mailing list