Mic*_*lle 4 c++ opencv smooth histogram
我想平滑直方图.
因此我试图平滑内部矩阵cvHistogram
.
typedef struct CvHistogram
{
int type;
CvArr* bins;
float thresh[CV_MAX_DIM][2]; /* for uniform histograms */
float** thresh2; /* for non-uniform histograms */
CvMatND mat; /* embedded matrix header for array histograms */
}
Run Code Online (Sandbox Code Playgroud)
我试着像这样平滑矩阵:
cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
(...)
// smooth histogram with Gaussian Filter
cvSmooth( hist->mat, hist_img, CV_GAUSSIAN, 3, 3, 0, 0 );
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用,因为cvSmooth
需要CvMat
输入而不是a CvMatND
.我不能转化CvMatND
成CvMat
(CvMatND
在我的情况下,2-DIM).
有没有人可以帮助我?谢谢.
您可以使用与Mean滤波器相同的基本算法,只计算平均值.
for(int i = 1; i < NBins - 1; ++i)
{
hist[i] = (hist[i - 1] + hist[i] + hist[i + 1]) / 3;
}
Run Code Online (Sandbox Code Playgroud)
您可以选择使用稍微灵活的算法,以便轻松更改窗口大小.
int winSize = 5;
int winMidSize = winSize / 2;
for(int i = winMidSize; i < NBins - winMidSize; ++i)
{
float mean = 0;
for(int j = i - winMidSize; j <= (i + winMidSize); ++j)
{
mean += hist[j];
}
hist[i] = mean / winSize;
}
Run Code Online (Sandbox Code Playgroud)
但请记住,这只是一种简单的技术.
如果您真的想使用OpenCv工具,我建议您访问openCv论坛:http://tech.groups.yahoo.com/group/OpenCV/join