描述:中值滤波器也是为了减少噪声,跟均值滤波器差不多,但是它比均值滤波器保留更多的细节。
什么是中值滤波器?
中值滤波器也是模板滤波器,不过此处的模板只是一个模板,里面没有数字而已。就想入下图所示:
此处展示的是一个3*3的模板,由图上可以看出中值滤波器就是取模板覆盖区域的排序之后的中间值作为该模板区域内中心的像素值。
Code:
/**
* Takes a 2D input image array and a kernel and a pixel location and
* calculates the new pixel value by calculating the median of its
* neighbours.
*
* @param input the 2D image array
* @param kernel the kernel array
* @param w the width of the input image
* @param h the height of the input image
* @param x the x coordinate of the pixel at the centre of the neighbourhood
* @param y the y coordinate of the pixel at the centre of the neighbourhood
*