Python+gdal裁剪遥感图像出现“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels ……”
Posted 空中旋转篮球
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python+gdal裁剪遥感图像出现“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels ……”相关的知识,希望对你有一定的参考价值。
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"],#影像压缩方式选择
没有报这个错误了,不过图像打开查看的时候还是没有压缩,没起作用。
……
其他办法我也在探索中,可能设置某个参数选项可以解决,欢迎大佬们留言交流!
以上是关于Python+gdal裁剪遥感图像出现“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels ……”的主要内容,如果未能解决你的问题,请参考以下文章
Python遥感图像处理应用篇(二十二):Python+GDAL 批量等距离裁剪影像-续
Python遥感图像处理应用篇(二十二):Python+GDAL 批量等距离裁剪影像-续
Python遥感图像处理应用篇(二十二):Python+GDAL 批量等距离裁剪影像
gdal学习笔记利用python 的gdal,以及相关库进行遥感图像处理(影像裁剪,辐射定标,大气校正,异常值去除)——以基于landsat8数据提取NDVI为例