如何平滑直方图?

发布于 2024-08-12 02:10:05 字数 752 浏览 13 评论 0原文

我想平滑直方图。

因此我尝试平滑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 转换为 CvMatCvMatND 在我的例子中是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

够钟 2024-08-19 02:10:05

您可以使用与均值过滤器相同的基本算法,只需计算平均值。

for(int i = 1; i < NBins - 1; ++i)
{
    hist[i] = (hist[i - 1] + hist[i] + hist[i + 1]) / 3;
}

您可以选择使用稍微灵活的算法,以便轻松更改窗口大小。

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;
}

但请记住,这只是一种简单的技术。

如果您确实想使用 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.

for(int i = 1; i < NBins - 1; ++i)
{
    hist[i] = (hist[i - 1] + hist[i] + hist[i + 1]) / 3;
}

Optionally you can use a slightly more flexible algorithm allowing you to easily change the window size.

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;
}

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

叹梦 2024-08-19 02:10:05

您可以通过更改使用的箱数来显着改变直方图的“平滑度”。一个好的经验法则是,如果有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文