Search code examples
matlabopencvhsv

MATLAB rgb2hsv() vs. OpenCV cvtColor()


Has anyone else noticed that the outputs of MATLAB's rgb2hsv() and OpenCV's cvtColor() (with the argument thereof being CV_BGR2HSV) appear to be calculated slightly differently?

For one, MATLAB's function maps any image input to the [0,1] interval, while OpenCV maintains the same interval of the input (i.e. an image with pixels in [0,255] in RGB keeps the same [0,255] interval in HSV).

But more importantly, when normalizing the cvtColor() output (e.g. mat = mat / 255), the values are not quite the same.

I couldn't find anything in the documentations about the specific formulas they use. Can anyone please shed some light on these differences?


Solution

  • For OpenCV the formula is right there in the document you point to. For Matlab, have a look here http://www.mathworks.com/matlabcentral/newsreader/view_thread/269237:

    Just dive into the code - they gave it to you. Just put the cursor on the function rgb2hsv() in your code and type control-d.