2010-07-28 119 views
2

我想加載一個CCITT T.3壓縮tiff到Python中,並從中獲取像素矩陣。它應該是一個邏輯矩陣。使用python加載CCITT T.3壓縮tiff的最佳方式是什麼?

我試過使用pylibtiff和PIL,但是當我加載它們時,它返回的矩陣是空的。我讀過很多地方,這兩個工具支持加載CCITT,但不訪問像素。

我打開轉換圖像,只要我可以從它得到邏輯矩陣,並在Python代碼中執行它。瘋狂的是,如果我在paint中打開其中一個圖像,保存它而不改變它,然後嘗試使用pylibtiff加載它,它可以工作。油漆將其重新壓縮到LZW壓縮。

所以我想我真正的問題是:有沒有辦法將CCITT圖像本地加載到matricies或使用python將圖像轉換爲LZW?

感謝,

tylerthemiler

回答

1

看來最好的辦法是不完全netpbm瘦,但使用Python:

import Image 
import ImageFile 
import subprocess 

tiff = 'test.tiff' 
im = Image.open(tiff) 
print 'size', im.size 
try: 
    print 'extrema', im.getextrema() 
except IOError as e: 
    print 'help!', e, '\n' 

print 'I Get by with a Little Help from my Friends' 
pbm_proc = subprocess.Popen(['tifftopnm', tiff], 
     stdout=subprocess.PIPE, 
     stderr=subprocess.PIPE) 
(pbm_data, pbm_error) = pbm_proc.communicate() 
ifp = ImageFile.Parser() 
ifp.feed(pbm_data) 
im = ifp.close() 
print 'conversion message', pbm_error, 
print 'extrema', im.getextrema() 
print 'size', im.size 
# houston: we have an image 
im.show() 

似乎做的伎倆:

$ python g3fax.py 
size (1728, 2156) 
extrema help! decoder group3 not available 

I Get by with a Little Help from my Friends 
conversion message tifftopnm: writing PBM file 
extrema (0, 255) 
size (1728, 2156) 
0

如何與pylibtiff運行tiffcpsubprocess轉換爲LZW(-c lzw開關),則進程正常?網絡上有Windows版本tiffcp。不完全是Python的原生解決方案,但仍...

+0

我試過tiffcp,雖然它轉換得很好,但圖片仍然沒有正確加載......我不知道你可以轉換爲lzw,但是...我會試試看......你能給我句法?? – tylerthemiler 2010-07-28 21:24:22

+0

@tylerthemiler,沒有特別的語法,只是'tiffcp -c lzw from.tiff to.tiff'。而msw的回答有'subprocess'用法的例子。 – Constantin 2010-07-29 06:40:19

相關問題