I read a paper that said about correlation kernel that defined: $$W(x-y)=(α/1+d(|y − x|))$$ where $α = (\int(1+d(y − x)dy)^{-1}$, $(d(|y − x|))$ is spatial Euclidean distance from the central pixel. My question is what is correlation kernel and benifit of that kernel comparison with gaussian kernel? Thank you so much.
-
2$\begingroup$ Can you link to the paper? Correlation is a mathematical operation similar to convolution. $\endgroup$– geometrikalJul 11, 2014 at 5:24
-
$\begingroup$ Right.But the reference paper mentioned that it is better than gaussian kernel $\endgroup$– JohnJul 11, 2014 at 11:47
1 Answer
Referencing the paper, the convolution kernel can be written as:
$d(|y-x|)$ is the Euclidean distance between the centre pixel $y$ and a location in the kernel $x$. $\alpha$ is used to ensure that the entire area under the kernel is 1. However, you did not specify how big this kernel is. As such, we will specify the rows and columns of this kernel to be M
and N
respectively. Let's also assume that the size of the kernel for each dimension is odd. The reason why is because the shape of the kernel will be an even square and makes implementation easier. As such, here are the steps that I would perform to do this:
- Define a grid of
X
andY
co-ordinates, and ensure that the centre pixel is at 0. - Compute each term in the convolution kernel without the $\alpha$ term.
- Sum up all of the terms in the kernel, then divide every value in this kernel by this term so that the entire area of the kernel is 1.
Let's do this step by step:
Step #1
We can do this by using meshgrid
. meshgrid
(in this case) creates a 2D grid of (X,Y)
co-ordinates. X
defines the horizontal co-ordinate for each location in X
, while Y
defines this vertically. By calling meshgrid(1:m, 1:n)
, I am creating a n x m
grid for both X
and Y
, where each row of X
progresses from 1 to m
, while each column of Y
progresses from 1 to n
. Therefore, these will both be n x m
matrices. Calling the above with m = 4
and n = 4
computes:
m = 4;
n = 4;
[X,Y] = meshgrid(1:m, 1:n)
X =
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Y =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
As such, we simply have to modify this, but we ensure that the middle is at (0,0)
, and also ensure that the size of X
and Y
are odd. Let's say that M = 5
and N = 5
. We can then define our X
and Y
co-ordinates like so:
M = 5;
N = 5;
[X,Y] = meshgrid(-floor(N/2):floor(N/2), -floor(M/2):floor(M/2))
X =
-2 -1 0 1 2
-2 -1 0 1 2
-2 -1 0 1 2
-2 -1 0 1 2
-2 -1 0 1 2
Y =
-2 -2 -2 -2 -2
-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
2 2 2 2 2
As you can see here, the centre pixel for both X
and Y
are defined as (0,0)
. Everywhere else has its (X,Y)
co-ordinates defined with respect to the centre.
Step #2
We simply have to compute the Euclidean distance between the centre pixel to every point in the kernel. This can be done by:
dis = sqrt(X.^2 + Y.^2)
dis =
2.8284 2.2361 2.0000 2.2361 2.8284
2.2361 1.4142 1.0000 1.4142 2.2361
2.0000 1.0000 0 1.0000 2.0000
2.2361 1.4142 1.0000 1.4142 2.2361
2.8284 2.2361 2.0000 2.2361 2.8284
Doing some quick calculation checks, you can see that this agrees with our understanding of Euclidean distance. Moving to the left by 1 from the centre is a distance of 1. Moving to the left by 1 then up by 1 gives us a Euclidean distance of $\sqrt{1^2 + 1^2} = \sqrt{2} = 1.4142$. Doing similar checks with each element will demonstrate that this is indeed a Euclidean distance field from the centre pixel. After we do this, let's compute the kernel terms without the $\alpha$ term.
kern = 1 ./ (1 + dis)
kern =
0.2612 0.3090 0.3333 0.3090 0.2612
0.3090 0.4142 0.5000 0.4142 0.3090
0.3333 0.5000 1.0000 0.5000 0.3333
0.3090 0.4142 0.5000 0.4142 0.3090
0.2612 0.3090 0.3333 0.3090 0.2612
Step #3
The last step we need is to normalize the mask so that the total sum of the kernel is 1. This can simply be done by:
kernFinal = kern / sum(kern(:))
kernFinal =
0.0275 0.0325 0.0351 0.0325 0.0275
0.0325 0.0436 0.0526 0.0436 0.0325
0.0351 0.0526 0.1052 0.0526 0.0351
0.0325 0.0436 0.0526 0.0436 0.0325
0.0275 0.0325 0.0351 0.0325 0.0275
This should finally give you the correlation kernel that you are seeking. You can now use this in convolution (i.e. using imfilter
or conv2
).
Hopefully I have answered your question adequately. Good luck!
-
1
-
1$\begingroup$ @geometrikal - Thanks :) I'm actually a Signal Processing guy, but I've mainly spent my time on StackOverflow. Figured it's time I flex some of my DSP knowledge here as this is the stuff I do for a living! $\endgroup$– rayryengJul 12, 2014 at 4:55