使用OpenCV实现径向模糊 [英] Implement radial blur with OpenCV

查看:158
本文介绍了使用OpenCV实现径向模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想要校正数码相机中镜头引入的场曲。我们计划使用数字非锐化掩模而不是应用高斯模糊我们想尝试径向模糊,因此锐化会对图像边缘产生更大的影响。

We would like to correct for field curvature introduced by a lens in a digital camera. We plan to use a digital unsharp mask Instead of applying a Gaussian blur we would like to try a radial blur, so the sharpening has more impact toward the edges of the image.

使用OpenCV创建径向模糊的最简单方法是什么?

What is simplest way to create a radial blur using OpenCV ?

推荐答案

上面的答案很接近,但遗漏了一些关键因素,让我想一想。
我已经改变了地图,以便他们正确地计算缩放和缩小,并在每个位置从x和y添加/减去它们(否则你最终会将图像重新映射到一个小方块。我也是将/ blur更改为* blur,否则你的地图将包含非常大的数字,而不是正确的(每个位置的极大倍数)。

The answer above is close but missing a few key elements that took me a bit to figure out. I've changed the maps so that they are correctly calculating the zoom and shrink and added/subtracted them from the x and y at each position (otherwise you will just end up remapping your image to a tiny square. Also I changed the /blur to *blur otherwise your maps will contain very large numbers and just not come out right (extremely large multiples of each position).

float center_x = width/2; //or whatever
float center_y = height/2;
float blur = 0.002; //blur radius per pixels from center. 2px blur at 1000px from center
int iterations = 5;

Mat growMapx, growMapy;
Mat shrinkMapx, shrinkMapy;
for(int x = 0; x < width; x++) {
  for(int y = 0; y < height; y++) {
    growMapx[x,y] = x+((x - center_x)*blur);
    growMapy[x,y] = y+((y - center_y)*blur);
    shrinkMapx[x,y] = x-((x - center_x)*blur);
    shrinkMapy[x,y] = y-((y - center_y)*blur);
  }
}

Mat tmp1, tmp2;
for(int i = 0; i < iterations; i++)  {
  remap(src, tmp1, growMapx, growMapy, CV_INTER_LINEAR); // enlarge
  remap(src, tmp2, shrinkMapx, shrinkMapy, CV_INTER_LINEAR); // shrink
  addWeighted(tmp1, 0.5, tmp2, 0.5, 0, src); // blend back to src
}

这篇关于使用OpenCV实现径向模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆