title: How to visualize an image segment borders in Matlab?
body: <p>I have a matrix with segment indices for each pixel of image. How can I visualize the borders of the segments? The most obvious idea is to use diff filter to obtain the edge map, but it looks very ugly. How can I make the image look like here?
  <a href="http://www.vlfeat.org/overview/slic.html" rel="nofollow">http://www.vlfeat.org/overview/slic.html</a></p>
  
  <p>UPD: I've tried this and it looks OK. The code itself looks ugly, perhaps it can be written in a more elegant form.</p>
  
  <pre><code>boundaries = zeros(size(segments));
  boundaries(2:end, :) = boundaries(2:end, :) + (segments(2:end, :) ~= segments(1:end-1, :));
  boundaries(:, 2:end) = boundaries(:, 2:end) + (segments(:, 2:end) ~= segments(:, 1:end-1));
  </code></pre>