Image pixel value statistics
- Maximum, minimum and position of image pixels
- Image mean and standard deviation
Find maximum and minimum values
API
public static MinMaxLocResult minMaxLoc(Mat src, Mat mask)
Copy the code
-
Parameter SRC: input image matrix
-
Parameter mask: Optional mask matrix
-
Return value MinMaxLocResult: Records the minimum value, maximum value, and their positions
public static class MinMaxLocResult {
public double minVal;
public double maxVal;
public Point minLoc;
public Point maxLoc;
public MinMaxLocResult(a) {
minVal=0; maxVal=0;
minLoc=new Point();
maxLoc=new Point();
}
}
Copy the code -
The function requires that the input image must be single channel
Find the maximum and minimum values of the image matrix and their positions
Since only a single channel image can be entered, the calculation operation is performed after separation
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 =
"Minimum =$minVal, located in the${minCha}channel${minLoc}\n Maximum value =$maxVal, located in the${maxCha}channel${maxLoc}\n"
message += tmp
for (current in bgrList) {
current.release()
}
}
Copy the code
Mean and standard deviation
concept
-
The mean value reflects the brightness of the image. The greater the mean value is, the greater the brightness of the image is, and vice versa.
-
The standard deviation, also known as the mean square error, is the square root of the arithmetic mean of the square of the mean deviation, denoted by σ. It is most commonly used in probability statistics as a measure of the degree of statistical distribution. Standard deviation is the arithmetic square root of variance. Standard deviation can reflect the degree of dispersion of a data set. Standard deviation reflects the degree of dispersion between the pixel value and the mean value of the image. The larger the standard deviation is, the better the quality of the image is.
API
public static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble stddev, Mat mask)
Copy the code
- Parameter SRC: input image matrix
- Parameter mean: output image pixel mean matrix
- Parameter stddev: J-matrix of output image pixel variance
- Parameter mask: Optional mask matrix
Calculate the mean and standard deviation of the image matrix
private fun meanStdDev(source: Mat) {
val mean = MatOfDouble()
val stdDev = MatOfDouble()
Core.meanStdDev(source, mean, stdDev)
val tmp = "Average value:${mean.toList()}\ n variance:${stdDev.toList()}\n"
message += tmp
mean.release()
stdDev.release()
}
Copy the code
The calculation results
The source code
https://github.com/onlyloveyd/LearningAndroidOpenCV
This article is formatted using MDNICE