This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

dm6437 YUV to RGB, noise

Hello, everyone,

I am now doing video processing using DM6437.

Now I just want to convert from YUV ( 4:2:2 ) to RGB,  but unfortunately , I encountered a problem, the converted result is bellow:

 

Obviously, there exists a lot of noise.

The code I used are as follows( marked in red ):

First,I extract the YUV components, and put them in the arrays below,

unsigned char YArray[720*480] = {0};
unsigned char CrArray[720*240] = {0};
unsigned char CbArray[720*240] = {0};

then, I invoke the function below,

PIXEL_COLOR *YUV2RGB(unsigned char *Y,unsigned char *Cr,unsigned char *Cb,PIXEL_COLOR *RGB,int width,int height)
{
 int i = 0;
 int j = 0;
 int k = 0;
 for( i = 0; i< height;i++)
 {
  k = i*width;
  for(j = 0;j < width;j++)
  {
     
   RGB[k+j].r = (298*(Y[k+j]-16) + 409*(Cr[ (k+j) / 2] - 128) + 128) >> 8;
   RGB[k+j].g = (298*(Y[k+j]-16) - 208*(Cr[(k+j) / 2] - 128) - 100*(Cb[(k+j) / 2] - 128) + 128) >> 8;
   RGB[k+j].b = (298*(Y[k+j]-16) + 516*(Cb[(k+j) / 2] - 128) + 128) >> 8;
       
   if(RGB[k+j].r > 255)
   {
    RGB[k+j].r = 255;
   }
   else if(RGB[k+j].r < 0)
   {
    RGB[k+j].r = 0;
   }
   if(RGB[k+j].g > 255)
   {
    RGB[k+j].g = 255;
   }
   else if(RGB[k+j].g < 0)
   {
    RGB[k+j].g = 0;
   }
   if(RGB[k+j].b > 255)
   {
    RGB[k+j].b = 255;
   }
   else if(RGB[k+j].b < 0)
   {
    RGB[k+j].b = 0;
   }
  }
 }
 return RGB;
}

finally, I show the image  using ccs, the detailed steps are as follows:

View -> Graph -> Image...

Could anyone help me?

Thank you!

Zhiqiang

  • Hi Zhiqiang,

    I am not sure where you got the coefficient

       RGB[k+j].r = (298*(Y[k+j]-16) + 409*(Cr[ (k+j) / 2] - 128) + 128) >> 8;
       RGB[k+j].g = (298*(Y[k+j]-16) - 208*(Cr[(k+j) / 2] - 128) - 100*(Cb[(k+j) / 2] - 128) + 128) >> 8;
       RGB[k+j].b = (298*(Y[k+j]-16) + 516*(Cb[(k+j) / 2] - 128) + 128) >> 8;

    Would you be able to try

    .
    R = (1.00000 ´ Y) + (0.00000 ´ (Cb – 128)) + (1.40200 ´ (Cr – 128))
    G = (1.00000 ´ Y) – (0.34414 ´ (Cb – 128)) – (0.71444 ´ (Cr – 128))
    B = (1.00000 ´ Y) + (1.72200 ´ (Cb – 128)) + (0.00000 ´ (Cr – 128))

    or

    R = (1.00000 ´ Y) + (0.00000 ´ (Cb – 128)) + (1.37110 ´ (Cr – 128))
    G = (1.00000 ´ Y) – (0.33690 ´ (Cb – 128)) – (0.69820 ´ (Cr – 128))
    B = (1.00000 ´ Y) + (1.73240 ´ (Cb – 128)) + (0.00000 ´ (Cr – 128))

     

  • In addition to Paul's comments...

    This looks like you have overflow occurring somewhere.

    What are the structure types for "PIXEL_COLOR" ?If these are not int then you will get overflow and the comparison against ">255" will never be true.

    Additionally I would look at the precedence of the calculation step. Sometimes there are implicit type conversions which may be causing issues.

    What you are seeing is not actually noise, but roll-over on some of the color channels. This type of 'noise' appears when you have shaded regions which have color components which are close to either maximum or minimum values and you have not correctly handled roll over and calculation ranges.

    What are the intermediate values of "RGB[k+j].r" just after the calculation?

    Try putting a break point inside the range checking code to make sure that it does get there at some time.

       if(RGB[k+j].r > 255)
       {
        RGB[k+j].r = 255; //Set break point here
       }
       else if(RGB[k+j].r < 0)
       {
        RGB[k+j].r = 0;
    //Set break point here
       }

    BR,

    Steve

  • Hi Steve and Paul.Yin

    I am sure that the roll-over has happened.

    Now I have solved the problem.

    Thank you!

    Zhiqiang