2016-10-18 31 views
0

每當我打開python正射影像(嘗試PIL,matplotlib,scipy,openCV)的GeoTIFF圖像時,圖像就會被擰緊。一些角落是剪裁的,但是圖像保持其原始形狀。如果我手動將tif轉換爲Photoshop中的png並加載它,它確實可以正常工作。所以看起來像PIL在處理tif文件時遇到了一些麻煩,這些文件中沒有填充整個畫布的對象。有沒有人有這個問題的解決方案?在PIL中打開的GeoTIFF問題

原始圖像的部分:

Part of original Image

開盤後:

After opening

回答

2

這本來是非常好的,如果你把人物的鏈接,您正在使用(如果它是免費的)。我從here下載了一個示例GeoTIFF圖像,並使用gdal打開它。

geotiff.ReadAsArray()的形狀(3, 1024, 2048),所以我將其轉換爲(1024, 2048, 3)(RGB),並與imshow打開它:

import gdal 
gdal.UseExceptions() 
import matplotlib.pyplot as plt 
import numpy as np 

geotiff = gdal.Open('/home/vafanda/Downloads/test.tif') 
geotiff_arr= geotiff.ReadAsArray() 
print np.shape(geotiff_arr) 
geotiff_shifted = np.rollaxis(geotiff_arr,0,3) 
print "Dimension converted to: " 
print np.shape(geotiff_shifted) 
plt.imshow(geotiff_shifted) 
plt.show() 

結果:

enter image description here

+0

我現在的工作!非常感謝你。 – seanzand

+0

@seanzand沒問題。只是爲了您的信息,如果您滿意答案,您可以接受它:) – Yugi

+0

不幸的是我不能分享原來的GeoTIFF,因爲它是保密的。 – seanzand