huge refactoring of non local means