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.

Input YCbCr image to output Graylevels omage

Hello all,

I am currently working on an image processing project, using the DaVinci DM6437. Basically, the image processing within requires only the gray level values of the input image.

I modified the video_preview.c program a little, so that I am now able to capture a single frame by pressing the DIP switch, and displaying it on an external TV screen. So far so good (almost..), however, I cannot seem to find a proper way to create a gray level image, based on the YCbCr input image.

What I have done so far is a YCbCr2GrayscaleRowStack() function, that basically allocates a new array, half the size of the original input frame, and inserts the Y values one-by-one, simply by going over every other byte in the inputted frame.

The other function I created (inwhich probably the problem is somewhere) is called Grayscale2YCbCr() and is quoted here:

// CODE

// function: Grayscale2YCbCr; gets: current frame ptr, width and height of image (in pixels);
// returns: ptr to array of YCbCr valuess, length is width*height*2
unsigned char* Grayscale2YCbCr(unsigned char* CurrentFrame, int width, int height)
{
    int i;
    unsigned char* framePointer;
   
    framePointer = (unsigned char*)malloc((width * height * 2)); // create a new array for the YCbCr gray image
   
    for( i = 0; i < (width * height); i+=2)   
    {
        *(framePointer + i) = 0x80; // every even byte has midpoint value
        *(framePointer + (i+1) ) = *(CurrentFrame + i); // every odd byte gets the gray level value
    }

    return framePointer;

}

// END OF CODE

 

Both functions are very simple, and so is the basic idea. Now, the problem is the output image looks like that:


I have been searching a solution in this forum for quite some time now, and found this thread, with a resembling (but not the same) problem. I tried the size multiplying by two trick and it didn't work for. Notice that in my problem, I do receive the whole original information (besides the Cr & Cb bytes), only that it is displayed twice for some reason, and also leaving the bottom half of the screen blank (uninitialized most likely).

 

I will be very grateful for any sort of help, I hope i supplied enough information regarding the problem.

 

Thanks a lot, Yoav

 

  • Allright!, I've managed to find the main problem, it was in the Grayscale2YCbCr() function which didn't assign values to the whole buffer. new (and somewhat uglyier) code is:

    // CODE

    unsigned char* Grayscale2YCbCr(unsigned char* CurrentFrame, int width, int height)
    {
        int i, j=0;
        unsigned char* framePointer;
       
        framePointer = (unsigned char*)malloc((width * height * 2)); // create a new array for the YCbCr gray image
       
        for( i = 0; i < (width * height); i++)
        {
            if( (i % 2) == 0) // even index
            {
                *(framePointer + i) = 0x80;
            }
            else
            {
                *(framePointer + i) = *(CurrentFrame + j);
                j++;
            }
        }

        return framePointer;

     

    // END OF CODE

     

    also, as same as in the thread I mentioned before, I had to use a trick a multiplying the height of the frame sent to the function for somereason. Though it is mentioned in several places that this board produces 8bit YCbCr values, maybe they are indeed 16bit values.


    Yoav

  • can you please use this loop for converting grayscale to ycbcr.

    for( i = 0; i < (width * height); i+=1,j+=2)

    {

         *(framePointer + j) = 0x80; // every even byte has midpoint value

        *(framePointer + (j+1) ) = *(CurrentFrame + i); // every odd byte gets the gray level value

    }

    I am assuming that CurrentFrame is having all 'Y' values next to each other[not interleaved].  If you can share the code of YCbCr2GrayscaleRowStack()with us, its easier to figure out the issue.