I have tiff images stored in such a way that i have each plane(color) stored in a separate file. Each file(C,M,Y,K) is a chunky tiff stored as a monochrome 8 bits per pixel file.
I want to combine these 4 files into one CMYK colored tiff using the python Imaging library(PIL)
This is the code I have so far but the output tiff produced is not correct, the tiff is being combined into a file that is mostly just black. I have merged these files with another utility and the result is correct, so I know there isnt a problem with the input files.
This is the code I have so far:
if len(sys.argv) <= 1:
print "ERROR: Usage !"
exit(1)
try:
cFile = str(sys.argv[1])+"Cyan.tif"
mFile = str(sys.argv[1])+"Magenta.tif"
yFile = str(sys.argv[1])+"Yellow.tif"
kFile = str(sys.argv[1])+"Black.tif"
print "Opening files:"
print cFile
print mFile
print yFile
print kFile
c_img = Image.open(cFile)
c_img = c_img.convert("L")
m_img = Image.open(mFile)
m_img = m_img.convert("L")
y_img = Image.open(yFile)
y_img = y_img.convert("L")
k_img = Image.open(kFile)
k_img = k_img.convert("L")
except Exception, e:
print "ERROR: Unable to open file..."
print str(e)
exit(1)
try:
mergedRaster = Image.merge('CMYK', (c_img, m_img, y_img, k_img))
mergedRaster = mergedRaster.convert("CMYK")
except Exception, e:
print "ERROR: Merging plates"
print str(e)
exit(0)
#exit(0)
try:
mergedRaster.save("output.tif", format="TIFF")
except Exception, e:
print "ERROR: Writing tiff"
NOTE: I have done the same without any of the .convert functions and found the result to be the same.