问题描述
我正在使用 Python rasterio
更改 PNG 文件中的颜色以生成 GeoTiff 文件。这是一个调色板文件,所以我基本上弄乱了 colormap
属性。我正在测试的代码是:
# read in data,a PNG file
src = rasterio.open(inputfile)
data = src.read()
# get input palette
src_colormap_dict = src.colormap(1)
# make up dummy colormap fully transparent
dst_colormap_dict = {}
for i,color in src_colormap_dict.items():
dst_colormap_dict[i] = (5*i,5*i,0)
# copy metadata for destination file
kwargs = src.meta.copy()
kwargs.update({'driver': 'GTiff'})
# write out the GeoTiff file
dst = rasterio.open('kk1.tif','w',**kwargs)
dst.write_colormap(1,dst_colormap_dict)
dst.write(data)
src.close()
dst.close()
并且预期的结果应该是完全透明的图像。但是,输出是完全不透明的,所有地方的 alpha 通道都设置为 255。为了更好地解释,我将原始图像和处理过的图像放在下面(第二张图像应该是完全透明的):
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)