title: How to Extract part of Image using Matlab
body: <p>i have not used matlab much, i need to extract the part of Left and Right Coronary Arteries of a heart from a given heart image. </p>
  
  <p>this is my image, <img src="https://i.stack.imgur.com/j8kdR.jpg" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/9y35V.jpg" alt="enter image description here"></p>
  
  <p>based on morphological operations, this is what i have come up with,</p>
  
  <pre><code>f=imread('heart.jpg');
  diam=strel('diamond',19);
  line=strel('line',10,90);
  linef=imclose(f,line);
  line120=strel('line',10,120);
  line120f= imclose(f,line120);
  bothline=linef+line120f;
  diamf=imclose(f,diam);
  arterybm=diamf-bothline;
  binaryartery= im2bw(arterybm,0);
  mask=cast(binaryartery,class(f));
  redPlane=f(:,:,1);
  greenPlane=f(:,:,2);
  bluePlane=f(:,:,3);
  maskedRed=redPlane.*mask;
  maskedGreen=greenPlane.*mask;
  maskedBlue=bluePlane.*mask;
  maskedRGBImage=cat(3,maskedRed,maskedGreen,maskedBlue);
  subplot(2,3,1);imshow(f);title('Input Image');subplot(2,3,2);imshow(diamf);title('imclose with Diamond Mask');subplot(2,3,3);imshow(bothline);title('imclose with Line 120 and 90 mask');subplot(2,3,4);imshow(arterybm);title('Difference of line and diamond');subplot(2,3,5);imshow(binaryartery);title('Convert to binary image');subplot(2,3,6);imshow(maskedRGBImage);title('Apply mask to input image');
  </code></pre>
  
  <p><strong>is there any better approach ?</strong></p>