Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

RGB to HSV Issue

alessandroferrucci
692 Views

Hello,

I'm using IPP 6.1.2.041.

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:

[cpp]JERRCODE ReadImageJPEGHighLevel ( CIppImage& image, std::string fileName ){
    JERRCODE jerr;

    image.Color(JC_UNKNOWN);

    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);
    in.Close();
    return jerr;
}[/cpp]

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

    [cpp]string fileName= "C:\\bluegreen.jpg";
    JERRCODE jerr;
    CIppImage imageRGB;
    CIppImage imageHSV;
    cout << "filename: " << fileName << endl;
    jerr=ReadImageJPEGHighLevel ( imageRGB, fileName );
    if(jerr!=JPEG_OK){
        cerr << "read image failed"<<endl;
    }else{
        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;
        }else{
           cout << "RGB->HSV Conversion error"<<endl;
        }
    }
    imageRGB.Free();
    imageHSV.Free();[/cpp]

I have included sample JPG in post.

Thank you,
Alessandro Ferrucci

0 Kudos
3 Replies
Gennady_F_Intel
Moderator
692 Views

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

0 Kudos
alessandroferrucci
692 Views

I have included the JPG now, sorry about that.

0 Kudos
alessandroferrucci
692 Views

Hello,

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 :)

Thanks.

Alessandro Ferrucci

0 Kudos
Reply