COMMANDS inpaint and inpaint_flow - GreycLab/gmic-community GitHub Wiki
Application: a known area of an image is totally lost and must be recovered by estimation typical examples in order of difficulty:
-
identifiable damage to a photograph by scratching
-
to create a stereo-gram or guess in-between frames of a motion sequence requires background fill
-
total object removal requires a seamless background repair
Approaches:
-
solve a smoothing equation that fits well with the observed boundary. GMIC inpaint_flow iteratively solves a pde, it is suitable for small areas or areas which should be smooth and copes with edge features across the missing areas.
-
clone textures from 'similar' areas. Cloning is a skilled manual job as the human eye spots features common within an exact repetition and discontinuities along straight edges, currently GMIC has no equivalent of GIMP's Resynth plugin which automatically generating non-repetitive textures and blends them.
-repair first released March 2013 v 1.5.5.1 (which as of 1.5.8.1 is merged with -inpaint) uses a patch-based algorithm, effectively cloning from similar image parts it tends to retain texture and extend patterns. The results are often comparable to Resynthesizer, it is a complex algorithm and slow for large areas.
-inpaint [mask]
This is a fast built-in function taking one image argument. Wherever the mask is non-zero the original target pixels are discarded and interpolated simply from the nearest neighbouring pixel without regularisation. The command is used only to initialise the iterative flow algorithm which would otherwise take a long time to flow in from the edges.
source
:::Perl
inpaint : [mask] : (+)
#@gmic : Inpaint selected images by specified mask.
#@gmic : $ image.jpg 100%,100% -ellipse 50%,50%,30,30,0,1,255 -ellipse 20%,20%,30,10,0,1,255 --inpaint[-2] [-1] -remove[-2]
-inpaint_flow nb_iter1,nb_iter2,dt,alpha,sigma
This is a complex iterative function, the mask MUST be [0] at each step of the standard pde_flow type loop the mask is applied to the delta, so the smoothing is only applied within that region.
The diffusiontensors computed with low sharpness and high anisotropy tend to preserve edge continuity from the boundary into the region itself.
source
:::Perl
#@gmic inpaint_flow : _nb_iter1>=0,_nb_iter2>=0,_dt>=0,_alpha,_sigma
#@gmic : Apply iteration of the inpainting flow on selected images.
#@gmic : Default values: 'nb_iter1=4', 'nb_iter2=15', 'dt=15', 'alpha=1' and 'sigma=3'.
#@gmic : $ image.jpg 100%,100% -ellipse[-1] 30%,30%,40,30,0,1,255 -reverse -inpaint_flow ,
inpaint_flow : -skip ${1=4},${2=15},${3=15},${4=1},${5=3}
-e[^-1] "Apply $1 iteration of the inpainting flow on image$?."
-v - -norm[0] -quantize[0] 2,1,1 -n[0] 0,1
-repeat @# -if $> -l[0,$>]
-r[0] [1] -inpaint[1] [0]
-repeat $1 --diffusiontensors[1] 0,1,$4,$5,0 -*[2] [0] -smooth[1] [2],$2,$3,0 -rm[2] -done
-endl -endif -done -v +
GIMP Filter __Enhancement / Inpaint region__
Simple GUI Interface for -inpaint_flow
source
:::Perl
#@gui Inpaint region : gimp_inpaint, gimp_inpaint_preview(0)
#@gui : Smooth inpaint = bool(true)
#@gui : Global iterations = int(10,1,30)
#@gui : Local iterations = int(10,1,30)
#@gui : Time step = float(20,5,50)
#@gui : Gradient smoothness = float(0.7,0,5)
#@gui : Tensor smoothness = float(1.2,0,5)
#@gui : note = note("<small><b>Note:</b>
#@gui : This filter tries to reconstruct the content of image regions.
#@gui : The inpainted region is defined as a white area in the top layer.
#@gui : </small>")
#@gui : sep = separator(), note = note("<small>Author: <i>David Tschumperlé</i>. Latest update: <i>2010/12/29</i>.</small>")
gimp_inpaint :
-if {@#==1} -return -endif
-if $1 -inpaint_flow $2,$3,$4,$5%,$6% -c 0,255 -else -inpaint[^0] [0] -endif
-to_rgba[0] -f[0] 0
gimp_inpaint_preview :
-if {@#==1} -return -endif
-gimp_inpaint ${^0} -rm[0]
see also Tschumperlé (2006)