我如何模仿medfilt2的Matlab与OpenCV? [英] How can I imitate medfilt2 of Matlab with OpenCV?
本文介绍了我如何模仿medfilt2的Matlab与OpenCV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个成像应用程序写在Matlab中,需要将其转换为C ++应用程序与OpenCV。但我似乎找不到一个简单的方法来模仿medfilt2与OpenCV。
I have an imaging application written in Matlab and need to convert it into C++ app with OpenCV. But I can't seem to find an easy way to imitate medfilt2 with OpenCV.
我尝试MedianBlur,但它没有产生相同的结果。
I tried MedianBlur but it didn't produce the same result. Could anybody give me any clue for this task?
推荐答案
对我来说,这个链接应该有您需要的。
然而,如果你想通过 m $ c $指定
n
c> window。
It would appear to me that this link should have what you need.
However, looks like you'll have to make a minor modification if you want to specify the n
by m
window.
// Pick up window elements
int k = 0;
// Original: element window[9];
element window[n_win*m_win];
for (int j = m_win - 1; j < m_win; ++j)
for (int i = n_win - 1; i < n_win; ++i)
window[k++] = image[j * N + i];
// Order elements (only half of them)
// make sure (n_win*m_win)/2 is odd :-)
for (int j = 0; j < (n_win*m_win)/2; ++j)
{
// Find position of minimum element
int min = j;
for (int l = j + 1; l < n_win*m_win; ++l)
if (window[l] < window[min])
min = l;
// Put found minimum element in its place
const element temp = window[j];
window[j] = window[min];
window[min] = temp;
}
// Get result - the middle element
result[(m - 1) * (N - 2) + n - 1] = window[4];
这篇关于我如何模仿medfilt2的Matlab与OpenCV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文