[Image-SIG] modes in Image package
Victor Reijs
geniet2003 at iol.ie
Wed Aug 24 15:03:23 CEST 2005
Hello all of you,
I was wondering if it is possible with the Image package to use a mode
like RGB but with 16 bits (or more) per each band?
I want to do some manipulations with the picture (and I could use the
method proposed by Nadav: fromstring/tostring), but I had hoped I could
be using only Image package.
The program I now use can be see below.
Thanks for your feedback.
All the best,
Victor
########
import Image
import ImageWin
#calculate a gamma function
def detergamma(x):
return 255*math.pow(float(x)/255,gamma)
#display picture
def displaypic(pix,titletext):
w2=ImageWin.ImageWindow(pix,title=titletext)
w2.mainloop() # this will block until the window is closed
return
#read picture
imbegin = Image.open("C:\\Documents and Settings\\vreijs\\My
Documents\\my projects\\colorcard\\bm-IFRAO_1.jpg")
displaypic(imbegin,"Original")
# just a sample color matrix (I kept the off-set zero (the last
# 'column' with zeros)
colormat = (2,-1.06,0.08, 0,
-0.01,1.11,-0.09, 0,
0.06,-0.22,1.25, 0)
#bring picture in linear space, assume it was near sRGB
#first split it in the three bands, to be able to do
#different gamma on each band
splitted= imbegin.split()
gamma=1/0.44
Rrr=Image.eval(splitted[0], detergamma)
gamma=1/0.5
Ggg=Image.eval(splitted[1], detergamma)
gamma=1/0.51
Bbb=Image.eval(splitted[2], detergamma)
displaypic(Rrr,"R-band")
displaypic(Ggg,"G-band")
displaypic(Bbb,"B-band")
#make it one RGB picture
combined=Image.merge("RGB",(Rrr,Ggg,Bbb))
displaypic(combined,"Combined")
#do a color matrix transform
converted = combined.convert("RGB", colormat)
displaypic(converted,"Color converted")
#bring back into sRGB space
gamma=1/2.2
imend=Image.eval(converted, detergamma)
displaypic(imend,"End result")
imend.save("C:\\Documents and Settings\\vreijs\\My Documents\\my
projects\\colorcard\\bm-IFRAO_1-optm.jpg")
########
More information about the Image-SIG
mailing list