Same as median_filter, using another approach

Something is wrong with how we calculate the median… what? Bug hunting
Simple median is not enough

Code modified to take into account that different images have different
intensity values
Minor changes