Question

J'ai des images TIFF stockées de manière à ce que j'ai reçu chaque plan (couleur) stocké dans un fichier séparé.Chaque fichier (C, M, Y, K) est un TIFF Chunky stocké comme un fichier monochrome 8 bits par fichier pixel.

Je veux combiner ces 4 fichiers dans un tiff coloré CMJN à l'aide de la bibliothèque d'imagerie Python (PIL)

Ceci est le code que j'ai jusqu'à présent mais le TIFF de sortie produit n'est pas correct, le TIFF est associé à un fichier qui est principalement noir.J'ai fusionné ces fichiers avec un autre utilitaire et le résultat est correct, alors je sais qu'il n'ya pas de problème avec les fichiers d'entrée.

C'est le code que j'ai jusqu'à présent:

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"

Remarque: j'ai fait la même chose sans aucune des fonctions .convert et a trouvé le résultat pour être identique.

Était-ce utile?

La solution

J'ai trouvé la solution pour que toutes les valeurs des fichiers séparés devaient être inversées, c'est-à-dire une valeur de 255.

convertir chaque fichier en une matrice numpue, puis soustrayez-la 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))

Je ne sais pas pourquoi cela était nécessaire, mais si quelqu'un peut l'expliquer, ce serait génial.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top