pixel是通过标准jdk或android bitmap获取的图像32位像素数组
这个方法的滤波器尺寸是3*3,需要更大尺寸滤波器可以依此类推,ColorModel可根据各平台变化调整
private int[] medianFiltering(int[] pixel, int w, int h) {
int[] newPixel = new int[w * h];
int[] tempR = new int[9];
int[] tempG = new int[9];
int[] tempB = new int[9];
ColorModel cm = ColorModel.getRGBdefault();
// median values of the matrix
int r;
int g;
int b;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (x == 0 || x == w - 1 || y == 0 || y == h - 1) {
newPixel[y * w + x] = pixel[y * w + x];
continue;
}
tempR[0] = cm.getRed(pixel[x - 1 + (y - 1) * w]);
tempR[1] = cm.getRed(pixel[x + (y - 1) * w]);
tempR[2] &