“rasterio – 设置压缩质量”

huangapple go评论59阅读模式
英文:

rasterio - set compression quality

问题

I know about the possibility in the rasterio module to set a compression "family" like webp or JPEG by using the respective profile. But I want to have more control over the compression quality, like it is possible when using GDAL.

Ideally, I want something like this:

from osgeo import gdal

driver = gdal.GetDriverByName('GTiff')
ds = driver.Create(MYFILE, cols, rows, 1, dtype, ['COMPRESS=JPEG', 'JPEG_QUALITY=90'])

I could not find anything in the rasterio writing or profile documentation.

英文:

I know about the possibility in the rasterio module to set a compression "family" like webp or JPEG by using the respective profile. But I want to have more control over the compression quality, like it is possible when using GDAL.

Ideally, I want something like this:

from osgeo import gdal

driver = gdal.GetDriverByName('GTiff')
ds = driver.Create(MYFILE, cols, rows, 1, dtype, ['COMPRESS=JPEG', 'JPEG_QUALITY=90'])

I could not find anything in the rasterio writing or profile documentation.

答案1

得分: 1

请参阅此处的文档:https://rasterio.readthedocs.io/en/stable/topics/image_options.html#creation-options

基本上,选项需要在打开数据集以写入数据时设置。

因此,对于您的具体示例,代码可能如下所示:

with rasterio.open("output.tif", "w", **src.meta, compress="JPEG",
                   jpeg_quality=90) as dataset:
    # Write data to the dataset.
英文:

See the documentation here: https://rasterio.readthedocs.io/en/stable/topics/image_options.html#creation-options

Basically the options need to be set when you open the dataset you will write your data to.

So for your specific example it would be something like this:

with rasterio.open("output.tif", "w", **src.meta, compress="JPEG",
                   jpeg_quality=90) as dataset:
    # Write data to the dataset.

huangapple
  • 本文由 发表于 2023年5月17日 22:19:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76273139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定