图像平滑是计算摄影学一门基础重要的工具,其作用是拂去不重要的细节,保留较大的图像边缘,主要应用于边缘检测,JPEG压缩图像人工伪迹去除,非真实绘制等领域。
L0范数可以理解为向量中非零元素的个数。
图像梯度L0范数可以如下表示
先以一维信号为例,输入信号 g ,输出信号 f ,那么我们的目标函数可以如下表示:
二维图像中,我们需要约束图像水平和垂直方向的梯度数目,形式上如下
迭代优化
% Distribution code Version 1.0 -- 09/23/2011 by Jiaya Jia Copyright 2011, The Chinese University of Hong Kong.
%
% The Code is created based on the method described in the following paper
% [1] "Image Smoothing via L0 Gradient Minimization", Li Xu, Cewu Lu, Yi Xu, Jiaya Jia, ACM Transactions on Graphics,
% (SIGGRAPH Asia 2011), 2011.
%
% The code and the algorithm are for non-comercial use only.
function S = L0Smoothing(Im, lambda, kappa)
%L0Smooth - Image Smoothing via L0 Gradient Minimization
% S = L0Smooth(Im, lambda, kappa) performs L0 graidient smoothing of input
% image Im, with smoothness weight lambda and rate kappa.
%
% Paras:
% @Im : Input UINT8 image, both grayscale and color images are acceptable.
% @lambda: Smoothing parameter controlling the degree of smooth. (See [1])
% Typically it is within the range [1e-3, 1e-1], 2e-2 by default.
% @kappa : Parameter that controls the rate. (See [1])
% Small kappa results in more iteratioins and with sharper edges.
% We select kappa in (1, 2].
% kappa = 2 is suggested for natural images.
%
% Example
% ==========
% Im = imread('pflower.jpg');
% S = L0Smooth(Im); % Default Parameters (lambda = 2e-2, kappa = 2)
% figure, imshow(Im), figure, imshow(S);
if ~exist('kappa','var')
kappa = 2.0;
end
if ~exist('lambda','var')
lambda = 2e-2;
end
S = im2double(Im);
betamax = 1e5;
fx = [1, -1];
fy = [1; -1];
[N,M,D] = size(Im);
sizeI2D = [N,M];
otfFx = psf2otf(fx,sizeI2D);
otfFy = psf2otf(fy,sizeI2D);
Normin1 = fft2(S);
Denormin2 = abs(otfFx).^2 + abs(otfFy ).^2;
if D>1
Denormin2 = repmat(Denormin2,[1,1,D]);
end
beta = 2*lambda;
while beta < betamax
Denormin = 1 + beta*Denormin2;
% h-v subproblem
h = [diff(S,1,2), S(:,1,:) - S(:,end,:)];
v = [diff(S,1,1); S(1,:,:) - S(end,:,:)];
if D==1
t = (h.^2+v.^2)beta;
else
t = sum((h.^2+v.^2),3)beta;
t = repmat(t,[1,1,D]);
end
h(t)=0; v(t)=0;
% S subproblem
Normin2 = [h(:,end,:) - h(:, 1,:), -diff(h,1,2)];
Normin2 = Normin2 + [v(end,:,:) - v(1, :,:); -diff(v,1,1)];
FS = (Normin1 + beta*fft2(Normin2))./Denormin;
S = real(ifft2(FS));
beta = beta*kappa;
fprintf('.');
end
fprintf('\n');
end
代码也是非常清晰,容易理解的。关于其更多应用,可以查看原文。但是该方法基于迭代优化,迭代次数与kappa对数下降关系, kappa=0.02 迭代22次。
Image Smoothing via L0 Gradient Minimization
Image Smoothing via L0 Gradient Minimization PPT
作者 | 日期 | 联系方式 |
---|---|---|
风吹夏天 | 2015年9月26日 | [email protected] |