其他分享
首页 > 其他分享> > Android OpenCV(三):图像像素值统计

Android OpenCV(三):图像像素值统计

作者:互联网

图像像素值统计

查找最大值、最小值

API

public static MinMaxLocResult minMaxLoc(Mat src, Mat mask)

寻找图像矩阵最大值最小值及其位置

由于只能输入单通道图片,所以先分离后执行计算操作

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()
    }
}

均值与标准差

概念

API

public static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble stddev, Mat mask)

计算图像矩阵均值和标准差

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()
}

计算结果

源码

https://github.com/onlyloveyd/LearningAndroidOpenCV

扫描左方二维码关注持续更新

onlyloveyd 博客专家 发布了160 篇原创文章 · 获赞 265 · 访问量 32万+ 他的留言板 关注

标签:tmp,maxVal,minVal,像素,OpenCV,标准差,图像,Android,public
来源: https://blog.csdn.net/poorkick/article/details/104077782