int* data = new int[imgL.rows * imgL.cols];
for (int y = 0; y < imgL.rows; y++)
{
for (int x = 0; x < imgL.cols; x++)
{
data[y * imgL.cols + x] = imgL.at<uchar>(y, x);
}
}
Mat imgL1 = imgL.clone();
int wnd_size = 5;
int radius = wnd_size / 2;
int size = wnd_size * wnd_size;
vector<int>wnd_data;
for (uint y = 0; y < imgL.rows; y++)
{
for (uint x = 0; x < imgL.cols; x++)
{
wnd_data.clear();
for (int r = -radius; r <= radius; r++)
{
for (int c = -radius; c <= radius; c++)
{
int row = y + r;
int col = x + c;
if (row >= 0 && row < imgL.rows && col >= 0 && col < imgL.cols)
{
//wnd_data.push_back((int)imgL1.at<uchar>(row, col));
wnd_data.push_back(data[row * imgL.cols + col]);
}
}
}
sort(wnd_data.begin(), wnd_data.end());
imgL1.at<uchar>(y, x) = wnd_data[wnd_data.size() / 2];
}
}
delete[]data;
图像滤波窗口demo
最新推荐文章于 2024-02-19 19:49:22 发布