Correcting errors in median filtering