[gdal-dev] gdal_fillnodata.py filling interior holes in RGB images

Travis Kirstine traviskirstine at gmail.com
Thu Oct 13 10:02:24 EDT 2011


Brian,

Thanks for your help, I had to switch up some of the commands to get
it to work.  This is what I did:

# merge all the tiles
gdalwarp -co TILED=YES -dstnodata 0 1000m/*.tif merged.tif

# create a mask file for nodata at the edge of the image
nearblack -near 0 -nb 0 -setmask -setalpha merged.tif -o mask.tif

# grab the mask band as a vrt
gdal_translate -of VRT -b 4 mask.tif mask.vrt

# fill holes for each band
gdal_fillnodata.py -md 1 -b 1 merged.tif r.tif
gdal_fillnodata.py -md 1 -b 2 merged.tif g.tif
gdal_fillnodata.py -md 1 -b 3 merged.tif b.tif

# recombine the bands with the mask
gdalbuildvrt -resolution highest -separate rgba.vrt r.tif g.tif b.tif mask.vrt

# convert to 3 band image with external mask file
gdal_translate -of GTiff -mask 4 -b 1 -b 2 -b 3 rgba.vrt rgb.tif

# convert the fill to rgb with mask applied
gdalwarp -co TILED=YES -dstnodata 0,0,0 -wo INIT_DEST=0 rgb.vrt final.tif

I may have a extra step in there but it works.  In the method you had
recommended the last gdalwarp command failed to recognize the 4th band
as a mask


Regards



On 12 October 2011 13:20, Travis Kirstine <traviskirstine at gmail.com> wrote:
> Thanks Brian,
> I'll give it a try.
>
> Regards
>
> On 12 October 2011 13:00, Brian Case <rush at winkey.org> wrote:
>> Travis,
>>
>> you have to run gdal_fillnodata on each band, then splice the outputs
>> back together.
>>
>> if the nodata areas on the inside do not connect to the outside area you
>> could create an alpha band
>>
>> ### -color 0,0,0 assumes odata value of 0
>> nearblack -dstalpha -near 0 -nb 0 -setalpha -color 0,0,0 \
>>          myfile.tif -o mytmpfile.tif
>> gdal_translate -b 4 -of VRT mytmpfile.tif a.vrt
>>
>> gdal_fillnodata.py -md 1 -b 1 myfile.tif r_filled.tif
>> gdal_fillnodata.py -md 1 -b 2 myfile.tif g_filled.tif
>> gdal_fillnodata.py -md 1 -b 3 myfile.tif b_filled.tif
>>
>> gdalbuildvrt -resolution highest -separate filled.vrt \
>>             r_filled.tif g_filled.tif b_filled.tif a.vrt
>>
>> if you want an rgba image use
>> gdal_translate filled.vrt filled.tif
>>
>> otherwise for rgb with nodata use
>>
>> ### INIT_DEST=0 assumes nodata value of 0
>> gdalwarp -wo INIT_DEST=0 filled.vrt filled.tif
>>
>> if your interior nodata areas connect to the outside nodata areas. I
>> don't know howto deal with that other than to just live with the extra
>> pixel around the outside of the valid data.
>>
>> Brian
>>
>>
>> On Wed, 2011-10-12 at 08:46 -0400, Travis Kirstine wrote:
>>> I have some RGB orthophotos that have interior holes, typically 1
>>> pixel.  Most of the images have "valid" nodata around the edges.  I
>>> would like to fill the interior holes while maintaining the valid
>>> nodata around the edges.  I have tried gdal_fillnodata.py but cannot
>>> get the utility to return a multiband image and / or interpolate only
>>> interior holes.
>>>
>>> Any help would be much appreciated
>>> _______________________________________________
>>> gdal-dev mailing list
>>> gdal-dev at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
>>
>


More information about the gdal-dev mailing list