0

I have a raster image with some values are nan and these are supposed to be filled by the valid values. These valid values should meet two conditions: within a certain distance to the target pixel, and are flagged as true in an input FlagMask. The rasterio.fill.fillnodata https://rasterio.readthedocs.io/en/latest/api/rasterio.fill.html can achieve filling nodata with the distance condition but not the FlagMask condition. The inpaint in matlab https://uk.mathworks.com/matlabcentral/fileexchange/27994-inpaint-over-missing-data-in-1-d-2-d-3-d-nd-arrays works similarly as rasterio.fill.fillnodata. Would appreciate existing functions or some ideas about modifying based on some modules. An efficient algorithm will be desired as my raster input will be more than 5000*5000.

Xue
  • 65
  • 11

1 Answers1

0

I would simply run inpaintn() and then reset those elements which are not flagged back to NaN. I'm having difficulty thinking of a scenario where the practical difference between your algorithm and my proposal is meaningful, if you have an example data set let me know.

aosborne
  • 371
  • 1
  • 7
  • Thanks for your answer! But I think the inpaint() is an automatic progressive process, meaning the NaN will be filled progressively until all done. I cannot find a place insert the set not flagged as NaN. I am using it to inpaint the holes in DEM, the flagged layer is Road-1 and None-road-0, I only want the valid values from the road be used in filling the NaN. – Xue Feb 11 '21 at 22:12
  • I must be misunderstanding. I'm not recommending you change `inpaint()` at all. Say you have a DEM raster image with NaNs interspersed and you know the elements which are road and which are not. Do two runs: `inpaint(image_masked_by_isroad)` and `inpaint(image_masked_by_isnotroad)`. Then recombine into a single image by using the same masks. I assume the masks provide full coverage of the image, without overlap. – aosborne Feb 11 '21 at 22:22
  • Could you explain a bit more? Wouldn't the inpaint(image_masked_by_isroad) fill values outside the road and these values will then participant in filling the road progressively? My understanding about inpaint is that it is an progressive process. – Xue Feb 11 '21 at 23:31
  • When I read the code I understood it to be iterative, not progressive. An initial guess is made based on nearest neighbor interpolation and then cosine transforms are iteratively applied to smooth the result. – aosborne Feb 11 '21 at 23:48