title: How to Extract part of Image inside specified boundary in MATLAB
body: <p>I am new to MATLAB, i wanted to know that can i extract a part of image from inside of a specified boundary,based on distinguishing color(red boundary in my case),The function,first traces the boundary of the image,then it extracts that part of image which is inside that particular boundary. I have my image(image of human head) attached, i wanted to extract the brain part from the head, other part of image should be ignored. I tried to find edges,using the following code(it shows 1's for boundaries, and 0 for no boundary),but it showed only 0's.</p>
  
  <p>Any help will be greatly appreciated.</p>
  
  <p>P.S. image attached shows original image and image with boundary....the code will be working on the one with boundary and will extract the part of image lying inside that boundary.</p>
  
  <p>Below is the code i tried:</p>
  
  <pre><code>BW = edge(x)
  
  BW = edge(x,'sobel')
  BW = edge(x,'sobel',thresh)
  BW = edge(x,'sobel',thresh,direction)
  [BW,thresh] = edge(x,'sobel',...)
  
  BW = edge(x,'prewitt')
  BW = edge(x,'prewitt',thresh)
  BW = edge(x,'prewitt',thresh,direction)
  [BW,thresh] = edge(x,'prewitt',...)
  
  BW = edge(x,'roberts')
  BW = edge(x,'roberts',thresh)
  [BW,thresh] = edge(x,'roberts',...)
  
  BW = edge(x,'log')
  BW = edge(x,'log',thresh)
  BW = edge(x,'log',thresh,sigma)
  [BW,threshold] = edge(x,'log',...)
  
  BW = edge(x,'zerocross',thresh,h)
  [BW,thresh] = edge(x,'zerocross',...)
  
  BW = edge(x,'canny')
  BW = edge(x,'canny',thresh)
  BW = edge(x,'canny',thresh,sigma)
  [BW,threshold] = edge(x,'canny',...)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/DCsoT.jpg" alt="enter image description here"></p>