M4 improv

Updated algorithm according to discussions to separate median calculation into four different horisontal blocks on the image.