title: how to extract the objects inside the region of interest in matlab
body: <p>I am interested in extracting the objects inside the region. </p>
  
  <p>For example, </p>
  
  <p>Fig1 showed the intensity profile of my laser profile. According to the laser intensity, I divide the profile into 2 region of interest (ROI1 and ROI2). </p>
  
  <p>Fig2 showed the overlap of my exp result of positive responses and the laser intensity profile. The positive response data file is composed of x and y coordinates. As you can see the results are scattered over the laser profile image.</p>
  
  <p>Here is what I want to do, I want to extract the spots within the ROI2 and discard all the rest as shown in Fig3. How can I do it? Specifically, how can I define a irregular shape ROI2 in matlab and extract the coordinates of positive response data.
  Thanks for the help.</p>
  
  <p><img src="https://i.stack.imgur.com/lycUT.png" alt="enter image description here"></p>