Median filter with previous edge detection and inversion@