title: How do you calculate the Affinity Matrix of an image?
body: <p>I've been reading the formulas on how to compute the affinity matrix of an image and I'm a bit confused. Ideally, I would like to use color intensity as a distance metric.</p>
  
  <p>I found this reference: <a href="http://spectrallyclustered.wordpress.com/2010/06/05/sprint-1-k-means-spectral-clustering/" rel="nofollow">http://spectrallyclustered.wordpress.com/2010/06/05/sprint-1-k-means-spectral-clustering/</a></p>
  
  <p>Which seems to do a great job of explaining the general process. My question is with respect to the affinity matrix.</p>
  
  <p>When constructing the affinity matrix (I'll call it A), they mention the affinity matrix should be KxK sized for a Kxn image. Other reference implementations say the affinity matrix for an MxN image should be (M*N) x (M*N):</p>
  
  <p><a href="http://www.mathworks.com/matlabcentral/fileexchange/26354-spectral-clustering-algorithms" rel="nofollow">http://www.mathworks.com/matlabcentral/fileexchange/26354-spectral-clustering-algorithms</a></p>
  
  <p>Which one is the traditional approach?</p>
  
  <p>When computing the affinity matrix, I wanted to know if each entry A(i,j) be a neighborhood computation (like the affinity of a 3x3 neighborhood or the pixels in the entire image)?</p>
  
  <p>Or do I linearize the image into a 1 dimensional array.</p>
  
  <p>Constructs an (m*n) x (m*n) matrix (the affinity matrix) and while iterating across the 1 dimensional image array, apply an affinity function to pixel i and every other pixel j. and stores the result into the affinity matrix.</p>
  
  <p>(basically a double nested for loop)</p>
  
  <p>am i off base? or is that about how it looks?</p>
  
  <p>Thanks in advance,</p>
  
  <p>ct</p>