@@ -0,0 +1,1353 @@
+%0Apackage net.restlesscoder.sandbox.interview;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Apublic class MedianFilter %7B%0A%0A%09private static void medianFilter(double%5B%5D%5B%5D in, double%5B%5D%5B%5D out,%0A%09%09final int radius)%0A%09%7B%0A%09%09final int h = in.length, w = in%5B0%5D.length;%0A%09%09for (int y = 0; y %3C h; y++) %7B%0A%09%09%09for (int x = 0; x %3C w; x++) %7B%0A%09%09%09%09out%5By%5D%5Bx%5D = median(in, y, x, radius);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private static double median(double%5B%5D%5B%5D in, int py, int px, int radius) %7B%0A%09%09final int h = in.length, w = in%5B0%5D.length;%0A%09%09final List%3CDouble%3E pts = new ArrayList%3C%3E();%0A%09%09for (int y = py - radius; y %3C= py + radius; y++) %7B%0A%09%09%09for (int x = px - radius; x %3C= px + radius; x++) %7B%0A%09%09%09%09if (y %3E= 0 && y %3C h && x %3E= 0 && x %3C w) %7B%0A%09%09%09%09%09pts.add(in%5By%5D%5Bx%5D);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09Collections.sort(pts);%0A%09%09return pts.get(pts.size() / 2);%0A%09%7D%0A%0A%09public static void show(final String title, final double%5B%5D%5B%5D matrix,%0A%09%09final int radius)%0A%09%7B%0A%09%09final int w = matrix%5B0%5D.length, h = matrix.length;%0A%09%09final double%5B%5D%5B%5D scaled = new double%5Bh%5D%5Bw%5D;%0A%09%09medianFilter(matrix, scaled, radius);%0A%09%09Images.display(title, Images.makeBufferedImage(scaled));%0A%09%7D%0A%0A%09public static void main(final String... args) %7B%0A%09%09final int w = 300, h = 200;%0A%09%09final double%5B%5D%5B%5D matrix = Images.noise(w, h);%0A%0A%09%09show(%22Radius 1%22, matrix, 1);%0A%09%09show(%22Radius 3%22, matrix, 3);%0A%09%09show(%22Radius 7%22, matrix, 7);%0A%09%7D%0A%7D%0A

Add simple solution for doing a median filter