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

Python+gdal crop the remote sensing image and warning 1: tiffreaddirectory:sum of photometric type related color channels... appears

編輯:Python

1. Error description

Running environment :windows10、pycharm、python3.7、gdal etc.

python Use GDAL The following warning appears when cropping remote sensing images :

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

Code snippet used :

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 Function has many parameter options :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)

Parameters to describe :

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

This error occurs before cropping the image , However, the calculated results , There is no big problem to open the calculation result view .

The data used are 19 Band , One after another 17 OK, this warning .

2. Problem analysis

2.1 google Search for

Because from 4 individual CMYK Channel transfer to 3 individual RGB passageway , That's why our image color changes .

As you can see on Google :“RGB It refers to the three primary colors of light , red 、 Green and blue , For display 、 TV screen 、 Digital cameras and scanners .CMYK It refers to the primary color of the pigment : Cyan 、 magenta 、 yellow 、 black . ... When from RGB The switch to CMYK when , We may notice the change of color .”

The warning means that each pixel of the image has 4 Samples , but Protometric TIFF The label is set to RGB, No, ExtraSamples Label settings .GDAL Gave a warning , because 3 + 0 It's not equal to 4. Then it sets a band to ExtraSample, Now? 3 + 1 be equal to 4, Everything is OK Of , At least technically .

2.2  Use GDAL Python Read the large grid for warnings | Ask wisely and answer wisely

It means creating TIFF The author of the file wrote metadata incorrectly . Maybe the metadata tells the image that there are no additional samples ( Band ) Of RGB type , But actually the image has four bands ,GDAL Treat it as RGBA. By doing so ,GDAL At least one band will not be discarded , But it may make wrong guesses about the role of additional bands , It doesn't have to be alpha But it may also contain data ( for example RGB+Near Infrared).

3. terms of settlement

I add a line of code :

options=["TILED=YES", "COMPRESS=LZW"],# Image compression mode selection 

This error was not reported , However, the image is not compressed when it is opened for viewing , Didn't work .

……

I am also exploring other ways , Maybe setting a parameter option can solve , Welcome big guys to leave messages and exchange !


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