Opencv: three gray algorithms for color images

Source: Internet
Author: User

In order to accelerate the processing speed in the image processing algorithm, color images often need to be converted into gray images. 24 represents each pixel of a color image in three bytes. Each byte corresponds to the brightness of the RGB component.

When the RGB component value is different, it is displayed as a color image. When the RGB component is the same, it is converted into a gray image:

Generally, there are three conversion formulas.

(1) Gray (I, j) = [R (I, j) + g (I, j) + B (I, j)]/3;

(2) Gray (I, j) = 0.299 * R (I, j) + 0.587 * g (I, j) + 0.144 * B (I, j );

(3) Gray (I, j) = g (I, j); // from 2, we can see that G has a large component, so we can directly use it instead.

The following code is used:

1 # include <cv. h> 2 # include 

Original Image:

Grayscale image generated by algorithm 1:

Grayscale image generated by algorithm 2:

Grayscale image generated by algorithm 3:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.