程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python+gdal裁剪遙感圖像出現“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels ……”

編輯:Python

1.錯誤描述

運行環境:windows10、pycharm、python3.7、gdal等

python使用GDAL 裁剪遙感圖像的時候出現以下警告:

“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.”

使用的代碼段:

out_ds = gdal.Warp(output_image,#output file full path
ds,#input file 2 ds
format='GTiff',
outputBounds=(x_left, x_bottom, x_right, x_top),
dstNodata=0)

Warp函數有很多參數選項:https://gdal.org/python/https://gdal.org/python/

Warp(destNameOrDestDS, srcDSOrSrcDSTab, **kwargs)
Warp one or several datasets.
Arguments are :
destNameOrDestDS --- Output dataset name or object
srcDSOrSrcDSTab --- an array of Dataset objects or filenames, or a Dataset object or a filename
Keyword arguments are :
options --- return of gdal.WarpOptions(), string or array of strings
other keywords arguments of gdal.WarpOptions()
If options is provided as a gdal.WarpOptions() object, other keywords are ignored.
WarpOptions(options=None, format=None, outputBounds=None,
outputBoundsSRS=None, xRes=None, yRes=None, targetAlignedPixels=False,
width=0, height=0, srcSRS=None, dstSRS=None, coordinateOperation=None,
srcAlpha=False, dstAlpha=False, warpOptions=None, errorThreshold=None,
warpMemoryLimit=None, creationOptions=None, outputType=gdalconst.GDT_Unknown,
workingType=gdalconst.GDT_Unknown, resampleAlg=None, srcNodata=None, dstNodata=None,
multithread=False, tps=False, rpc=False, geoloc=False, polynomialOrder=None,
transformerOptions=None, cutlineDSName=None, cutlineLayer=None, cutlineWhere=None,
cutlineSQL=None, cutlineBlend=None, cropToCutline=False, copyMetadata=True,
metadataConflictValue=None, setColorInterpretation=False, overviewLevel='AUTO',
callback=None, callback_data=None)

參數描述:

Create a WarpOptions() object that can be passed to gdal.Warp()
Keyword arguments are :
  options --- can be be an array of strings, a string or let empty and filled from other keywords.
  format --- output format ("GTiff", etc...)
  outputBounds --- output bounds as (minX, minY, maxX, maxY) in target SRS
  outputBoundsSRS --- SRS in which output bounds are expressed, in the case they are not expressed in dstSRS
  xRes, yRes --- output resolution in target SRS
  targetAlignedPixels --- whether to force output bounds to be multiple of output resolution
  width --- width of the output raster in pixel
  height --- height of the output raster in pixel
  srcSRS --- source SRS
  dstSRS --- output SRS
  coordinateOperation -- coordinate operation as a PROJ string or WKT string
  srcAlpha --- whether to force the last band of the input dataset to be considered as an alpha band
  dstAlpha --- whether to force the creation of an output alpha band
  outputType --- output type (gdalconst.GDT_Byte, etc...)
  workingType --- working type (gdalconst.GDT_Byte, etc...)
  warpOptions --- list of warping options
  errorThreshold --- error threshold for approximation transformer (in pixels)
  warpMemoryLimit --- size of working buffer in MB
  resampleAlg --- resampling mode
  creationOptions --- list of creation options
  srcNodata --- source nodata value(s)
  dstNodata --- output nodata value(s)
  multithread --- whether to multithread computation and I/O operations
  tps --- whether to use Thin Plate Spline GCP transformer
  rpc --- whether to use RPC transformer
  geoloc --- whether to use GeoLocation array transformer
  polynomialOrder --- order of polynomial GCP interpolation
  transformerOptions --- list of transformer options
  cutlineDSName --- cutline dataset name
  cutlineLayer --- cutline layer name
  cutlineWhere --- cutline WHERE clause
  cutlineSQL --- cutline SQL statement
  cutlineBlend --- cutline blend distance in pixels
  cropToCutline --- whether to use cutline extent for output bounds
  copyMetadata --- whether to copy source metadata
  metadataConflictValue --- metadata data conflict value
  setColorInterpretation --- whether to force color interpretation of input bands to output bands
  overviewLevel --- To specify which overview level of source files must be used
  callback --- callback method
  callback_data --- user data for callback

這個錯誤是在裁剪圖像之前出現的,不過也計算出來的結果,打開計算結果查看也沒有太大問題。

使用的數據有19個波段,一連出現了17行這個警告。

2.問題分析

2.1 google搜索

因為從4個CMYK通道轉移到3個RGB通道,這就是為什麼我們的圖像顏色變了。

正如谷歌上所看到的:“RGB指的是光的三原色,紅、綠和藍,用於顯示器、電視屏幕、數碼相機和掃描儀。CMYK指的是顏料的原色:青色、品紅、黃色、黑色. ...當從RGB轉換到CMYK時,我們呢可能會注意到顏色的變化。”

警告意味著圖像每個像素有4個樣本,但Protometric TIFF標簽設置為RGB,沒有ExtraSamples標簽設置。GDAL給出了一個警告,因為3 + 0不等於4。然後它設置一個帶為ExtraSample,現在3 + 1等於4,一切都是OK的,至少在技術上。

2.2 使用 GDAL Python 讀取大柵格獲取警告 | 智問智答

意味著創建 TIFF 文件的作者將元數據寫入錯誤。也許元數據告訴圖像是沒有額外樣本(波段)的 RGB 類型,但實際上圖像有四個波段,GDAL 將其視為 RGBA。通過這樣做,GDAL 至少不會丟棄一個波段,但它可能會對額外波段的作用做出錯誤的猜測,這不一定是 alpha 但也可能包含數據(例如 RGB+Near Infrared).

3.解決辦法

我加一行代碼:

options=["TILED=YES", "COMPRESS=LZW"],#影像壓縮方式選擇

沒有報這個錯誤了,不過圖像打開查看的時候還是沒有壓縮,沒起作用。

……

其他辦法我也在探索中,可能設置某個參數選項可以解決,歡迎大佬們留言交流!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved