How to do Image Pixel value Statistics in C++ OpenCV
The editor today takes you to understand how to carry out image pixel value statistics in C++ OpenCV. The knowledge points in the article are introduced in great detail. Friends who think it is helpful can browse the content of the article with the editor, hoping to help more friends who want to solve this problem to find the answer to the problem. Now follow the editor to learn in depth the knowledge of "how to carry out image pixel value statistics in C++ OpenCV".
Preface
Opencv knowledge points:
Image Pixel Min / Max-minMaxLoc
Image pixel mean / standard deviation-meanStdDev
1. Commonly used pixel value statistics
In image analysis, we often need to count the pixels of a single-channel image. The following four are commonly used.
Minimum (min)
Maximum (max)
Average (mean)
Standard deviation (standard deviation)
To require these four kinds of statistics, we need to use the following two API
MinMaxLoc
MeanStdDev
These two API are very useful and will be used in many places in the future.
two。 Statistical calculation of pixel value
Next, let's apply two API to get four pixel value statistics.
The first is the minimum value and the maximum value.
/ / function definition void pixel_statistics_demo (Mat& image); / / function implementation void QuickDemo::pixel_statistics_demo (Mat& image) {double minv, maxv; Point minLoc, maxLoc; std::vector mvt; split (image, mvt) / * minMaxLoc calculates the minimum pixel value of a single-channel image The maximum value is a total of 6 parameters, the first parameter input single channel image, the second parameter output minimum value, the third parameter output maximum value, the fourth parameter output minimum point coordinates, the fifth parameter output maximum point coordinates The sixth parameter inputs a subarray of the image (sometimes we find the minimum / maximum value of the ROI region The mask image will be passed in) (the subarray here is an image mask that can add things / buttons) * / for (int I = 0) I < mvt.size ()) {minMaxLoc (mvt [I], & minv, & maxv, & minLoc, & maxLoc); std::cout