There are two terms which play a role here: confidence and data term. confidence signifies the amount of reliable information in the neighbourhood. And data term represents the presence of strong edges hitting the mask boundary.