@@ -0,0 +1,1046 @@
+%0Apackage net.restlesscoder.sandbox.interview;%0A%0Apublic class ResampleImage %7B%0A%0A%09/** %22Nearest%22 neighbor resampling. */%0A%09public static void resampleNN(final double%5B%5D%5B%5D in, final double%5B%5D%5B%5D out) %7B%0A%09%09final int iw = in%5B0%5D.length, ih = in.length;%0A%09%09final int ow = out%5B0%5D.length, oh = out.length;%0A%0A%09%09for (int oy = 0; oy %3C oh; oy++) %7B%0A%09%09%09final int iy = ih * oy / oh;%0A%09%09%09for (int ox = 0; ox %3C ow; ox++) %7B%0A%09%09%09%09final int ix = iw * ox / ow;%0A%09%09%09%09out%5Boy%5D%5Box%5D = in%5Biy%5D%5Bix%5D;%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09public static void show(final String title, final double%5B%5D%5B%5D matrix,%0A%09%09final double scale)%0A%09%7B%0A%09%09final int w = matrix%5B0%5D.length, h = matrix.length;%0A%09%09final int ow = (int) (w * scale), oh = (int) (h * scale);%0A%09%09final double%5B%5D%5B%5D scaled = new double%5Boh%5D%5Bow%5D;%0A%09%09resampleNN(matrix, scaled);%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.gradient(w, h);%0A%0A%09%09show(%223.5x%22, matrix, 3.5);%0A%09%09show(%221.5x%22, matrix, 1.5);%0A%09%09show(%220.333x%22, matrix, 0.333);%0A%09%7D%0A%7D%0A

Add simple solution for resampling an image