How to get gray image from a RGB image

  • Dear All,

    I am working with GV-5260 CP color camera using VQ4-GE framegrabber for my application. I need to get gray image out of RGB image captured from the camera. I am using the following formula for extracting gray image:


    The three channels of the RGB image are passed as the first three channels of the input image. The image is transformed according to the following formula:

    gray = 0.299 * red + 0.587 * green + 0.114 * blue .

    Since there is no fractional input for any operators in Visual applets ( ver 3.1) , I have just multiplied the channels with 299,587 and 114 respectively and divided it by 1000. Is it the right way to do that or any other solution?

    Please refer my applet that I have attached here!



  • Dear Jayasuriya,

    Since your function is : R*0.299 + G*0.587 + B*0.114 you can also write it as : ( R*299 + G*587 + B114)/1000

    In your design you used DIV operation 3 times. You can use DIV operation just one time and get the same result. Also in your design using DIV operator 3 times decrease the precision. For example your first pixel value is R:21 G:27 B:45 acording to your design output od DIV operators are: 21*299/1000 = 6 and 27*587/1000=15 and 45*114/1000=5 and your final gray value will be 15+5+6 = 26. However your exact value must be 27.258 you will have 26. If you use DIV operator just one time then you will have : (21*299 + 27*587 + 45*114) / 1000 = 27. In this case you will increase the precision and also decrease the number of operators. Attachment you can have a look the example design. This is my suggestion to you. I dont know if there is another better solution.Hope that helps to you:)

    Have a nice day

  • Hello Jayasuriya

    your implementation is correct but there are other options as well which might be a little more efficient.

    1. Use operator ColorTransform

    This operator can be used with fractional numbers, Internally they are converted to fixed point values. As you only need one component set the other matrix coeffcients to 0.

    2. Use RGB2YUV. This operator actually performs a RGB to YCbCr conversion what you need.

    3. Same as your implementation but multiply with a power of 2 value instead of 1000. SO you can use shift right instead of a DIV operator. DIV requires many resources.

    See the attached design.


    Moreover it is important to set all dynamic parameters to static to save FPGA resources. Furthermore on mE4 a Scale can be replaced by HWMULT to use the FPGA hard coded multipliers. On mE5 use Mult. The program will automatically decide between LUTs or DSPs for multiplication.