如何平滑直方图?
我想平滑直方图。
因此我尝试平滑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 */
}
我尝试像这样平滑矩阵:
cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
(...)
// smooth histogram with Gaussian Filter
cvSmooth( hist->mat, hist_img, CV_GAUSSIAN, 3, 3, 0, 0 );
不幸的是,这不起作用,因为 cvSmooth
需要 CvMat
作为输入而不是 CvMatND
。我无法将 CvMatND
转换为 CvMat
(CvMatND
在我的例子中是 2-dim)。
有人可以帮助我吗?谢谢。
I want to smooth a histogram.
Therefore I tried to smooth the internal matrix of 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 */
}
I tried to smooth the matrix like this:
cvCalcHist( planes, hist, 0, 0 ); // Compute histogram
(...)
// smooth histogram with Gaussian Filter
cvSmooth( hist->mat, hist_img, CV_GAUSSIAN, 3, 3, 0, 0 );
Unfortunately, this is not working because cvSmooth
needs a CvMat
as input instead of a CvMatND
. I couldn't transform CvMatND
into CvMat
(CvMatND
is 2-dim in my case).
Is there anybody who can help me? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用与均值过滤器相同的基本算法,只需计算平均值。
您可以选择使用稍微灵活的算法,以便轻松更改窗口大小。
但请记住,这只是一种简单的技术。
如果您确实想使用 OpenCv 工具来完成此操作,我建议您访问 openCv 论坛:http: //tech.groups.yahoo.com/group/OpenCV/join
You can use the same basic algorithm used for Mean filter, just calculating the average.
Optionally you can use a slightly more flexible algorithm allowing you to easily change the window size.
But bear in mind that this is just one simple technique.
If you really want to do it using OpenCv tools, I recommend you access the openCv forum: http://tech.groups.yahoo.com/group/OpenCV/join
您可以通过更改使用的箱数来显着改变直方图的“平滑度”。一个好的经验法则是,如果有 n 个数据点,则有 sqrt(n) 个 bin。您可以尝试将此启发式应用于直方图,看看是否会得到更好的结果。
You can dramatically change the "smoothness" of a histogram by changing the number of bins you use. A good rule of thumb is to have sqrt(n) bins if you have n data points. You might try applying this heuristic to your histogram and see if you get a better result.