Opencv Statistical Application-mean and standard deviation

Source: Internet
Author: User
The mean and Mark difference is the most basic thing in statistics. cvavg () is an average data calculation and supports multi-channel usage. The method used is as follows:

Simple cvavg () Implementation
# Include <cv. h>
# Include # Include <stdio. h>
IntMain ()
{
Iplimage * image1 = cvloadimage ("grotto.jpg", 1 );
Cvscalar scalar1;
Scalar1 = cvavg (image1 );

Printf ("blue channel AVG is: %. f/N", scalar1.val [0]);
Printf ("Green Channel AVG is: %. f/N", scalar1.val [1]);
Printf ("red channel AVG is: %. f/N", scalar1.val [2]);

Cvnamedwindow ("grotto", 1 );
Cvshowimage ("grotto", image1 );
Cvwaitkey (0 );
}

The result of the rows:

The same as cvsum (), and the only difference between cvsum () and cvsum () is that it supports the operation of the mask, cvavg () calculate the average number of white parts of the black and white masks. The usage is as follows:

Implementation of a single cvavg () mask
# Include <cv. h>
# Include # Include <stdio. h>
IntMain ()
{
Iplimage * image1 = cvloadimage ("grotto.jpg", 1 );
Iplimage * maskimage1 = cvloadimage ("grotto_threshold.jpg", 0 );
Cvscalar scalar1;
Scalar1 = cvavg (image1, maskimage1 );

Printf ("blue channel AVG is: %. f/N", scalar1.val [0]);
Printf ("Green Channel AVG is: %. f/N", scalar1.val [1]);
Printf ("red channel AVG is: %. f/N", scalar1.val [2]);

Cvnamedwindow ("grotto", 1 );
Cvshowimage ("grotto", image1 );
Cvwaitkey (0 );
}

The result of the rows:

Calculate the average number of the white part of the previous cave's binarization black and white parts as the mask, and opencv also has another function to calculate the average value cvavgsdv (), it can calculate the mean and Mark difference at the same time, and also supports the actual mask. The usage is as follows:

Simple cvavgsdv () Implementation
# Include <cv. h>
# Include # Include <stdio. h>
IntMain ()
{
Iplimage * image1 = cvloadimage ("grotto.jpg", 1 );
Cvscalar meanscalar;
Cvscalar standarddeviationscalar;
Cvavgsdv (image1,&Meanscalar,&Standarddeviationscalar );

Printf ("blue channel AVG is: %. f/N", meanscalar. Val [0]);
Printf ("blue channel standard deviation is: %. f/N", standarddeviationscalar. Val [0]);
Printf ("Green Channel AVG is: %. f/N", meanscalar. Val [1]);
Printf ("Green Channel standard deviation is: %. f/N", standarddeviationscalar. Val [1]);
Printf ("red channel AVG is: %. f/N", meanscalar. Val [2]);
Printf ("Red Channel standard deviation is: %. f/N", standarddeviationscalar. Val [2]);

Cvnamedwindow ("grotto", 1 );
Cvshowimage ("grotto", image1 );
Cvwaitkey (0 );
}

The result of the rows:

The above section uses cvavgsdv () to calculate the mean data and the standard deviation, and also uses the cvscalar data structure to receive the data value. Then, it is part of the mask.

Implementation of a single cvavgsdv () mask
# Include <cv. h>
# Include # Include <stdio. h>
IntMain ()
{
Iplimage * image1 = cvloadimage ("grotto.jpg", 1 );
Iplimage * maskimage1 = cvloadimage ("grotto_threshold.jpg", 0 );
Cvscalar meanscalar;
Cvscalar standarddeviationscalar;
Cvavgsdv (image1,&Meanscalar,&Standarddeviationscalar, maskimage1 );

Printf ("blue channel AVG is: %. f/N", meanscalar. Val [0]);
Printf ("blue channel standard deviation is: %. f/N", standarddeviationscalar. Val [0]);
Printf ("Green Channel AVG is: %. f/N", meanscalar. Val [1]);
Printf ("Green Channel standard deviation is: %. f/N", standarddeviationscalar. Val [1]);
Printf ("red channel AVG is: %. f/N", meanscalar. Val [2]);
Printf ("Red Channel standard deviation is: %. f/N", standarddeviationscalar. Val [2]);

Cvnamedwindow ("grotto", 1 );
Cvshowimage ("grotto", image1 );
Cvnamedwindow ("grotto_threshold", 1 );
Cvshowimage ("grotto_threshold", maskimage1 );

Cvwaitkey (0 );
}

The result of the rows:

It also uses a single-channel binarization image as cvavg () as a mask to calculate the mean and standard deviation, and is not limited to linear embedding, in fact, any amount of data can be written into the database. The following figure shows how to calculate the mean data and the standard data.

Cvmat Data Structure Calculation average data difference
# Include <cv. h>
# Include # Include <stdio. h>

Uchar array [10] = {1, 2, 4, 5, 6, 7, 8, 9 };
IntMain ()
{
Cvmat * matrix1 = cvcreatemat (1, 10, cv_8uc1 );
Cvsetdata (matrix1, array, matrix1-> step );

Cvscalar meanscalar;
Cvscalar standarddeviationscalar;
Cvavgsdv (matrix1,&Meanscalar,&Standarddeviationscalar );

Printf ("matrix1 AVG is: %. f/N", meanscalar. Val [0]);
Printf ("matrix1 standard deviation is: %. f/N", standarddeviationscalar. Val [0]);

System ("pause ");
}

The result of the rows:

In practice, many of the functional iplimage information structure and cvmat information structure can be shared, including the previous cvcountnonzero (), cvsum (), cvavg () and cvavgsdv ().

Cvavg ()
Calculate the average number of iplimage data structure or cvmat data structure, and support the operation of the mask, the first data source is the iplimage data structure or cvmat data structure, and the second data source is the uchar-type unique mask response of the iplimage data structure, outputs the cvscalar Information Structure
Cvavg)

Cvavgsdv ()
Calculate the average number of the iplimage data structure or cvmat data structure, with a poor standard, supporting the calculation of the mask channel, the first is to import the iplimage data structure or cvmat data structure, and the second is to export the cvscalar average data structure, the third Reference refers to the cvscalar mark difference information structure, and the fourth Reference refers to the signature of the uchar-type unique mask in the single-channel iplimage data structure.
Cvavgsdv (imports the iplimage data structure or cvmat data structure, generates the average cvscalar data structure, and generates the cvscalar data structure according to the standard deviation, uchuch (uchar-type iplimage data structure)

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.