本文是Image Smoothing via L0 Gradient Minimization一文的笔记。L0 Gradient Smoothing的formulation与TV和WLS等基于变分的模型很相似,所以本文重在推导。读者需注意,本文采用的符号标记与原论文不同,笔者觉得本文采用的符号标记表达力更强些,且不容易产生歧义。本文重写了原论文中的问题描述,推导了原论文中的公式(8),笔者还推导了一个新的向量形式的Solver,并编码验证了该Solver的正确性(遗憾的是,效率不及原作者用FFT实现的代码)。

更新记录

本文持续更新!如文中有错误,或你对本文有疑问或建议,欢迎留言或发邮件至quarrying#qq.com!

2016年01月12日,发布博文。

2016年01月13日,修改代码二,效果与代码一一致。感谢网友guide(QQ昵称)指出错误。

参考

[1] L. Xu, C. Lu, Y. Xu, and J. Jia, “Image smoothing via L0 gradient minimization,” Proc. 2011 SIGGRAPH Asia Conf. - SA ’11, vol. 30, no. 6, p. 1, 2011.

相关代码

代码一,这是原作者采用FFT实现的L0 Gradient Smoothing

%   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-commercial use only. function S = L0Smoothing(Im, lambda, kappa)
%L0Smooth - Image Smoothing via L0 Gradient Minimization
% S = L0Smoothing(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 iterations and with sharper edges.
% We select kappa in (1, 2].
% kappa = 2 is suggested for natural images.
%
% Example
% ==========
% Im = imread('pflower.jpg');
% S = L0Smoothing(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)<lambda/beta;
else
t = sum((h.^2+v.^2),3)<lambda/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

代码一的效果图

代码二,本代码对应于向量化显式求解,是实验代码,只能处理单通道,效率不及代码一,仅为示例。

% Author: Kang Kai( Nickname: quarryman)
% Update: 2016-01-13
% References:
% [1] "Image Smoothing via L0 Gradient Minimization", Li Xu,
% Cewu Lu, Yi Xu, Jiaya Jia, ACM Transactions on Graphics,
% (SIGGRAPH Asia 2011), 2011.
%
% This code is only for non-commercial use . function U = kcvL0Smooth(U0, lambda, kappa)
% kcvL0Smooth - Image Smoothing via L0 Gradient Minimization
% U = kcvL0Smooth(U0, lambda, kappa) performs L0 gradient smoothing of input
% image U0, with smoothness weight lambda and rate kappa.
%
% Paras:
% @U0 : Input UINT8 image, only accept grayscale images.
% @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 iterations and with sharper edges.
% We select kappa in (1, 2].
% kappa = 2 is suggested for natural images.
%
% Example
% ==========
% U0 = imread('pflower.jpg');
% U = kcvL0Smooth(U0);
% figure, imshow(U0), figure, imshow(U); if ~exist('U0','var')
U0 = imread('lena.jpg');
U0 = rgb2gray(U0);
end
if ~exist('lambda','var')
lambda = 0.005;
end
if ~exist('kappa','var')
kappa = 2.0;
end betaMax = 1e5;
beta = 2 * lambda; U = im2double(U0); while beta < betaMax
% v subproblem
Vx = padarray(diff(U, 1, 2), [0 1], 'post');
Vy = padarray(diff(U, 1, 1), [1 0], 'post');
t = (Vx.^2 + Vy.^2) < lambda / beta;
Vx(t) = 0; Vy(t) = 0;
% U subproblem
U = updateU(U, Vx, Vy, beta);
beta = beta * kappa;
imshow(U); pause(1)
fprintf('.');
end end function U = updateU(U0, Vx, Vy, beta)
[m, n] = size(U0); k = m * n; dVx = padarray(-diff(Vx, 1, 2), [0 1], 'pre');
dVy = padarray(-diff(Vy, 1, 1), [1 0], 'pre');
B = U0 + beta * (dVx + dVy); b = B(:); dx = [ones(m, n - 1), zeros(m, 1)];
dy = [ones(m - 1, n); zeros(1, n)];
dx = beta * dx(:); dy = beta * dy(:);
T1 = spdiags([dx, dy], [-m, -1], k, k); W = padarray(dx, m, 'pre'); W = W(1 : end - m);
N = padarray(dy, 1, 'pre'); N = N(1 : end - 1);
% T2 = 1 + (dx + dy + W + N);
T2 = 1 + (2 * beta + W + N);
A = spdiags(T2, 0, k, k) - T1 - T1';
% deprecated, out of memory
% Sm = diag(ones(m - 1, 1), 1) - eye(m);
% Sn = diag(ones(n - 1, 1), 1) - eye(n);
% A = eye(m * n) + beta * (kron(Sn'*Sn, eye(m)) + ...
% kron(eye(n), Sm'*Sm));
U = reshape(A \ b, m, n);
end

代码二的效果图:

正文

图像分析之梯度L0范数平滑的更多相关文章

  1. 带阈值的平滑l0范数加速稀疏恢复——同名英文论文翻译

    原文链接:Thresholded Smoothed l0 Norm for Accelerated Sparse Recovery http://ieeexplore.ieee.org/documen ...

  2. paper 126:[转载] 机器学习中的范数规则化之(一)L0、L1与L2范数

    机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http://blog.csdn.net/zouxy09 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化. ...

  3. 机器学习中的范数规则化之(一)L0、L1与L2范数(转)

    http://blog.csdn.net/zouxy09/article/details/24971995 机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http: ...

  4. L0、L1与L2范数、核范数(转)

    L0.L1与L2范数.核范数 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化.我们先简单的来理解下常用的L0.L1.L2和核范数规则化.最后聊下规则化项参数的选择问题.这里因为篇幅比较庞大 ...

  5. 机器学习中的范数规则化之(一)L0、L1与L2范数 非常好,必看

    机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http://blog.csdn.net/zouxy09 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化. ...

  6. 笔记︱范数正则化L0、L1、L2-岭回归&Lasso回归(稀疏与特征工程)

    机器学习中的范数规则化之(一)L0.L1与L2范数 博客的学习笔记,对一些要点进行摘录.规则化也有其他名称,比如统计学术中比较多的叫做增加惩罚项:还有现在比较多的正则化. -------------- ...

  7. 机器学习中的范数规则化-L0,L1和L2范式(转载)

    机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http://blog.csdn.net/zouxy09 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化. ...

  8. 机器学习中的规则化范数(L0, L1, L2, 核范数)

    目录: 一.L0,L1范数 二.L2范数 三.核范数 今天我们聊聊机器学习中出现的非常频繁的问题:过拟合与规则化.我们先简单的来理解下常用的L0.L1.L2和核范数规则化.最后聊下规则化项参数的选择问 ...

  9. 机器学习中的范数规则化 L0、L1与L2范数 核范数与规则项参数选择

    http://blog.csdn.net/zouxy09/article/details/24971995 机器学习中的范数规则化之(一)L0.L1与L2范数 zouxy09@qq.com http: ...

随机推荐

  1. nginx平滑升级、在线添加模块(tengine 动态加载模块)

    http://www.orzace.com/how-to-upgrade-nginx/ 下面是nginx替换成tengine再加上lua 模块,(tengine-2.0.1版本暂时无法动态加载lua模 ...

  2. 两种方法直接删除数组中特定值的项(JavaScript)

    一.问题详情: 直接删除意为原数组需要被改变,而不是得到另一个数组. 二.JavaScript实现 (一)巧用数组的push( ).shift( )方法 function del(arr,num) { ...

  3. 数学--数论--HDU 2197 本原串 (推规律)

    由0和1组成的串中,不能表示为由几个相同的较小的串连接成的串,称为本原串,有多少个长为n(n<=100000000)的本原串? 答案mod2008. 例如,100100不是本原串,因为他是由两个 ...

  4. django+nginx+uwsgi的生产环境部署(Ubuntu16.04)

    一,准备工作: 代码一定要能本地跑起来! 各种基础包的安装略默认已经安装python3,nginx,uwsgi等基础依赖,注意版本问题. 本地setting.py文件修改如下(改为生产模式,把debu ...

  5. JavaWeb开发规范

    以下的建议将帮助你更有效地使用本文所描述的 Java 编程标准: ******************************************************* 当你写代码时就应该遵守 ...

  6. JVM之类加载器、加载过程及双亲委派机制

    JVM 的生命周期 虚拟机的启动 Java 虚拟机的启动是通过引导类加载器(bootstrap class loader)创建一个初始类(initial class)来完成的,这个类是由虚拟机的具体实 ...

  7. OKR新手入门指南 (第一部分)

    什么是OKR? OKR(目标和关键结果)是Google和其他公司使用的目标系统.这是一个简单的工具,围绕可衡量的目标进行调整和互动. OKR:Google的目标设定方法 与传统的规划方法有何不同? O ...

  8. P2422 良好的感觉(两头单调)

    描述:https://www.luogu.com.cn/problem/P2422 kkk做了一个人体感觉分析器.每一天,人都有一个感受值Ai,Ai越大,表示人感觉越舒适.在一段时间[i, j]内,人 ...

  9. IDEA编写快捷生成代码

    转载于:https://www.jianshu.com/p/029c2de5c612 1. psvm //生成main方法: public static void main(String[] args ...

  10. 实用,小物体检测的有监督特征级超分辨方法 | ICCV 2019

    论文提出新的特征级超分辨方法用于提升检测网络的小物体检测性能,该方法适用于带ROI池化的目标检测算法.在VOC和COCO上的小物体检测最大有5~6%mAP提升,在Tsinghua-Tencent 10 ...