Domanda

Ho immagini TIFF memorizzate in modo tale da avere ciascun piano (colore) memorizzato in un file separato.Ogni file (C, M, Y, K) è un TIFF grosso memorizzato come un file monocromatico da 8 bit per pixel.

Voglio combinare questi 4 file in un TIFF colorato CMYK utilizzando la libreria di imaging Python (PIL)

Questo è il codice che ho finora ma il TIFF di uscita prodotto non è corretto, il TIFF viene combinato in un file che è per lo più nero.Ho unito questi file con un'altra utilità e il risultato è corretto, quindi so che non c'è un problema con i file di input.

Questo è il codice che ho finora:

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: ho fatto lo stesso senza nessuna delle funzioni .Convert e ho trovato il risultato per essere lo stesso.

È stato utile?

Soluzione

Ho trovato la soluzione per essere che tutti i valori nei file separati necessari per essere invertiti, cioè 255 - valore.

Conversione di ciascun file in un array ninpy e quindi sottraendolo da 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))
.

Non so perché è stato richiesto questo, ma se qualcuno può spiegarlo sarebbe fantastico.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top