"functional" version of Inpanting algorithm