#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
#include<iostream>
using namespace std;
using namespace cv;
//计算给定阈值下的熵
float calCurrentEntropy(Mat& hist, int threshold)
{
float backgroundSum = 0, targetSum = 0;
const float* pDataHist = (float*)hist.ptr<float>(0);
for (int i = 0; i < 256; i++)
{
if (i < threshold)
{
backgroundSum += pDataHist[i];
}
else
targetSum += pDataHist[i];
}
float backgroundEntropy = 0, targetEntropy = 0;
for (int i = 0; i < 256; i++)
{
if (i < threshold)
{
if (pDataHist[i] == 0)
continue;
float ratio1 = pDataHist[i] / backgroundSum;
backgroundEntropy += -ratio1*logf(ratio1);
}
else
{
if (pDataHist[i] == 0)
continue;
float ratio2 = pDataHist[i] / targetSum;
targetEntr
opencv实现最大熵求解
最新推荐文章于 2023-04-07 15:23:25 发布