Hi,

I am trying to compare the results between convolving an image *once*

with a 2D derivative of a Gaussian *matrix* and between convolving

*twice* once in the X direction and once in the Y direction with a

1D derivative of a Gaussian *vector* (using the seperability property

of the derivative of a Gaussian).

I wrote two functions, one for generating the vector and one for

generating the matrix and then used those with the imfilter function

(see below) . The problem is that the convolution results are

different(!) and I am trying to find the fault in the logic and

hopefully someone can help.

% derivative of a Gaussian *vector*

function [der_gauss_vector]=dog_vector(r,d)

r2=2*(r^2);

s=0;

midpoint=floor(d/2);

for n = -midpoint:midpoint

der_gauss_vector(n +midpoint +1 )=-n*exp( -(n^2)/(r2))/(r^2);

s=s+der_gauss_vector(n +midpoint+1);

end

% derivative of a Gaussian *matrix*

function [gauss_der_matrix]=dog_kernel(r,d)

r2=2*(r^2);

s=0;

gauss_matrix=ones(d,d);

gauss_der_matrix=ones(d,d);

midpoint=floor(d/2);

for n = -midpoint:midpoint

for k = -midpoint:midpoint

gauss_matrix(n +midpoint +1 ,k +midpoint +1)=exp( -(k^2 +

n^2)/(r2));

gauss_der_matrix(n +midpoint +1 ,k +midpoint

+1)=-k*gauss_matrix(n +midpoint +1 ,k +midpoint +1);

end

end

gauss_der_matrix=gauss_der_matrix/(r^2);

and here is the code that calls the functions:

clc

clear all

close all

r=1; % sigma

d=3; % kernel size

gauss_der_vector=dog_vector(r,d); % 1D

gauss_der_matrix=dog_kernel(r,d); % 2D

I=ones(7,7); % test image

img111 = conv2(gauss_der_matrix,I) % 2D case

%1D case

img222 = conv2(gauss_der_vector,I)

img222 = conv2(gauss_der_vector',img222)

%img333 = conv2(gauss_der_vector,gauss_der_vector', I)

Thank you very much,

Shlomo Kashani.