【发布时间】:2019-01-03 06:35:50
【问题描述】:
我正在使用 python 将 RGBA tiff 转换为具有白色背景的 RGB tiff。
我正在使用 ImageMagick 和 GDAL 库。
我的代码是这样的:
def add_background_to_rgba_geotiff(source, destination):
convert_rgba_to_rgb_tif(source, destination)
add_metadata_to_new_geotiff_file(source, destination)
def convert_rgba_to_rgb_tif(source, destination):
# work also with BigTiff
command = ' '.join(['convert', quote(source),
'-background', 'white',
'-alpha', 'background',
'-alpha', 'off', quote(destination)])
shell_command.execute_and_log_outputs(command, shell=True)
def add_metadata_to_new_geotiff_file(source, destination):
RGBA_tif = gdal.Open(source, gdalconst.GA_ReadOnly)
RGB_tif = gdal.Open(destination, gdalconst.GA_Update)
RGB_tif.SetMetadata(RGBA_tif.GetMetadata())
RGB_tif.SetGeoTransform(RGBA_tif.GetGeoTransform())
RGB_tif.SetProjection(RGBA_tif.GetProjection())
del (RGBA_tif)
del (RGB_tif)
def execute_and_log_outputs(command, silence_errors=False, **kwargs):
shell_process = execute_async(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
**kwargs)
(out, err) = shell_process.communicate()
当我尝试使用 tiff 运行我的代码时,一切正常,但是当我想在 BigTIFF (>4GB) 上应用它时,它会失败并出现以下错误:
TIFFWriteDirectoryTagData:超过最大 TIFF 文件大小。
有人知道如何将 BigTiff 与 ImageMagick 一起使用吗? 或者可以用GDAL做到这一点吗?在我尝试使用 GDAL 的那一刻,我只实现了黑色背景。
感谢您的帮助。
【问题讨论】:
-
尝试像这样在输出文件的前面强制使用 BigTIFF delgate...
convert input.tiff ... TIFF64:BigBoy.tif
标签: python image image-processing imagemagick gdal