# 联合双边滤波器（joint bilateral filter)【OpenCV】

48 篇文章 20 订阅
40 篇文章 17 订阅

JBF的原理图，如图（1）所示。

function B = jbfltGray(D,C,w,sigma_d,sigma_r)
%    D should be a double precision matrix of size NxMx1 (i.e., grayscale)  with normalized values in the
%    closed interval [0,1].
%    C should be similar to D, from which the weights are calculated, with normalized values in the
%   closed interval [0,1].
% Pre-compute Gaussian distance weights.
[X,Y] = meshgrid(-w:w,-w:w);
G = exp(-(X.^2+Y.^2)/(2*sigma_d^2));
% Apply bilateral filter.
dim = size(D);
B = zeros(dim);
for i = 1:dim(1)
for j = 1:dim(2)
% Extract local region.
iMin = max(i-w,1);
iMax = min(i+w,dim(1));
jMin = max(j-w,1);
jMax = min(j+w,dim(2));
I = D(iMin:iMax,jMin:jMax);
% To compute weights from the color image
J = C(iMin:iMax,jMin:jMax);
% Compute Gaussian intensity weights according to the color image
H = exp(-(J-C(i,j)).^2/(2*sigma_r^2));
% Calculate bilateral filter response.
F = H.*G((iMin:iMax)-i+w+1,(jMin:jMax)-j+w+1);
B(i,j) = sum(F(:).*I(:))/sum(F(:));
end
end

----------------------------------------------以上原理转载自： pplong的博客----------------------------------------------

OpenCV 3.x.x的扩展模块（ximgproc. Extended Image Processing） 也添加了JBF的 API  ：

OpenCV的代码：

#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <ximgproc.hpp>

int main()
{
cv::Mat src = cv::imread("data/dp.png", 1); // 原始带噪声的深度图

cv::Mat dst;
int64 begin = cvGetTickCount();
cv::ximgproc::jointBilateralFilter(joint, src, dst, -1, 3, 9);
int64 end = cvGetTickCount();

float time = (end - begin) / (cvGetTickFrequency() * 1000.);
printf("time = %fms\n", time);

imshow("src", src);
imshow("joint", joint);
imshow("jointBilateralFilter", dst);
cv::waitKey(0);

return 0;
}

• 6
点赞
• 78
收藏
觉得还不错? 一键收藏
• 打赏
• 10
评论
07-23 1069
05-30 15万+
12-17 5753
07-08 1621
01-14 6万+
07-26
02-22
07-09 2万+
01-18 3009

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。