Finding edges 是 image processing 成熟的理论
MATLAB自带edge函数
% MATLAB自带的edge函数
pic = imread('pic.jpg');
tmp = size(pic);
N = tmp(1); M = tmp(2);
pic_ = rgb2gray(pic);
pic2 = edge(pic_,'canny');
for x = 1:N
for y = 1:M
if pic2(x,y) == true
pic2(x,y) = false;
elseif pic2(x,y) == false
pic2(x,y) = true;
end
end
end
imwrite(pic2,'pic_canny.jpg');
Canny方法提取edges的噪声过高,于是我们想是否可以ROF模型分离噪声之后再使用Canny方法。
ROF方法其实是变分法转化为偏微分方程数值解。
% ROF.m
% Decomposing images into geometry and texture using ROF models
% 方法是数值解Euler-Lagrange equations
function [u,v] = ROF(pic)
% 论文中参数lambda取0.1
lambda = 0.1;
tmp = size(pic);
N = tmp(1); M = tmp(2);
f = rgb2gray(pic);
u = double(f);
v = uint8(zeros(N,M));
% u的梯度
Dx_u = zeros(N,M);
Dy_u = zeros(N,M);
Dx_u_ = zeros(N,M);
Dy_u_ = zeros(N,M);
% 定义偏微分方程迭代次数
n_loop = 300;
for n = 1:n_loop
% 首先求解 u 的梯度 (Dx_u, Dy_u)
for x = 2:N
for y = 2:M
Dx_u(x,y) = u(x,y) - u(x-1,y);
Dy_u(x,y) = u(x,y) - u(x,y-1);
end
end
% Dx_u_ = Dx_u / module(Du)
for x = 2:N
for y = 2:M
Dx_u_(x,y) = Dx_u(x,y) / ((Dx_u(x,y)^2+Dy_u(x,y)^2)^0.5+0.01);
Dy_u_(x,y) = Dy_u(x,y) / ((Dx_u(x,y)^2+Dy_u(x,y)^2)^0.5+0.01);
end
end
% Euler-Lagrange Equations
for x = 2:N
for y = 2:M
div = Dx_u_(x,y) - Dx_u_(x-1,y) + Dy_u_(x,y) - Dy_u_(x,y-1);
u(x,y) = f(x,y) + 0.5 / lambda * div;
end
end
end
u = uint8(u);
%imwrite(u,'pic_ROF_u.jpg');
for x = 1:N
for y = 1:M
v(x,y) = 127 + uint8(f(x,y)-u(x,y));
if v(x,y) > 255
v(x,y) = 255;
elseif v(x,y) < 0
v(x,y) = 0;
end
end
end
%imwrite(v,'pic_ROF_v.jpg');
end
这是提取出的texture
注意到提取texture之后再提取edges效果微好一点点,但仍然不理想
论文Modeling Textures with Total Variation Minimization and
Oscillating Patterns in Image Processing BY Vese and Osher 较ROF更好的提取纹理的方法
或许效果能更好