opencv4学习总结-图像像素信息统计

像素最大值最小值

using namespace cv;
using namespace std;


int main()
{
    Mat src = imread("E:/opencv_source/opencv/sources/samples/data/chicky_512.png",IMREAD_GRAYSCALE);
    imshow("src", src);
    int h = src.rows;
    int w = src.cols;
    int channels = src.channels();

    double min_val, max_val;
    Point minLoc;
    Point maxLoc;
    minMaxLoc(src, &min_val, &max_val, &minLoc, &maxLoc);//针对单通道Mat对象
    printf("minVal:%.2f,loc:(%d,%d)\nmaxVal:%.2f,loc:(%d,%d)\n", min_val, minLoc.x, minLoc.y, max_val, maxLoc.x, maxLoc.y);


    waitKey(0);
    destroyAllWindows();

    return 0;
}

均值和方差

using namespace cv;
using namespace std;


int main()
{
    Mat src = imread("E:/opencv_source/opencv/sources/samples/data/chicky_512.png");
    imshow("src", src);
    int h = src.rows;
    int w = src.cols;
    int channels = src.channels();

    Scalar s = mean(src);//计算每个通道的平均像素值
    printf("mean channel B:%.2f,mean channel G:%.2f,mean channel R:%.2f\n", s[0], s[1], s[2]);


    waitKey(0);
    destroyAllWindows();

    return 0;
}
using namespace cv;
using namespace std;


int main()
{
    Mat src = imread("E:/opencv_source/opencv/sources/samples/data/chicky_512.png");
    imshow("src", src);
    int h = src.rows;
    int w = src.cols;
    int channels = src.channels();

    Mat mm, mstd;
    meanStdDev(src, mm, mstd);
    printf("mean:%.2f,%.2f,%.2f\n", mm.at<double>(0, 0), mm.at<double>(1, 0), mm.at<double>(2, 0));
    printf("std:%.2f,%.2f,%.2f\n", mstd.at<double>(0, 0), mstd.at<double>(1, 0), mstd.at<double>(2, 0));



    waitKey(0);
    destroyAllWindows();

    return 0;
}