(C) Android OpenCV: the image pixel value statistics

Image pixel value statistics

  • Pixel maximum, minimum and a position
  • The image mean, standard deviation

Find the maximum, minimum

API

public static MinMaxLocResult minMaxLoc(Mat src, Mat mask)
  • Parameters src: input image matrix

  • Parameters mask: The optional mask matrix

  • Return Value MinMaxLocResult: record minimum, maximum, and its location

    public static class MinMaxLocResult {
        public double minVal;
        public double maxVal;
        public Point minLoc;
        public Point maxLoc;
    
    
        public MinMaxLocResult() {
            minVal=0; maxVal=0;
            minLoc=new Point();
            maxLoc=new Point();
        }
    }
    
  • Function requires the input image must be a single channel

Image matrix to find the minimum and maximum position

Because a single channel can only enter the picture, so to perform computing operations after the separation of the first

private fun minMaxLoc(source: Mat) {
    val bgrList = ArrayList<Mat>()
    Core.split(source, bgrList)

    var minLoc = Point()
    var maxLoc = Point()
    var minVal = 255.0
    var maxVal = 0.0
    var minCha = 0
    var maxCha = 0
    for (index in 0 until bgrList.size) {
        val tmp = Core.minMaxLoc(bgrList[index])
        if (tmp.minVal < minVal) {
            minVal = tmp.minVal
            minLoc = tmp.minLoc
            minCha = index
        }
        if (tmp.maxVal > maxVal) {
            maxVal = tmp.maxVal
            maxLoc = tmp.maxLoc
            maxCha = index
        }
    }
    val tmp =
        "最小值 = $minVal, 位于${minCha}通道${minLoc}\n最大值 = $maxVal, 位于${maxCha}通道${maxLoc}\n"
    message += tmp

    for (current in bgrList) {
        current.release()
    }
}

Mean and standard deviation

concept

  • Reflects the average brightness of an image, the greater the larger the mean image brightness, the smaller the contrary;

  • Standard deviation and variance are often called, is a deviation from the mean square root of the arithmetic mean, expressed as σ. The most commonly used in probability and statistics as a measure on the degree of statistical distribution. The standard deviation is the square root of the variance of the arithmetic. Standard deviation reflects the degree of dispersion of a data set. Standard deviation reflects the degree of dispersion image pixel values of the mean, standard deviation, the greater the better the image quality.

API

public static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble stddev, Mat mask)
  • Parameters src: input image matrix
  • Parameter mean: mean matrix of pixels of the output image
  • Parameters stddev: image pixel variance matrix output j
  • Parameters mask: The optional mask matrix

Image matrix calculated mean and standard deviation

private fun meanStdDev(source: Mat) {
    val mean = MatOfDouble()
    val stdDev = MatOfDouble()
    Core.meanStdDev(source, mean, stdDev)
    val tmp = "平均值:${mean.toList()}\n方差:${stdDev.toList()}\n"
    message += tmp
    mean.release()
    stdDev.release()
}

Calculation results

Source

https://github.com/onlyloveyd/LearningAndroidOpenCV

Scan left Fanger Wei code for the continual update

Published 160 original articles · won praise 265 · views 320 000 +

Guess you like

Origin blog.csdn.net/poorkick/article/details/104077782