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

RGBToYCbCr returns wrong range

kkirtac
Beginner
525 Views
Hi, I am usingippiRGBToYCbCr_8u_C3Rto convert the colorspace of a rgb image to YCbCr.
The returned range of the Y channel is different than it should be, i.e., it has a maximum of 255 value, though as it says in the documentation and in theory that it cannot be greater than 235.
Below is the source code that I used:
_________________________________________________________________________________________
void getY_8u(Ipp8u* pSrc, int srcStep, Ipp8u* pDst, int dstStep, IppiSize roiSize)
{
IppStatus sts = ippiCopy_8u_C3C1R(pSrc+0, srcStep, pDst, dstStep, roiSize);
assert(sts==ippStsNoErr || sts!=ippStsNullPtrErr || sts!=ippStsSizeErr || sts!=ippStsStepErr);
}
IppStatus sts;
int srcStep;
Ipp8u* pSrcYCbCr = ippiMalloc_8u_C3(imgWidth, imgHeight, &srcStep);
int dstStep = srcStep;
sts = ippiRGBToYCbCr_8u_C3R(pSrc,srcStep,pSrcYCbCr,srcStep,srcRoiSize); //RGB to YCbCr conversion
assert(sts==ippStsNoErr || sts!=ippStsNullPtrErr || sts!=ippStsSizeErr);
int srcYstep;
Ipp8u* pSrcY = ippiMalloc_8u_C1(imgWidth , imgHeight, &srcYstep); //Y channel
getY_8u(pSrc, srcStep, pSrcY, srcYstep, srcRoiSize);
Ipp8u max,min;
sts = ippiMax_8u_C1R(pSrcY, srcYstep, srcRoiSize, &max);
sts = ippiMin_8u_C1R(pSrcY, srcYstep, srcRoiSize, &min);
_________________________________________________________________________________________
When I do the same rgb2ycbcr operation in matlab, it produces a maximum of 226 for the same image while ipp function produces 255.
What could be wrong?
Best regards.
0 Kudos
8 Replies
Vladimir_Dudnik
Employee
525 Views
Hello,

could you please provide input RGB values for the point where you believeyou get wrong YCbCr result?

Regards,
Vladimir
0 Kudos
kkirtac
Beginner
525 Views
hello,
I've checked for one of the pixel location for which 255 is produced, and found out that the corresponding RGB values are 91,207,89, respectively.
The Y channel output for that triple should be (0.257*91) + (0.504*207) + (0.098*89) + 16 =152.4370.
I give the code below, which I find matching pixel locations in input image, for generated 255 values:
________________________________________________________________________________________
for (int i=0; i
for (int j=0; j
if ( pSrcY[i*srcYstep+j] == max )
{
printf("%d\n%d\n%d\n",pSrc[i*srcStep+j],pSrc[i*srcStep+j+1],pSrc[i*srcStep+j+2]);
}
________________________________________________________________________________________
My input image has 512*512 size, and hence, srcYstep=512, srcStep=512x3=1536 .
Thanks..
0 Kudos
kkirtac
Beginner
525 Views
Hi again,

I changed the printf code to
printf("%d\n",(Ipp8u)0.257*pSrc[i*srcStep+j]+0.504*pSrc[i*srcStep+j+1]+0.098*pSrc[i*srcStep+j+2]+16);

which prints out a value 1133871366 . How can a value such that big can be produced with integer arithmetic of
range 0-255 ?
0 Kudos
kkirtac
Beginner
525 Views
Well, it prints the right value when the pSrc pixel values are casted to float before the arithmetic:
printf("%d\n",(Ipp8u)((0.257*(float)pSrc[i*srcStep+j])+(0.504*(float)pSrc[i*srcStep+j+1])+(0.098*(float)pSrc[i*srcStep+j+2])+16));

but, whyippiRGBToYCbCr_8u_C3Rfunction can't produce this value? Maybe it doesnt implicitly cast the rgb values to float type prior to arithmetic, and so the previous wrong value of1133871366is generated and converted to the biggest value of the range,i.e.,255 .
0 Kudos
kkirtac
Beginner
525 Views
It's ok now, its all my fault that I was using the wrong image pointer while retrieving the Y channel. I noticed that I am giving the original rgb input image to the functiongetY_8u.. so its normal to see 255 values in Y image..
this thread can be removed..
Best regards.
0 Kudos
Vladimir_Dudnik
Employee
525 Views

Coould you please double check that your assumption that image step for your case is really 512*3. This depends on how you allocated memory for your 512x512 C3 image.

Vladimir

0 Kudos
kkirtac
Beginner
525 Views
it was all my fault that I used wrong input, sorry,
this thread can be removed..
Thank you.
0 Kudos
Vladimir_Dudnik
Employee
525 Views
No problem, thanks for updating us and I'm really glad IPP work for you as expected (I hope) :)

Vladimir
0 Kudos
Reply