title: Detect exact color range of most spread color in a given image using OpenCv C++
body: <p>I am new to OpenCV and developing image processing program using opencv c++. I have a image with only defined color (ex - pink). </p>
  
  <p><a href="https://i.stack.imgur.com/8FntD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8FntD.jpg" alt="enter image description here"></a></p>
  
  <p>I get the RGB value of image to 3 separate arrays.If I consider R value array, I can get number set like bellow.If I consider that number set, there is a standard values and other numbers should have a close values to it. But there are some numbers which are highly deviated from that number and I want to remove them from number set.In the bellow number set should remove 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 57  and 243 , 255 , 255 .Finally I want to get color range of given color image.I want to get 166 - 170 range cluster .What is the best way to solve this?. Is there any simple way to solve this  using opencv? or have to develop algorithm?</p>
  
  <p>0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 57 , 166 , 166 , 166 , 166 , 166 , 166 , 166 , 166 , 167 , 167 , 167 , 167 , 167 , 167 ,167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 167 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 168 , 169 , 169 , 169 , 169 , 169 , 169 , 169 , 169 , 170 , 170 ,170 , 243 , 255 ,  255</p>
  
  <p>Here is my</p>
  
  <pre><code>        Mat image;
          image = imread("saved.jpg", CV_LOAD_IMAGE_COLOR);
          const int SIZE = image.rows*image.cols;
          int bValue[SIZE];
          int gValue[SIZE];
          int rValue[SIZE];
          int index = 0;
          for(int i=1;i &lt;= image.rows; i++){
              for(int j=1;j &lt;= image.cols; j++){
                  int b = (int)(image).at&lt;cv::Vec3b&gt;(j,i)[0];
                  int g = (int)(image).at&lt;cv::Vec3b&gt;(j,i)[1];
                  int r = (int)(image).at&lt;cv::Vec3b&gt;(j,i)[2];
  
                  bValue[index]= b ;
                  gValue[index]= g ;
                  rValue[index]= r ;
                  index++;                    
              }                
          }
          sort(bValue,bValue+SIZE);
          sort(gValue,gValue+SIZE);
          sort(rValue,rValue+SIZE);
  </code></pre>