title: Get hue (HSV/HSB) value of RGB using Emgu C# yields wrong result
body: <p>I am using <a href="http://www.emgu.com/wiki/index.php/Main_Page" rel="nofollow noreferrer">EMGU.CV</a> 3.4.1.2976 (latest) library to analyze images but I am not getting the results I expect. I benchmark against <a href="https://imagej.nih.gov/ij/" rel="nofollow noreferrer">ImageJ</a> but any image package should do.</p>
  
  <p>To test functionality, I am analyzing a simple blue 640x320 jpeg like below. The RGB value for this image is 0,0,255.</p>
  
  <p><a href="https://i.stack.imgur.com/DiKqI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DiKqI.jpg" alt="test image to get hue value from"></a></p>
  
  <p>Hue histogram from ImageJ (value is 170, count 2048000)</p>
  
  <p><a href="https://i.stack.imgur.com/UHXhw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UHXhw.png" alt="Hue histogram of blue jpeg"></a></p>
  
  <p>Using code below I get a spike at 120 instead of the 170 - count 2048000 is correct though.
  What am I doing wrong?</p>
  
  <pre><code>    public void AnalyzeEmgu(object image)
      {
          int[] arr = new int[256];
  
          using (Bitmap bmp = (Bitmap)image)
          {
              using (Image&lt;Hsv, byte&gt; hsvImage = new Image&lt;Hsv, byte&gt;(bmp))
              {
                  Image&lt;Gray, byte&gt;[] channels = hsvImage.Split();
                  Image&lt;Gray, byte&gt; imgHue = channels[0];
  
                  for (int x = 0; x &lt; imgHue.Rows; x++)
                  {
                      for (int y = 0; y &lt; imgHue.Cols; y++)
                      {
                          var b = imgHue.Data[x, y, 0];
                          arr[b]++; // fill array with Hue data. Add 1 (++) to count amount.
                      }
                  }
              }
          }
  
          GC.Collect();
          OnImageFinished(arr); // return array 
      }
  
    // call function.
    Bitmap bmp =new Bitmap(@"c:\test\blue.jpg");
    AnalyzeEmgu(bmp);
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>It turns I need to convert to a different color space but it still is not 100 % correct. <code>arr</code> now returns 171 instead of 170. It is of course only a slight difference but for more complex images it is noticable. </p>
  
  <p>What can be the problem? </p>
  
  <pre><code>    public void AnalyzeEmgu(object image)
      {
          int[] arr = new int[256];
  
          using (Mat orig = new Mat((string)image, ImreadModes.Color))
          {
              using (Mat hsv = new Mat())
              {
                  // convert color to HSV here.
                  CvInvoke.CvtColor(orig, hsv, ColorConversion.Bgr2HsvFull);
                  Mat[] channels = hsv.Split();
  
                  using (Image&lt;Bgr, byte&gt; img = channels[0].ToImage&lt;Bgr, byte&gt;())
                  {
                      for (int x = 0; x &lt; img.Rows; x++)
                      {
                          for (int y = 0; y &lt; img.Cols; y++)
                          {
                              var b = img.Data[x, y, 0];
                              arr[b]++;
                          }
                      }
                  }
                  channels[1].Dispose();
                  channels[2].Dispose();
              }
          }
          GC.Collect();
      }
  
      OnImageFinished(arr);
  </code></pre>