英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论