前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >快速双边滤波源码「建议收藏」

快速双边滤波源码「建议收藏」

作者头像
全栈程序员站长
发布2022-08-01 08:02:48
4290
发布2022-08-01 08:02:48
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

快速双边滤波源码「建议收藏」
快速双边滤波源码「建议收藏」

% Fast Bilateral Filter Using Raised Cosines

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % inImg : grayscale image % sigma1 : width of spatial Gaussian % sigma2 : width of range Gaussian % [-w, w]^2 : domain of spatial Gaussian % tol : truncation error % % Author: Kunal N. Chaudhury. % Date: March 1, 2012. % Modified: June 21, 2014. % % References: % [1] K.N. Chaudhury, D. Sage, and M. Unser, “Fast O(1) bilateral % filtering using trigonometric range kernels,” IEEE Trans. Image Proc., % vol. 20, no. 11, 2011. % % [2] K.N. Chaudhury, “Acceleration of the shiftable O(1) algorithm for % bilateral filtering and non-local means,” IEEE Transactions on Image Proc., % vol. 22, no. 4, 2013. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% load test image clc, clear all, close all force; Img = double( imread(‘./images/ckb.jpg’) ); [m, n] = size(Img);

% create noisy image (additive Gaussian noise) sigma = 20; inImg = Img + sigma * randn(m, n);

% filter parameters sigma1 = 4; sigma2 = 30; tol = 0.01;

% Set window for spatial Gaussian w = 6*sigma1; if (mod(w,2) == 0) w = w+1; end

% call bilateral filter tic; [outImg, param] = shiftableBF(inImg, sigma1, sigma2, w, tol); toc;

% plot results T = param.T; N = param.N; M = param.M; gamma = 1 / (sqrt(N) * sigma2); twoN = 2^N;

warning(‘off’); %#ok<WNOFF>

s = linspace(-T, T, 200); g = exp( -s.^2 / (2 * sigma2 *sigma2) ); gApprox = cos(gamma * s).^N; if M == 0 gTrunc = gApprox; else gTrunc = zeros( 1, length(s) ); for k = M : N – M gTrunc = gTrunc + (nchoosek(N, k) / twoN) * … cos( (2*k – N) * gamma * s ); end end

figure(‘Units’,’normalized’,’Position’,[0 0.5 1 0.5]); plot(s, g, ‘b’); hold on, plot(s, gApprox, ‘m’), hold on, plot(s, gTrunc, ‘r’); axis(‘tight’), grid(‘on’), legend(‘Gassian’,’Raised cosine’,’Truncated raised cosine’,’FontSize’, 10); title(‘Comparison of the range kernels’, ‘FontSize’, 10),

peak = 255; PSNR0 = 10 * log10(m * n * peak^2 / sum(sum( (inImg – Img).^2)) ); PSNR1 = 10 * log10(m * n * peak^2 / sum(sum((outImg – Img).^2)) );

figure(‘Units’,’normalized’,’Position’,[0 0.5 1 0.5]); colormap gray, subplot(1,3,1), imshow(uint8(Img)), title(‘Original’, ‘FontSize’, 10), axis(‘image’, ‘off’); subplot(1,3,2), imshow(uint8(inImg)), title([ ‘Noisy, ‘, num2str(PSNR0, ‘%.2f’), ‘dB’] , ‘FontSize’, 10), axis(‘image’, ‘off’); subplot(1,3,3), imshow(uint8(outImg)), title([ ‘Filtered, ‘, num2str(PSNR1, ‘%.2f’), ‘dB’] , ‘FontSize’, 10), axis(‘image’, ‘off’);

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127397.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年4月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档