Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 使用OpenCV实现径向模糊_Image Processing_Opencv - Fatal编程技术网

Image processing 使用OpenCV实现径向模糊

Image processing 使用OpenCV实现径向模糊,image-processing,opencv,Image Processing,Opencv,我们想校正数码相机中镜头引入的场曲率。我们计划使用一个模糊,而不是应用高斯模糊,我们想尝试径向模糊,所以锐化对图像边缘的影响更大 使用OpenCV创建径向模糊的最简单方法是什么?我对类似于Photoshop径向运动模糊的东西感兴趣。如果这也是您正在寻找的,我认为最好的解决方案可能是迭代调整大小和混合(addWeighted)。也可以通过remap完成。伪代码,或多或少: float center_x = width/2; //or whatever float center_y = height

我们想校正数码相机中镜头引入的场曲率。我们计划使用一个模糊,而不是应用高斯模糊,我们想尝试径向模糊,所以锐化对图像边缘的影响更大


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

我对类似于Photoshop径向运动模糊的东西感兴趣。如果这也是您正在寻找的,我认为最好的解决方案可能是迭代调整大小和混合(
addWeighted
)。也可以通过
remap
完成。伪代码,或多或少:

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

Mat mapx, mapy;
for(int x = 0; x < width; x++) {
   for(int y = 0; y < height; y++) {
       mapx[x,y] = (x - center_x)/blur;
       mapy[x,y] = (y - center_y)/blur;
   }
}

Mat tmp1, tmp2;
for(int i = 0; i < iterations; i++)  {
    remap(src, tmp1, mapx, mapy, CV_INTER_LINEAR); // enlarge
    remap(src, tmp2, -mapx, -mapy, CV_INTER_LINEAR); // shrink
    addWeighted(tmp1, 0.5, tmp2, 0.5, 0, src); // blend back to src
}
float center_x=宽度/2//或者别的什么
浮动中心y=高度/2;
浮动模糊=0.02//从中心到每像素的模糊半径。距中心100像素处的2倍模糊
int迭代次数=5;
Mat-mapx,mapy;
对于(int x=0;x
上面的答案很接近,但缺少一些关键元素,我花了一点时间才弄明白。 我已经更改了贴图,以便它们正确地计算缩放和收缩,并在每个位置从x和y中添加/减去它们(否则,您将只需将图像重新映射到一个小正方形。此外,我还将/blur更改为*blur,否则您的贴图将包含非常大的数字,并且不会正确显示(每个位置的倍数非常大)

float center\u x=width/2;//或其他
浮动中心y=高度/2;
float blur=0.002;//距离中心每像素的模糊半径。距离中心1000px处的2倍模糊
int迭代次数=5;
Mat growmappx,growmappy;
Mat shrinkMapx、shrinkMapy;
对于(int x=0;x
Python代码:

w, h = img.shape[:2]

center_x = w / 2
center_y = h / 2
blur = 0.01
iterations = 5

growMapx = np.tile(np.arange(h) + ((np.arange(h) - center_x)*blur), (w, 1)).astype(np.float32)
shrinkMapx = np.tile(np.arange(h) - ((np.arange(h) - center_x)*blur), (w, 1)).astype(np.float32)
growMapy = np.tile(np.arange(w) + ((np.arange(w) - center_y)*blur), (h, 1)).transpose().astype(np.float32)
shrinkMapy = np.tile(np.arange(w) - ((np.arange(w) - center_y)*blur), (h, 1)).transpose().astype(np.float32)

for i in range(iterations):
    tmp1 = cv2.remap(img, growMapx, growMapy, cv2.INTER_LINEAR)
    tmp2 = cv2.remap(img, shrinkMapx, shrinkMapy, cv2.INTER_LINEAR)
    img = cv2.addWeighted(tmp1, 0.5, tmp2, 0.5, 0)

我正要发布同样的问题
w, h = img.shape[:2]

center_x = w / 2
center_y = h / 2
blur = 0.01
iterations = 5

growMapx = np.tile(np.arange(h) + ((np.arange(h) - center_x)*blur), (w, 1)).astype(np.float32)
shrinkMapx = np.tile(np.arange(h) - ((np.arange(h) - center_x)*blur), (w, 1)).astype(np.float32)
growMapy = np.tile(np.arange(w) + ((np.arange(w) - center_y)*blur), (h, 1)).transpose().astype(np.float32)
shrinkMapy = np.tile(np.arange(w) - ((np.arange(w) - center_y)*blur), (h, 1)).transpose().astype(np.float32)

for i in range(iterations):
    tmp1 = cv2.remap(img, growMapx, growMapy, cv2.INTER_LINEAR)
    tmp2 = cv2.remap(img, shrinkMapx, shrinkMapy, cv2.INTER_LINEAR)
    img = cv2.addWeighted(tmp1, 0.5, tmp2, 0.5, 0)