A combinação de 4 separados monocromático tiffs em 1 CMYK tiff
-
23-12-2019 - |
Pergunta
Eu tenho tiff imagens armazenadas de tal forma que eu tenho cada plano(cor) armazenada em um arquivo separado.Cada arquivo(C,M,Y,K) é um robusto tiff armazenado como um monocromática de 8 bits por pixel arquivo.
Eu quero combinar esses 4 arquivos em um de cor CMYK tiff usando o python Imaging library(PIL)
Este é o código que eu tenho até agora, mas a saída tiff produzido não é correto, o tiff é ser combinadas em um arquivo que é mais apenas preto.Eu tenho intercalado esses arquivos com outro utilitário e o resultado é correto, portanto, eu sei que não existe um problema com os arquivos de entrada.
Este é o código que eu até agora:
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"
NOTA:Eu fiz o mesmo sem nenhuma .converter funções e achei que o resultado seja o mesmo.
Solução
Eu encontrei a solução para o ser que todos os valores em arquivos separados precisava ser invertido, isto é,255 - valor.
A conversão de cada arquivo para uma numpy matriz e, em seguida, subtraindo-se a partir de 255.\
try:
cArray = numpy.array(c_img)
mArray = numpy.array(m_img)
yArray = numpy.array(y_img)
kArray = numpy.array(k_img)
except Exception, e:
print "ERROR: Converting to numpy array..."
print str(e)
exit(1)
try:
toSub = 255
cInvArray = toSub - cArray
mInvArray = toSub - mArray
yInvArray = toSub - yArray
kInvArray = toSub - kArray
except Exception, e:
print "ERROR: inverting !"
print str(e)
try:
cPlate = Image.fromarray(cInvArray)
mPlate = Image.fromarray(mInvArray)
yPlate = Image.fromarray(yInvArray)
kPlate = Image.fromarray(kInvArray)
except Exception, e:
print "ERROR: Creating image from numpy arrays"
print str(e)
exit(1)
try:
mergedRaster = Image.merge('CMYK', (cPlate, mPlate, yPlate, kPlate))
Eu não sei por que isso foi necessário, mas se alguém pode explicar o que seria ótimo.