So I ended up making a GRASS script to mitigate edge effect from course imagery such as Landsat 8. Script is as follows. I know each step could be simplified but have it in steps helps understand what is going on.
Basically it does a neighbourhood count. It uses the output to discover the edge of the imagery. These gaps are given a null value. The null value is filled in with median value from 5x5 neighbourhood. The output is then masked to the original image.
See input & output side by side.
run_command("r.neighbors",
overwrite = True,
input = "in@PERMANENT",
output = "count",
method = "count",
size = 5)
run_command("r.mapcalc",
overwrite = True,
expression = "step1=if(count@PERMANENT<25 & count@PERMANENT>0,0,1)")
run_command("r.mapcalc",
overwrite = True,
expression = "step2=if( step1@PERMANENT==0,null(),1)")
run_command("r.mapcalc",
overwrite = True,
expression = "step3=if( count@PERMANENT ==0,0,1)* step2@PERMANENT")
run_command("r.mapcalc",
overwrite = True,
expression = "step4=if(isnull(in@PERMANENT )==1,0,in@PERMANENT)")
run_command("r.mapcalc",
overwrite = True,
expression = "step5=step4@PERMANENT * step3@PERMANENT")
run_command("r.neighbors",
overwrite = True,
input = "step5@PERMANENT",
output = "step6",
method = "median",
size = 5)
run_command("r.mapcalc",
overwrite = True,
expression = "step7=if(isnull(step6@PERMANENT )==1, step6@PERMANENT, in@PERMANENT )")
run_command("r.mapcalc",
overwrite = True,
expression = "step8=if(isnull(in)==0,step7,null())")