Python+gdal裁剪遥感图像出现“Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels ……”

博客讨论了在Windows 10环境下,使用Python的GDAL库裁剪遥感图像时遇到的警告问题。警告涉及TIFF文件的色彩通道与样本周不符。尽管结果看似正常,但提示可能与图像的波段处理有关。作者分析了错误原因,可能是元数据错误地表明图像为RGB而实际包含额外的波段。尝试通过设置压缩选项解决,但未见明显效果。寻求进一步的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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"],#影像压缩方式选择

没有报这个错误了,不过图像打开查看的时候还是没有压缩,没起作用。

……

其他办法我也在探索中,可能设置某个参数选项可以解决,欢迎大佬们留言交流!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空中旋转篮球

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值