title: intersection points of line and object - Matlab
body: <p>I marked in green one coin (green) in the coin image and I pass a line over it. How can I find the x,y points that they are intersecting?
  Thanks in advance.</p>
  
  <p><a href="https://i.stack.imgur.com/4msLv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4msLv.jpg" alt="enter image description here"></a></p>
  
  <pre><code>clc;
  clear; 
  
  I = imread('coins.png'); 
  BW = im2bw(I);
  
  BW_filled = imfill(BW,'holes');
  
  boundaries = bwboundaries(BW_filled);  
  figure,imshow(I) ;
  
  hold on;
  
  b = boundaries{1}; 
  plot(b(:,2),b(:,1),'g','LineWidth',1);
  
  h = imline;
  myPoints = wait(h);
  delete(h)  ;
  x1 = round(myPoints(1,1),2);
  y1 = round(myPoints(1,2),2);
  x2 = round(myPoints(2,1),2);
  y2 = round(myPoints(2,2),2);
  
  %plot line
  x=[x1 x2];
  y=[y1 y2];
  plot(x',y','r')
  </code></pre>