1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
function result = deriche(img, alpha, method)
if nargin < 2
alpha = 1.0
end
if nargin < 3
method = 0
end
a = -(1-exp(-alpha))^2;
b1 = -2*exp(-alpha);
b2 = exp(-2*alpha);
a0 = -alpha / (1 - alpha * b1 - b2);
a1 = a0 * (alpha-1)*exp(-alpha);
a2 = a1 - a0 * b1;
a3 = -a0 * b2;
[m,n] = size(img);
g_v1 = zeros(n,m);
g_v2 = zeros(n,m);
g_h1 = zeros(n,m);
g_h2 = zeros(n,m);
g_hv = zeros(n,m);
result = zeros(n,m,2);
for k=3:m
g_v1(:,k) = img(:, k-1) - b1 * g_v1(:,k-1)- b2 * g_v1(:,k-2);
end;
for k=m-2:-1:1
g_v2(:,k) = img(:, k+1) - b1 * g_v2(:,k+1)- b2 * g_v2(:,k+2);
end;
g_hv = a * (g_v1 - g_v2);
for k=3:n
g_h1(k,:) = a0 * g_hv(k,:) + a1 * g_hv(k-1,:) - b1 * g_h1(k-1,:) - b2 * g_h1(k-2,:);
end;
for k=n-2:-1:1
g_h1(k,:) = a2 * g_hv(k+1,:) + a3 * g_hv(k+2,:) - b1 * g_h2(k+1,:) - b2 * g_h2(k+2,:);
end;
result(:,:,1) = g_h1 + g_h2;
for k=3:n
g_v1(k,:) = img(k-1,:) - b1 * g_v1(k-1,:)- b2 * g_v1(k-2,:);
end;
for k=n-2:-1:1
g_v2(k,:) = img(k+1,:) - b1 * g_v2(k+1,:)- b2 * g_v2(k+2,:);
end;
g_hv = a * (g_v1 - g_v2);
for k=3:m
g_h1(:,k) = a0 * g_hv(:,k) + a1 * g_hv(:,k-1) - b1 * g_h1(:,k-1) - b2 * g_h1(:,k-2);
end;
for k=m-2:-1:1
g_h1(:,k) = a2 * g_hv(:,k+1) + a3 * g_hv(:,k+2) - b1 * g_h2(:,k+1) - b2 * g_h2(:,k+2);
end;
result(:,:,2) = g_h1 + g_h2;
if (method == 0)
result = sqrt(result(:,:,1).*result(:,:,1)+result(:,:,2).*result(:,:,2));
end |
Partager