我正在用gdal镶嵌一些图像,并想通过朝每个图像的边缘使用淡入/渐变Alpha层来消除马赛克中间的尖锐边缘来改善最终结果。我遇到的问题是,每个带有渐变Alpha层的图像的一部分在最终的镶嵌图中都将其下方的图像掩盖了,而不是半透明的,如下所示:
理想情况下,我希望使用这种渐变透明度将一张图像逐渐淡入另一张图像。
我执行的生成镶嵌的步骤如下:
将gcps添加到原始图像以对其进行地理位置定位和正确定向(依次对每个图像进行处理):
gdal_translate -of GTiff -a_srs EPSG:4326 -a_srs EPSG:4326 -gcp 1616 0 -88.2728612066 40.5175787437 -gcp <etc., etc.> <original_image_with_gradual_alpha>.tif <image_with_gradual_alpha_and_gcps>.tif
将图像扭曲到正确定向的新geotiff(依次对每个图像执行):
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:4326 -dstnodata 0 <image_with_gradual_alpha_and_gcps>.tif <warped_geotiff_with_alpha>.tif
将所有变形的图像合并到一个马赛克中:
gdalbuildvrt -srcnodata 0 mosaic.vrt <warped_geotiff_with_alpha_root>*.tif
gdal_translate mosaic.vrt mosaic.tif
我链接的图像是mosaic.tif。
gdalinfo提供样本输入文件:
Driver: GTiff/GeoTIFF
Files: dsc00562.tif
Size is 1616, 1080
Coordinate System is `'
Metadata:
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_XRESOLUTION=350
TIFFTAG_YRESOLUTION=350
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 1080.0)
Upper Right ( 1616.0, 0.0)
Lower Right ( 1616.0, 1080.0)
Center ( 808.0, 540.0)
Band 1 Block=1616x1 Type=Byte, ColorInterp=Red
Mask Flags: PER_DATASET ALPHA
Band 2 Block=1616x1 Type=Byte, ColorInterp=Green
Mask Flags: PER_DATASET ALPHA
Band 3 Block=1616x1 Type=Byte, ColorInterp=Blue
Mask Flags: PER_DATASET ALPHA
Band 4 Block=1616x1 Type=Byte, ColorInterp=Alpha
带有渐变Alpha层的扭曲Geotiff的gdalinfo:
Driver: GTiff/GeoTIFF
Files: geo_dsc00603.tif
Size is 1944, 1356
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-88.275727919349990,40.518829195724997)
Pixel Size = (0.000001599004942,-0.000001599004942)
Metadata:
AREA_OR_POINT=Area
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_XRESOLUTION=350
TIFFTAG_YRESOLUTION=350
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( -88.2757279, 40.5188292) ( 88d16'32.62"W, 40d31' 7.79"N)
Lower Left ( -88.2757279, 40.5166609) ( 88d16'32.62"W, 40d30'59.98"N)
Upper Right ( -88.2726195, 40.5188292) ( 88d16'21.43"W, 40d31' 7.79"N)
Lower Right ( -88.2726195, 40.5166609) ( 88d16'21.43"W, 40d30'59.98"N)
Center ( -88.2741737, 40.5177451) ( 88d16'27.03"W, 40d31' 3.88"N)
Band 1 Block=1944x1 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=1944x1 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=1944x1 Type=Byte, ColorInterp=Blue
NoData Value=0
Band 4 Block=1944x1 Type=Byte, ColorInterp=Alpha
NoData Value=0
最终镶嵌的gdalinfo:
Driver: GTiff/GeoTIFF
Files: mosaic.tif
Size is 5702, 6846
Coordinate System is:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4326"]]
Origin = (-88.278946072799997,40.524561377550008)
Pixel Size = (0.000001509761581,-0.000001509761581)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( -88.2789461, 40.5245614) ( 88d16'44.21"W, 40d31'28.42"N)
Lower Left ( -88.2789461, 40.5142255) ( 88d16'44.21"W, 40d30'51.21"N)
Upper Right ( -88.2703374, 40.5245614) ( 88d16'13.21"W, 40d31'28.42"N)
Lower Right ( -88.2703374, 40.5142255) ( 88d16'13.21"W, 40d30'51.21"N)
Center ( -88.2746417, 40.5193935) ( 88d16'28.71"W, 40d31' 9.82"N)
Band 1 Block=5702x1 Type=Byte, ColorInterp=Red
NoData Value=0
Band 2 Block=5702x1 Type=Byte, ColorInterp=Green
NoData Value=0
Band 3 Block=5702x1 Type=Byte, ColorInterp=Blue
NoData Value=0
Band 4 Block=5702x1 Type=Byte, ColorInterp=Alpha
NoData Value=0
在该过程的每个阶段之后,我都包括了一个示例图像,最后一个镶嵌图位于此处的保管箱链接中-如有必要,我可以提供整个图像集。