1

ピクセルあたり 16 ビットでマルチバンドの tif 画像を開いて、RAW ファイルに変換しようとしました。次のコマンドi = Image.open('image.tif')で PIL を使用していますrawData = i.tostring()。マルチバンド tif イメージでは機能しません。

エラーは次のとおりです。

File "C:\Python27\lib\site-packages\PIL\Image.py", line 1980, in open
    raise IOError("cannot identify image file")
IOError: cannot identify image file

ディレクトリにはファイルが含まれています。

どうすればいいですか?

4

1 に答える 1

2

GDAL はマルチバンド ラスターを開くのに非常に優れており、int16 を含む11 の異なるバンド タイプをサポートしています。

from osgeo import gdal
import numpy as np

ds = gdal.Open('image.tif')

# loop through each band
for bi in range(ds.RasterCount):
    band = ds.GetRasterBand(bi + 1)
    # Read this band into a 2D NumPy array
    ar = band.ReadAsArray()
    print('Band %d has type %s'%(bi + 1, ar.dtype))
    raw = ar.tostring()
于 2012-09-16T21:30:26.503 に答える