title: Find maximum Euclidean distance of Canny edge output and drawing a line between the points
body: <p>I am new to Matlab and I am working on a project wherein I want to draw a line between the farthest two  edges of an image.
  I have first used Canny edge detection algorithm to get the edges.
  Stored the boundaries in a vector.
  Then, I have calculated the Euclidean distances amongst all the pixels stored inside the vector.
  The problem I am having is storing the maximum value obtained of this Euclidean distance and plotting a line amongst those two pixels.</p>
  
  <p>Here is an example image:<br/>
  <img src="https://i.stack.imgur.com/6Mymk.png" alt="enter image description here"></p>
  
  <p>Code:</p>
  
  <pre><code>im = edge(gray,'canny',0.3);
  subplot(2,2,3);imshow(im);title('Canny Output');
  figure
  imagesc(im)
  hold on
  
  [B,L] = bwboundaries(im,'noholes');
  for l=1:length(B)-1
      for m=l+1:length(B)-1
          for j=1:length(B{l})
              for k=1:length(B{m})
                  a(j,k) = abs(B{l}(j,2) - B{m}(k,2));
                  b(j,k) = abs(B{l}(j,1) - B{m}(k,1));
                  c(j,k) = sqrt(sum(a(j,k)*a(j,k),b(j,k)*b(j,k)));
                  [~,idx] = max(c(j,k));
                  [x,y] = ind2sub(size(c),idx);
                  p1.l = [B{l}(x,2),B{l}(x,1)];
                  p2.m = [B{m}(y,2),B{m}(y,1)];
                  plot([p1.l(1),p2.m(1)],[p1.l(2),p2.m(2)],'Color','g','LineWidth',2)
                  clear a b c x y idx
              end
          end
      end
  end
  </code></pre>