Pixelation in the RGBToHSV color conversion function

Pixelation in the RGBToHSV color conversion function

Hello again,
I am experiencing pixelation when performing RGBToHSV color conversion.

A picture of this can be found here:
Before the conversion process
http://www.andrew.cmu.edu/user/bmeeder/noConv.bmp
After the conversion process
http://www.andrew.cmu.edu/user/bmeeder/conv.bmp

Is there anything that I should know about this function that would affect how it is performing? The code that I am using is as follows:

void HSVThresholdGTVal_I(CBuffer *buf, RECTANGLE region, int val, int satisfyValue, int data)
{
#define iw buf->w()
#define ih buf->h()
assert(region.top >= 0 && region.top < region.bottom && region.left >= 0 && region.right > region.left);
//code to figure out the region of interest that we are going to be dealing with
int roiW, roiH;
int offset;
int tempSB;
int paneSB;

//the region of interest should be contained within the image
if(region.left < iw && region.top < ih)
{
if(region.right <= iw)
roiW = region.right - region.left;
else
roiW = iw - region.left;
if(region.bottom <= ih)
roiH = region.bottom - region.top;
else
roiH = ih - region.top;
IppiSize roi = {roiW, roiH};
offset = (region.top * buf->StepSize() + region.left)*3;
Ipp8u* temp = ippiMalloc_8u_C3(roiW, roiH, &tempSB);
Ipp8u* pane = ippiMalloc_8u_C1(roiW, roiH, &paneSB);
ippiRGBToHSV_8u_C3R(buf->Buffer() + offset, buf->StepSize(), temp, tempSB, roi);
//copy the right part of the buffer over
//data specifies whether hue, sat. or value is copied
ippiCopy_8u_C3C1R(temp + data, tempSB, pane, paneSB, roi);
//clear the region that we are looking at
ippiSet_8u_C3R(BLACK, buf->Buffer() + offset, buf->StepSize(), roi);
ippiCopy_8u_C1C3R(pane, paneSB, buf->Buffer() + offset, buf->StepSize(), roi);
ippiCopy_8u_C1C3R(pane, paneSB, buf->Buffer() + offset+1, buf->StepSize(), roi);
ippiCopy_8u_C1C3R(pane, paneSB, buf->Buffer() + offset+2, buf->StepSize(), roi);

}

#undef iw
#undef ih
}

Many thanks,
Brendan Meeder

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

Let me perhaps as a different question:

Does RGBToHSV perform the function on every single pixel in the image, or does it work on groups of pixels to increase performance?

Many thanks,

Brendan

Hi, ippiRGBToHSV work on pixel by pixel basis in reference implementation. Of course, it might use some optimization technics in optimized code. The pseudo code looks like that:

// Reference:
// David F.Rogers
// Procedural elements for computer graphics
// 1985.pp.(401-403)
//
// H is the hue red at 0 degrees, which has range [0 .. 360 degrees],
// S is the saturation,
// V is the value
// The RGB to HSV conversion algorithm in pseudocode:
// Value:
// V = max(R,G,B);
// Saturation:
// temp = min(R,G,B);
// if V = 0 then // achromatics case
// S = 0
// H = 0
// else // chromatics case
// S = (V - temp)/V
// Hue:
// Cr = (V - R) / (V - temp)
// Cg = (V - G) / (V - temp)
// Cb = (V - B) / (V - temp)
// if R = V then H = Cb - Cg
// if G = V then H = 2 + Cr - Cb
// if B = V then H = 4 + Cg - Cr
// H = 60*H
// if H < 0 then H = H + 360
//
// The HSV to RGB conversion algorithm in pseudocode:
// if S = 0 then
// R = G = B = V
// else
// if H = 360 then
// H = 0
// else
// H = H/60
// I = floor(H)
// F = H - I;
// M = V * ( 1 - S);
// N = V * ( 1 - S * F);
// K = V * ( 1 - S * (1 - F));
// if(I == 0)then{ R = V;G = K;B = M;}
// if(I == 1)then{ R = N;G = V;B = M;}
// if(I == 2)then{ R = M;G = V;B = K;}
// if(I == 3)then{ R = M;G = N;B = V;}
// if(I == 4)then{ R = K;G = M;B = V;}
// if(I == 5)then{ R = V;G = M;B = N;}
//
// in the range [0..IPP_MAX_8u ] for the 8u depth,
// in the range [0..IPP_MAX_16u] for the 16u depth,

Regards,
Vladimir

Hello everybody,

I am using IPL2.5 (ok ancient tool, but at the end we are a university;)) I want to ask a question about the rgb2HSV tool used by IPL. I used the one embedded in IPL, and compared it with theoretical values, however I observed differences between them. (The theoretical values I used were the one described in here, and the formula described in Gonzalez's book with arccos)Does anybody know what conversion is using IPL's RGB2HSV tool?

IPL library not released for several years. You should know that there are University license for IPP, see IPP web page for more details

Regards,
Vladimir

Leave a Comment

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