Phase unwrapping algorithm using edge detection and statistical cost functions