本文是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. 【Linux常见命令】vi,vim命令

    所有的 Unix Like 系统都会内建 vi 文书编辑器,其他的文书编辑器则不一定会存在. 但是目前我们使用比较多的是 vim 编辑器. vim 具有程序编辑的能力,可以主动的以字体颜色辨别语法的正 ...

  2. 在okhttp的callback回调中加Toast出现Cant create handler inside hread that has not called Looper.prepare()...

    2019独角兽企业重金招聘Python工程师标准>>> 分析:callback中回调的response方法中还是在子线程中运行的,所以要调取Toast必须回到主线程中更新ui 解决方 ...

  3. 图论--网络流--最小割 HDU 2485 Destroying the bus stations(最短路+限流建图)

    Problem Description Gabiluso is one of the greatest spies in his country. Now he's trying to complet ...

  4. 51 NOD 1049 最大子段和 动态规划 模板 板子 DP

    N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的连续子段和的最大值.当所给的整数均为负数时和为0. 例如:-2,11,-4,13,-5,- ...

  5. P3119 [USACO15JAN]Grass Cownoisseur G

    P3119 [USACO15JAN]Grass Cownoisseur G tarjan缩点+分层图上跑 spfa最长路 约翰有 \(n\) 块草场,编号 \(1\) 到 \(n\),这些草场由若干条 ...

  6. predixy源码学习--开篇

    最近开始研究predixy.predixy是一款高性能全功能redis代理 ,网上有的文章大部分都是功能上的介绍,很少有源码相关的分享. predixy的相关介绍在github: https://gi ...

  7. 一个简单的wed服务器SHTTPD(9)————main函数文件,Makefile,头文件

    主函数: #include "lcw_shttpd.h" //初始化时服务器的默认配置 extern struct conf_opts conf_para= { "/us ...

  8. 07 模型层 orm相关查询 F查询Q查询 django开启事务

    一.Django终端打印SQL语句 如果你想知道你对数据库进行操作时,Django内部到底是怎么执行它的sql语句时可以加下面的配置来查看 在Django项目的settings.py文件中,在最后复制 ...

  9. 细说 PEP 468: Preserving Keyword Argument Order

    细说 PEP 468: Preserving Keyword Argument Order Python 3.6.0 版本对字典做了优化,新的字典速度更快,占用内存更少,非常神奇.从网上找了资料来看, ...

  10. andorid jar/库源码解析之zxing

    目录:andorid jar/库源码解析 Zxing: 作用: 生成和识别,二维码,条形码. 栗子: 生成二维码,赋值到ImageView上 QRCodeWriter qrCodeWriter = n ...