RGB to HSV Issue

RGB to HSV Issue


I'm using IPP

I need to convert RGB image to HSV color model.  I have a simple 2 pixel image to test, first pixel is RGB 0,0,254 (near pure blue), second pixel is

0,255,1 (near pure green).

First Pixel in HSV should be 240,100,100, but IPP sets first pixel components to 170,255,254.

Here is code for the simple test program I wrote (ReadImageJPEGHighLevel basically just calls ReadImageJPEG in jpeg.cpp that is included with IPP decoder package).

1) First is the JPEG reading method:

JERRCODE ReadImageJPEGHighLevel ( CIppImage& image, std::string fileName ){
    JERRCODE jerr;
    CStdFileInput in;
    UIC::BaseStream::TStatus status;
    status = in.Open(fileName.c_str());
    PARAMS_JPEG m_param_jpeg;
    m_param_jpeg.nthreads  = 2;
    m_param_jpeg.dct_scale = JD_1_1;
    m_param_jpeg.use_qdct  = 1;
    jerr = ReadImageJPEG(in, m_param_jpeg, image);
    return jerr;

2: Here is the sample test program that performs conversion:


string fileName= "C:\bluegreen.jpg";
    JERRCODE jerr;
    CIppImage imageRGB;
    CIppImage imageHSV;
    cout << "filename: " << fileName << endl;
    jerr=ReadImageJPEGHighLevel ( imageRGB, fileName );
        cerr << "read image failed"<<endl;
        cout << "read image success"<<endl;
        CIppImage imageHSV( imageRGB.Width(), imageRGB.Height(), imageRGB.NChannels(), imageRGB.Precision() );
        IppStatus hsvConversionStatus = ippiRGBToHSV_8u_C3R( imageRGB.DataPtr(), imageRGB.Step(), imageHSV.DataPtr(), imageHSV.Step(), imageHSV.Size() );
        if( hsvConversionStatus == ippStsNoErr ){
            Ipp8u* colorDataRGB = imageRGB.DataPtr();
            Ipp8u* colorDataHSV = imageHSV.DataPtr();
            cout << "RGB(0,0) = " << (int)colorDataRGB[0] << "," << (int)colorDataRGB[1] << "," << (int)colorDataRGB[2] << endl;
            cout << "HSV(0,0) = " << (int)colorDataHSV[0] <<","<<(int)colorDataHSV[1]<<","<<(int)colorDataHSV[2]<<endl;
           cout << "RGB->HSV Conversion error"<<endl;

I have included sample JPG in post.

Thank you,
Alessandro Ferrucci

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Alessandro, I don't see the JPG in this thread.

I have included the JPG now, sorry about that.


Downloadimage/jpeg bluegreen.jpg414 bytes


It seems that I am an idiot :)

I have looked into this and the results are correct.  I re-read the documentation and noticed "The computed H,S,V values are scaled to the full range of the destination data type".

So When I was using color dropper in GIMP, the HSV values for the first pixels are 240,100,100 (GIMP rounds to nearest ingeter).  The Hue is 240 degrees in color wheel so the ratio is 240/360=0.666666667, the S=100 and V=100  are 100%.  The values that IPP returns (170,255,254) are values related to the "MAX of the data type my Image is using", which is 255, so the Hue is 170 (170/255)=0.6666666667, 255/255 = 1 (100%) and 254/255 = 0.996.  So everything works as advertised it seems...I just didn't know how to interpret the return values :)


Alessandro Ferrucci

Leave a Comment

Please sign in to add a comment. Not a member? Join today