title: Discard outlier SIFT Key Points in Cell Image with OpenCV
body: <p>I'm approaching a task of Bio Informatics, and need to extract some features from some cell images.</p>
  
  <p>I used SIFT algorithm to extract Key Points inside of the image, as you can see in the picture.</p>
  
  <p><img src="https://i.stack.imgur.com/WjKPy.jpg" alt="enter image description here"></p>
  
  <p>As you can also see in the picture (circled in red), some key points are outliers and I don't want to calculate any feature on them. </p>
  
  <p>I obtained the <code>cv::KeyPoint</code> vector with the following code: </p>
  
  <pre><code>const cv::Mat input = cv::imread("/tmp/image.jpg", 0); //Load as grayscale
  
  cv::SiftFeatureDetector detector;
  std::vector&lt;cv::KeyPoint&gt; keypoints;
  detector.detect(input, keypoints);
  </code></pre>
  
  <p>but I would like to discard from the <code>vector</code> all those key points that, say for example, have less than 3 key points inside of a certain region of interest (ROI) centred on them in the image.</p>
  
  <p>Therefore I need to implement a function returning the number of key points inside of a certain ROI given as input:</p>
  
  <pre><code>int function_returning_number_of_key_points_in_ROI( cv::KeyPoint, ROI );
     //I have not specified ROI on purpose...check question 3
  </code></pre>
  
  <p>I have three questions:</p>
  
  <ol>
  <li>Is there any existing function doing something similar?</li>
  <li>If not can you give me some help in understanding how to implement it by myself?</li>
  <li>Would you use a circular, or rectangular ROI for this task?And how would you specify it in input?</li>
  </ol>
  
  <p>Note: </p>
  
  <p>I forgot to specify that I would like an efficient implementation for the function, i.e. checking for each key point the relative position of all others with respect to it would not be a good solution (if there exists another way of doing).</p>