title: Count occurrences of integers in moving window on 2-dimensional numpy array
body: <p>I would like to calculate per integer how often this value occurs within a moving window. I have no idea however how to tackle this as I can only find how to calculate a focal mean. </p>
  
  <p>So the window has the size:</p>
  
  <pre><code>kernel =array([[1, 1, 1],
                 [1, 1, 1],
                 [1, 1, 1]])
  </code></pre>
  
  <p>The input data:</p>
  
  <pre><code>input = array([[3, 3, 2, 3],
                 [3, 1, 2, 3],
                 [2, 1, 1, 1],
                 [3, 1, 3, 2]])
  </code></pre>
  
  <p>The output should look like the following:
  First "layer" count of 1, Second "layer" count of 2 etc.</p>
  
  <pre><code>output = array([[[1, 1, 1, 0],
                   [2, 3, 4, 2],
                   [3, 4, 5, 3],
                   [2, 3, 4, 2]],
                  [[0, 2, 2, 0],
                   [1, 3, 2, 2],
                   [1, 2, 2, 2],
                   [1, 1, 1, 1]],
                  [[3, 3, 3, 2],
                   [3, 3, 3, 2],
                   [2, 3, 2, 2],
                   [1, 2, 1, 1]]])
  </code></pre>
  
  <p>The output should be a 3 dimensional array. x, y the dimensions of the original array, and z the amount of unique integers. Each layer shows the count per unique integer. </p>
  
  <p>if you have any directions on how to solve this that would be great. </p>