| Online Publication | Signal Processing | Research Article | http://werner.yellowcouch.org/Papers/sadvssip/ |
Werner Van Belle1* - werner@yellowcouch.org, werner.van.belle@gmail.com
1- Personal Research; CH-9294 Basel, Switzerland
Abstract: While investigating relations between various comparators and the inproduct we found that the inproduct correlates strongly towards the absolute difference when the domain from which the values are taken come from a uniform distribution on [-1:1]. This useful relation might help to speed up block comparison in content databases and can be used as a valuable tool to estimate the inproduct based on the absolute difference and vice versa
Keywords: sum of absolute differences, sum of inproduct, landmark tracking, feature tracking
Reference: Werner Van Belle; Correlation between the inproduct and the sum of absolute differences is -0.8485 for uniform sampled signals on [-1:1]; Signal Processing; Yellowcouch Scientific; November 2006
To compare two data-blocks (of size
), two easy implementable
techniques are widely used. The first is the summed inproduct (SIP),
defined as
. The second one, termed the
sum of absolute differences (SAD), is defined as
.
Depending on the application behind the comparison one might be favored
over the other.
The absolute difference is a well known operator for block comparison within images and is one of the basic blocks used in MPEG coding [1]. It is often used for motion estimation by means of landmark detection [2,3,4,5] and many different hardware implementations of the absolute difference exist [6,7,8,9]. In general statistics, the absolute difference is also often used as a robust measure [10], with specialized application such as model evaluation of protein 3D structures [11].
In audio
applications, the absolute difference could also be used,
but for historical reasons, the standard inproduct seems to be favored,
mainly because multiplication is a basic operation in digital filters
[12]. The
inproduct, and specifically convolution,
has an interesting application in fuzzy pattern matching. There it
is often used to find sub-patterns in a haystack of information.
Convolution
will then assess the correlation between every position and the
pattern-to-be-found
[13,14,15]. Since convolution itself
can be efficiently implemented through a Fourier transform (or a
sliding
sliding window Fourier transform when the datasets are large), pattern
matching becomes a faster operation than finding similar fragment
by means of the absolute difference. To go somewhat into the details,
we denote the Fourier transform as
. On a block of size
it takes time complexity
log
[16].
The inproduct of two signals expressed in their frequency domain is
the same as convolution of their information in the time domain [12].
As such, the function
,
in which
denotes the
inproduct and
denotes
conjugation,
will return a vector of which element
describes the correlation
between signal
and signal
shifted
positions. This operation
itself has time complexity
,
which is much faster than the same process using an iteration of
absolute
differences, which would yield a time complexity of
.
As such, the two operations both have their advantages and disadvantages. The absolute difference can be quickly calculated, but it is difficult to optimize for many comparisons. The inproduct on the other hand is slower on individual comparisons, but has very efficient implementations for large volumes.
Aside from these
trade-offs, both metrics behave very different. The
sum of absolute differences will be small for similar blocks, while
the inproduct instead will be large. Some other subtitles arise as
well: the absolute difference is independent of any constant added
to both vectors since
.
The inproduct does not have such a property:
and will
provide different results for any two same values:
when
. In other words the strength of the reported similarity
depends on the strength of the values themselves. Actually, the
inproduct
itself is strictly speaking not a metric since
for
most values of
.
Notwithstanding their completely different mathematical behavior, both are often used in very similar contexts and therefore, we became interested to understand the relation between a number of well known comparators such as the summed inproduct and the sum of absolute differences. This could make it possible to predict one in function of the other.
To study the relations between various comparators we created
data-blocks, each containing two vectors
and
. The
variables
and
, both of size
and element
from
,
were randomly sampled from the same multi-variate distribution. Based
on such test vectors we measured the spearman rank order and linear
pearson correlation.
and
annotate the
elements of
and
, with the variables
and
.
americanFor 8-bit signed integers,
and
ranges within [-127,128], and for 16 bit signed integers the values
come from [-32767,32768]. americanWe do not
take into account the discrete nature of integers and will work with
real numbers taken from
. americanAll
and
values were drawn from the same distribution, which
could be normal or uniform distributed.
All
comparators are set up as a summation of some underlying operator
, which could be one
of the following 6:
| (1) | |
| (2) | |
| (3) | |
| (4) | |
| (5) | |
| (6) |
The first operator
is the absolute difference.
The second operator
is the multiplication. The third
operator
will provide us with insight on the relation
between the absolute difference and the basic difference. The fourth
operator
investigates the impact of signed to
unsigned
conversion in a comparison process and the last operator.
takes the inverse of the signal and puts it back into the equation
as an attempt to balance the inequality that occurs when comparing
identical couples with a different value.
The
multidimensional comparator
, based on
is defined as
We tested the relations between every pair of comparators using
sequences each of
samples. The values for
and
were first drawn from a uniform distribution between
and
and then from a normal distribution. The random generators are ran2
and gasdev from [17].
In all cases, both
the linear Pearson and spearman rank order correlations were similar.
The programs to measure the correlations can be found in section
appendix.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
We now assume that both vectors
and
are uniform distributed
within range
, with
and
.
denotes the size
of the interval (
). The comparators
and
,
both depending on
and
, will now be considered to be variables
themselves. The correlation between them,
,
is given by
![]() |
(7) |
Under the assumption that the various sample positions are independent
from each other, one can easily show that
.
This reduces the 5 estimates we need to
,
,
,
and
. We will now determine those
5 values.
Estimates of a variable
can be calculated from probability functions
as follows (
is the
probability distribution function of the variable
)
To calculate the probability distribution function of
with
both
and
uniform distributions over
, we must first
obtain the probability function of
, which is given by [18]:
Since this probability distribution is symmetrical around
(the
means of the two uniform distribution has been subtracted), we would
get an expected value of 0, but then we would forget to take into
account the absolute difference. englishThe absolute
difference will flip the probability of all values below zero over
the vertical axis and add them there. This will result in an increased
slope to the right and a probability density of 0 for negative values
[19].
Figure 1 plots eq.8. englishThe expectancy can now be calculated
![]() |
(9) |
Testing this empirically gives the following values:
,
,
,
,
and
. Which is consistent
to the above formula.
![]() |
(10) |
we can calculate
based on the previous probability
density function (8) as
![]() |
(11) |
Testing this empirically gives the following values:
,
,
,
,
and
. Which is
close to the results as given by eq. 11.
To determine
we will calculate the probability
distribution function of
, which might appear as taking the
long road when the probability distribution of uniform products on
is already known [20]. However, we will
later on needs this probability distribution on
to determine
and
and
we can now introduce the technique we will also use in section 3.5.2.
The probability
density function of
is defined as
the differential
of the cumulative probability function, which in turn is defined as
|
Figure 2 illustrates how to find the number of
values
(of
) located below a fixed
. The surface area that is not
cut off at
directly
reflects the probability that a value below
can be chosen because both
and
are uniformly distributed.
Since the isoline of
is
located at
, various
forms of
can be combined.
suffers from a discontinuity at 0 when
and its calculation
in this particular context is further complicated with a sudden
quadrant-change
of the isoline when
becomes
negative. In which case quadrant
1 and 3 no longer contain the isoline. Instead, quadrant 2 and 4 will
contain it (see figure 3 for an
illustration). To
approach this problem, we divided the calculation of
CDF
into three branches. The first with
; The second with
and the last with
.
|
Aside from these standard complications, we must also limit our
and
values to the range
. This restricts the maximal
surface area we can find and requires a piecewice approach. We start
out with a general solutions for rectangles originating in
and ending at a specific point. We have the following 4 sections:
Every section forms the two dimensional bounds (on
and
)
for the integral
, and depending on the sign of
they wil be added or
substracted to/from each other. Figure
4 presents this graphically. When
is positive
we need to subtract
and
, otherwise we need to add
them.
is used to
denoted the size of area
intersected
with the area below the isoline. The cumulative distribution function
is now defined as
CDF![]() |
(12) |
min
can be
determined by first obtaining the x-point where
the hyperbole crosses the top line of our box, which happens at
position
.
When
and
are positive, this point will
always be larger than 0. When
, the intersection will happen
outside
, in which case the surface area will be
. When
we need to integrate
and
(See figure 5 for an illustration), which gives
![]() |
(14) |
The cumulative probability function (13)
requires
us to calculate the different sections based on (14)
with
;
and
.
Since (14) appears to be discontinue at
position
we split the cumulative
probability function in 4 segments.
When
the cumulative probability
is 0 because there can
be no values
and
, both larger than
that can lead
to
a multiple that is smaller than
.
| CDF |
ln |
||
| (15) |
| CDF |
(17) |
(15), (16) and (17)
are the non-normalized
cumulative distribution functions americanwhen
. Given the maximum surface
area (17), we can divide
and differentiate them all to provide us with the proper probability
distribution (illustrated in figure 6).
We
conclude that, when
:
When
the result is somewhat more complex.
Instead
of subtracting
, we need to add them. The interesting thing
is that neither
nor
will intersect with
,
when
. However, as soon as
the situation is different.
(depicted in fig. 3). Therefore we further
branch
the calculation.
When
we have
as surface area for
and
.
| (19) |
When
we are
interested in the outside of the function
,
which is to be found in
and
. Since the area below
the curve matches that as if
,
and
were positive, we
get surface area
1.
As such, the remaining surface area must then be
![]() |
(22) |
The estimate of
is calculated
as
PDF
The probability density function of
is given in (18)
and (25).
The situation when
is discussed below. We first start with
the case where
. This gives us
Since (31)==(32), we conclude that
![]() |
(33) |
If we define
and
to be the translation and scaling of
and
as follows
then
and
are uniform distributed over
. americanThe
variable
(and
) can also be defined in function of
as
| (34) |
This substitution will make it possible to rewrite
| (35) |
becomes
and
are uniform distributions, as such
.
The estimates for
(under
condition that
) and
(under condition that
will be the same:
ln![]() |
(36) |
Without the condition that
we need to double the estimate of
(36)