private static Image medianFilter(Image image) {
		if (image == null)
			return null;
		ImageData imageData = image.getImageData();
		int height = imageData.height;
		int width = imageData.width;
		int mx = width - 1;
		int my = height - 1;
		int[][] matrix = new int[height][width];
		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				int[] pixels = getNeighbours(imageData, mx, my, y, x);

				ArrayList<Integer> a = new ArrayList<Integer>();
				for (int n = 0; n < pixels.length; n++)
					a.add(pixels[n]);
				Collections.sort(a);
				int pixel = a.get(4);

				matrix[y][x] = pixel;
				// imageData.setPixel(x, y, matrix[y][x]);
			}
		}

		for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				imageData.setPixel(x, y, matrix[y][x]);
			}
		}

		image = new Image(image.getDevice(), imageData);
		return image;
	}