title: Image Segmentation Using K means
body: <p>When I execute the following command in Matlab 2012a</p>
  
  <pre><code>centroids=kmeans(imread('image.jpg'),4);
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Error using  +
  Integers can only be combined with integers of the same class, or scalar doubles.
  
  Error in kmeans&gt;distfun (line 659)
  
              D(:,i) = D(:,i) + (X(:,j) - C(i,j)).^2;
  
  Error in kmeans (line 273)
  
  D = distfun(X, C, distance, 0, rep, reps);
  </code></pre>
  
  <p>I need to segment the image into 4 clusters. The image is a CT Brain tumour image in <code>JPEG</code> format. The size of this image is <code>233x216</code>.<br>
  Please give me a solution to cluster this image file.</p>