% 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)<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
没有合适的资源?快使用搜索试试~ 我知道了~
基于L0约束实现图像平滑处理附matlab代码
共4个文件
m:2个
jpg:1个
png:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 14 浏览量
2022-06-29
01:06:41
上传
评论 1
收藏 600KB ZIP 举报
温馨提示
1.版本:matlab2019a,不会运行可私信 2.领域:【图像平滑】 3.内容: 基于L0约束实现图像平滑处理附matlab代码 4.适合人群:本科,硕士等教研学习使用
资源推荐
资源详情
资源评论
收起资源包目录
【图像平滑】基于L0约束实现图像平滑处理附matlab代码 上传版本.zip (4个子文件)
1.png 568KB
L0Smoothing.m 2KB
pflower.jpg 35KB
testL0Smoothing.m 171B
共 4 条
- 1
资源评论
- Toslow2023-05-29感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
- mifun2023-01-21资源简直太好了,完美解决了当下遇到的难题,这样的资源很难不支持~
天天Matlab科研工作室
- 粉丝: 2w+
- 资源: 7251
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功