Make calculation of mask_edge free of branches, faster of course but probably