title: find nearest neighbor to each pixel in a map
body: <p>I am trying to find a simple method in python in which for each pixel in a 2dim mask, I can get the indices of the nearest non-zero neighbor. In Matlab there is a bwdist which returns exactly that. 
  for example: if my input is:</p>
  
  <pre><code>array [[0 0 0 0 0 0 0]
         [0 1 0 0 0 0 0]
         [0 0 0 0 0 1 0]
         [0 0 0 0 0 0 0]]
  </code></pre>
  
  <p>my output should be:</p>
  
  <pre><code>array [[(1,1) (1,1) (1,1) (1,1) (2,5) (2,5) (2,5)]
         [(1,1) (1,1) (1,1) (1,1) (2,5) (2,5) (2,5)]
         [(1,1) (1,1) (1,1) (2,5) (2,5) (2,5) (2,5)]
         [(1,1) (1,1) (1,1) (2,5) (2,5) (2,5) (2,5)]]
  </code></pre>
  
  <p>The function can also return the absolute index (for 1dim array) like bwdist in Matlab.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: so far, I have tried some potential solutions relating to scipy such as distance_transform_edt, but it only finds the distance to the closest pixel and not the pixel itself.
  I also use OpenCV and VLfeat in other places in my code if its relevant. </p>