changed median function so that the input image is now a pixel replicated image of correct dimensions