[Image-SIG] modes in Image package

Nadav Horesh nadavh at visionsense.com
Wed Aug 24 16:41:58 CEST 2005


1. 16  bits manipulation: PIL supports (unlike most image processing programs) 16 bits TIF. But I do not know if there is a 16x3 colour format.
2. For a quick image enhancement look at enhacer.py that comes with the package. It may be instructive to look at the other scripts in the same directory.

  Nadav.


-----Original Message-----
From:	image-sig-bounces at python.org on behalf of Victor Reijs
Sent:	Wed 24-Aug-05 15:03
To:	image-sig at python.org
Cc:	
Subject:	[Image-SIG] modes in Image package
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")

########


_______________________________________________
Image-SIG maillist  -  Image-SIG at python.org
http://mail.python.org/mailman/listinfo/image-sig





More information about the Image-SIG mailing list