Monday, 8 April 2019

gdal - gdalwarp outline artefact


I'm using GDAL to warp images into a different map-projections. However the warping processes seem to leave grey marks where the boundary of the original image was (see warped.png below). I figured out this was probably caused by my image having a white background and the 'filler' pixels created by the warping process being transparent but black. And the interpolation is smudging the black and white together (even though it shouldn't as the black is transparent).


Is there any way to avoid the grey outline from appearing? Maybe force gdalwarp to fill with opaque white rather than transparent black?



I can't do a square crop on the warped image as I'll loose bits of the image, and I can't just make my background black instead of white as this messes up some filtering I have to do beforehand.


There seems to be lots of options for gdalwarp that sound useful like -srcnodata but I can't figure out how to use them.


input.png


warped.png


warped.tiff



Answer



Using the -r near flag will implement nearest-neighbor resampling. If that doesn't get rid of the border, at least it will make it pure black!


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...