Mercurial > hg > octave-image
changeset 212:58c96786e2fe
interface changed to match cc implementation. (returns magnitude by default)
author | cocus |
---|---|
date | Fri, 08 Dec 2006 06:41:30 +0000 |
parents | 805aa2984c3d |
children | 859991fe7b35 |
files | inst/deriche.m |
diffstat | 1 files changed, 21 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/inst/deriche.m +++ b/inst/deriche.m @@ -1,8 +1,10 @@ # $Id$ -function [V, H] = deriche(img, alpha) -# OUTPUT -# V -> vertical gradient -# H -> horizontal gradient +function result = deriche(img, alpha, method) +# OUTPUT +# method 0 (default) +# magnitude of gradient +# method = 1 +# vector gradient (last index 1 for H, 2 for V) # # INPUT # img -> input image (as matrix of doubles) @@ -33,6 +35,9 @@ # version: 0.1 # ## $Log$ +## Revision 1.2 2006/12/08 06:41:30 cocus +## interface changed to match cc implementation. (returns magnitude by default) +## ## Revision 1.1 2006/12/03 10:53:14 cocus ## initial m-file implementetaion. ## @@ -55,6 +60,10 @@ alpha = 1.0 end +if nargin < 3 + method = 0 +end + a = -(1-exp(-alpha))^2; b1 = -2*exp(-alpha); b2 = exp(-2*alpha); @@ -71,9 +80,8 @@ g_h1 = zeros(n,m); g_h2 = zeros(n,m); g_hv = zeros(n,m); - H = zeros(n,m); - V = 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; @@ -91,7 +99,7 @@ g_h1(k,:) = a2 * g_hv(k+1,:) + a3 * g_hv(k+2,:) - b1 * g_h2(k+1,:) - b2 * g_h2(k+2,:); end; -H = g_h1 + g_h2; +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,:); @@ -110,9 +118,10 @@ g_h1(:,k) = a2 * g_hv(:,k+1) + a3 * g_hv(:,k+2) - b1 * g_h2(:,k+1) - b2 * g_h2(:,k+2); end; -V = g_h1 + g_h2; +result(:,:,2) = g_h1 + g_h2; + +if (method == 0) + result = sqrt(result(:,:,1).*result(:,:,1)+result(:,:,2).*result(:,:,2)); +end - - -