title: Finding the pixel that minimizes the distance between two sets
body: <p>I have a statement trying to implement but confused on how to do so. This is my issue:</p>
  
  <ul>
  <li>I have an image where I have set some pixels of interest (region of interest) to the value <code>1</code>. So, we can say that we now have a set with the following values <code>1s</code> where each <code>1</code> here represents a particular location in the image.</li>
  </ul>
  
  <blockquote>
    <p>C = [1 1 1 1 1 1 1 1 1 1];</p>
  </blockquote>
  
  <p>For example, say <code>img</code> for simplicity here is the matrix <code>x</code> as follows:</p>
  
  <pre><code>x = [2 3 5; 5 4 5; 6 4 3; 6 5 4; 6 54 3; 6 5 3];
  </code></pre>
  
  <p><code>x</code> will have a degree of membership <code>y</code> based on which we set some values to <code>1</code>. To clarify, for each pixel for which <code>y</code> = <code>1</code> we set that pixel to <code>1</code>. So, let's say <code>y</code> is:</p>
  
  <pre><code>y = [0 1 0; 0 1 1; 1 1 0; 0 0 1; 0 0 1; 1 1 1];
  </code></pre>
  
  <p>So, <code>C</code> contains 10 <code>1s</code>. For instance the first <code>1</code> represents the location <code>x(1,2)</code> and so forth...</p>
  
  <ul>
  <li><p>Now, I want to check the <code>4-neighbourhoods</code> of the pixels in <code>C</code> but that at the same time not in <code>C</code>. That is, on the surroundings.</p></li>
  <li><p>Now, for those pixels that belong to the surroundings and are four neighbors of <code>C</code> I want to select that pixel <code>p</code> that <strong>minimizes the distance</strong> between <code>x</code> and <code>C</code>.</p></li>
  </ul>
  
  <p>Is it clear now? Do you know how I can go around it?</p>
  
  <p>Thanks.</p>