title: Median filter of a pgm image
body: <p>I have to write a program that replaces each pixel with the median value of it and its 8 neighbors. What I have will compile but when i try to create a new image im getting multiple errors. Help is appreciated. </p>
  
  <p>Here's the stacktrace:</p>
  
  <pre><code>Exception in thread "main" java.lang.ClassCastException: [I cannot be cast to java.lang.Comparable
  at java.util.ComparableTimSort.countRunAndMakeAscending(ComparableTimSort.java:290)
  at java.util.ComparableTimSort.sort(ComparableTimSort.java:171)
  at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
  at java.util.Arrays.sort(Arrays.java:472)
  at ImageProcessing.median(ImageProcessing.java:25
  </code></pre>
  
  <p>And here's my code:</p>
  
  <pre><code>public static int [] [] median(int [] [] image) {
      int height = image.length;
      int width = image[0].length;
      int [] [] result = new int [height] [width];
  
      for (int col = 0 ; col &lt; image.length ; col++) {
          result[0][col] = image[0][col];
          result[height - 1][col] = image[height - 1][col];
      }
  
      for (int row = 0 ; row &lt; image[0].length ; row++) {
          result[row][0] = image[row][0];
          result[row][width - 1] = image[row][width - 1];
      }
  
      for (int row = 1 ; row &lt; height - 1 ; row++) {
          for (int col = 1 ; col &lt; width - 1 ; col++) {
              Arrays.sort(image);
              result[row][col] = image[row][col] / 2;
          }
      }
      return result;
  }
  </code></pre>