title: Replace values in an 2d array according to neighboring values
body: <p>I have an array (n,m) :</p>
  
  <pre><code> [255 100 255]
   [100 255 100]
   [255 100 255]
  </code></pre>
  
  <p>I need to create a new array like that where neigboring values are tested an if North, East, South, West are ALL equal to 100 my value is set to 100 :</p>
  
  <pre><code> [255 100 255]
   [100 100 100]
   [255 100 255]
  </code></pre>
  
  <p>I have a simple solution that loops on 1:n and 1:m but it is obviously very slow and I am wondering if there is way to do it faster.
  I found several links that are talking about sliding window to compute average but i don't see how i can keep track of my indexes to create the new array.
  <a href="https://stackoverflow.com/questions/4936620/using-strides-for-an-efficient-moving-average-filter" title="Using strides for an efficient moving average filter">Using strides for an efficient moving average filter</a></p>
  
  <p>Thanks in advance for your inputs.</p>