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

%FastBilateralFilterUsingRaisedCosines%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%inImg:grayscaleimage%sigma1:widthofspatialGaussian%sigma2:widthofrangeGaussian%[-w,w]^…

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

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

% 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.net/127397.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 什么是redis

    什么是redis

    2021年10月18日
    52
  • linux复制多个文件到另一个文件命令_怎么替换安装目录下的文件

    linux复制多个文件到另一个文件命令_怎么替换安装目录下的文件使用参数-R

    2022年8月23日
    11
  • Linux 多学习过程

    Linux 多学习过程

    2022年1月5日
    52
  • 群环域,理想商环,原根复习

    群环域,理想商环,原根复习包含了抽象代数里面的一些概念,最近看文章的时候一直反映不过来,理想是个啥来着,环和域的区别是啥来着。所以统筹整理一下。集合/(Set):一个集合GGG表示一组数据有限集合:G={a1,a2,…,an},∣G∣=nG=\{a_1,a_2,…,a_n\},|G|=nG={a1​,a2​,…,an​},∣G∣=n无穷集合:G={a1,a2,…},∣G∣=∞G=\{a_1,a_2,…\},|G|=\infinG={a1​,a2​,…},∣G∣=∞一个班级的所有学生半群/(Mo

    2022年6月18日
    37
  • jnpf开发文档_java开发最新技术

    jnpf开发文档_java开发最新技术JNPF快速开发平台JNPF快速开发平台采用前后端分离技术、采用B/S架构开发,形成一站式开发多端(APP+PC)使用。使用JNPF开发平台可以简单、快速、高效的构建各种类型java项目。JAVA版介绍JNPF.java版采用前后端分离,可将代码直接导入idea运行,也可将前后端代码利用ngnix分开部署。JNPF主体架构、技术采用前后端分离技术,主体架构为B/S,PC端和APP混合开发。前后端分离特点JNPF快速开发平台平台采用全新的前后端分离架构模式。前…

    2022年8月23日
    27
  • py2exe怎么安装_py安装及开发环境设置

    py2exe怎么安装_py安装及开发环境设置一、简介py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows系统上运行这个可执行程序。py2exe已经被用于创建wxPython,Tkinter,Pmw,PyGTK,pygame,win32comclient和server,和其它的独立程序。py2exe是发布在开源许可证下的。目前只有py…

    2025年10月25日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号