23
@imos http://imoz.jp/ /23 Fast Gaussian Filtering Algorithm Using Splines Kentaro Imajo (M2, Kyoto University) November 12, International Conference on Pattern Recognition 2012 1

Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

@imos http://imoz.jp/

/23

Fast Gaussian Filtering Algorithm Using Splines Kentaro Imajo (M2, Kyoto University)

November 12, International Conference on Pattern Recognition 2012 1

Page 2: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Contents 1. Background and Goal 2. Approximation of Gaussian Function 3. 1D Convolution 4. 2D Convolution 5. Outline of Algorithm 6. Experiments 7. Conclusions November 12, International Conference on Pattern Recognition 2012 Chapter 0. Contents 2

Page 3: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Background and Goal Chapter 1 of 7

November 12, International Conference on Pattern Recognition 2012 Chapter 1. Background and Goal 3

Page 4: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Background Many algorithms such as SIFT need to compute Gaussian filter.

Chapter 1. Background and Goal November 12, International Conference on Pattern Recognition 2012

* = 2D Gaussian Func.

Figure Image Blurred by 2D Gaussian Filter

convolution

4

Page 5: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Gaussian Filter Gaussian Filter is computed by convolutions with 2D Gaussian function. 2D Gaussian Function: where σ is spread.

Chapter 1. Background and Goal November 12, International Conference on Pattern Recognition 2012

1�2��

exp��x2 + y2

2�2

�Circle

5

Page 6: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Propose an algorithm to compute one Gaussian-filtered pixel in constant time to area size n (∝ σ2). Naïve method requires O(n) time.

Goal

Chapter 1. Background and Goal November 12, International Conference on Pattern Recognition 2012

× Area size is n Target Pixel

6

Page 7: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Preceding Methods •  Naïve method takes O(n) time. •  FFT method is fast for all pixels, but it cannot compute pixels apart. •  Down-sampling method has large errors. Within 3% error in constant time Chapter 1. Background and Goal November 12, International Conference on Pattern Recognition 2012 7

Page 8: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Approximation of Gaussian Function Chapter 2 of 7

Chapter 2. Approximation of Gaussian Function November 12, International Conference on Pattern Recognition 2012 8

Page 9: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Spline Approximate Gaussian function with a spline, which is written as: where a, b, n are parameters, and (・)+ is max(・, 0). * Coordinates b are control points. Chapter 2. Approximation of Gaussian Function November 12, International Conference on Pattern Recognition 2012

�̃(x) =�

i

ai (x� bi)n+

9

Page 10: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

-15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15

80

160

240

�̃(x) = 3(x + 11)2+ � 11(x + 3)2++11(x� 3)2+ � 3(x� 11)2+,

� 2.657� 102 exp�� x2

5.27202

�.

Approximation

Chapter 2. Approximation of Gaussian Function November 12, International Conference on Pattern Recognition 2012 10

× ×

× ×

- Approximation - Gaussian func. × Control points

Page 11: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Evaluation Approximation error is about 2%. (2D error is about 3%.) Higher order improves more: Approximation error of 4th order approximation is about 0.3%.

Chapter 2. Approximation of Gaussian Function November 12, International Conference on Pattern Recognition 2012 11

�̃(x) = 70(x + 22)4+ � 624(x + 11)4+ + 1331(x + 4)4+�1331(x� 4)4+ + 624(x� 11)4+ � 70(x� 22)4+.

Page 12: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

1D Convolution Chapter 3 of 7

Chapter 3. 1D Convolution November 12, International Conference on Pattern Recognition 2012 12

Page 13: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Convolution Convolution of a signal and a spline. Key Idea: Splines get discrete by differentiation.

Chapter 3. 1D Convolution November 12, International Conference on Pattern Recognition 2012 13

-12 -8 -4 0 4 8 12

-240

-160

-80

80

160

240

-12 -8 -4 0 4 8 12

-25

25

-12 -8 -4 0 4 8 12

-10

-5

5

10

-12 -8 -4 0 4 8 12

-12

-8

-4

4

8

12

Differentiate

Page 14: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Transformation Transform convolution into summation.

Chapter 3. 1D Convolution November 12, International Conference on Pattern Recognition 2012 14

(�̃ � I)(x) =�

�x�Z�̃(�x)I(x��x)

=�

�x�Z

�m�

i=0

ai(�x� bi)n+

�I(x��x)

=m�

i=0

aiJ(x� bi), J(x) =�

�x�Z�xn

+I(x��x)

Pre-computed Several calculations

Page 15: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

2D Convolution Chapter 4 of 7

Chapter 4. 2D Convolution November 12, International Conference on Pattern Recognition 2012 15

Page 16: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

2D Gaussian func. can be decomposed: Approximation can be written as: where

(�̃ � I)(x, y) =m�

i=1

ai

m�

j=1

ajJ(x� bi, y � bi)

2D Convolution

Chapter 4. 2D Convolution November 12, International Conference on Pattern Recognition 2012 16

exp��x2 + y2

2�2

�= exp

�� x2

2�2

�exp

�� y2

2�2

20 multiplications and 16 additions

J(x, y) =�

(�x,�y)�Z2+

�xn�ynI(x��x, y ��y)

Page 17: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Evaluation

Chapter 4. 2D Convolution November 12, International Conference on Pattern Recognition 2012 17

using a discrete image J , which is written as:

J(x, y) =!

(!x,!y)!Z2+

!xn!ynI(x ! !x, y ! !y).

When a source image I is given, the image J can becomputed in O(n2|I|) time by iterations as well asEquation (6).

As a result, precomputing J at once, for any convo-lution of a source image I and an nth-order 2D splinefunction, a convoluted value (!̃II " I)(x, y) can be com-puted in O(m2) time.

6. Approximated Gaussian Functions

In this section, we present two good sets of param-eters below to approximate the 1D Gaussian function.Absolute values of parameters b of a good set shouldbe small for easy and fast computation, and absolutevalues of the parameters b of the following sets are notlarger than 22, which is small, compared with ordinaryimages.

Second-order approximation:

!̃2(x) = 3(x + 11)2+ ! 11(x + 3)2++11(x ! 3)2+ ! 3(x ! 11)2+, (7)

# 2.657 $ 102 exp"! x2

5.27202

#. (8)

Fourth-order approximation:

!̃4(x) = 70(x + 22)4+ ! 624(x + 11)4++1331(x + 4)4+ ! 1331(x ! 4)4++624(x ! 11)4+ ! 70(x ! 22)4+, (9)

# 7.621 $ 107 exp"! x2

7.767802

#. (10)

6.1. Evaluation of Approximated Functions

Next, we evaluate the approximated functions by cal-culating error of two types EI,!̃ and EII,!̃ , which areerror in 1D and in 2D respectively. Using an approxi-mation function !̃ and its targeted function !, they aredefined as:

EI,!̃ =

$

R

%%%!(x) ! !̃(x)%%% dx

$

R!(x)dx

, (11)

EII,!̃ =

$$

R2

%%%!(x)!(y) ! !̃(x)!̃(y)%%% dxdy

$$

R2|!(x)!(y)| dxdy

. (12)

0 10 20x

0

4 ! 104

8 ! 104

z

· · · Gaussian— Horizontal section- - - Oblique section

Figure 2. Second-order approximation

-15 0 15x

-15

0

15

y

$ $ $ $

$ $ $ $

$ $ $ $

$ $ $ $

· · · Gaussian — Approximation ! Control point

Figure 3. Elevation and control points

Applying the equations, we can calculate values oferror of the two approximations (7) and (9), whose tar-geted functions are (8) and (10) respectively, as follows:

EI,!̃2% 0.02009, EII,!̃2

% 0.03473,EI,!̃4

% 0.00305, EII,!̃4% 0.00583.

Figure 2 compares the 2D Gaussian function and twosections of the second-order approximated function intwo dimension. One of the sections is a horizontal sec-tion z = !̃2(x)!̃2(0), and the other one is an oblique

section z =&!̃2( x"

2)'2

.

Figure 3 shows elevations of every 104 for the Gaus-sian function and the approximation function in two di-mension. As the Gaussian function is rotatable, eleva-tions of the Gaussian function are perfect circles. Onthe other hand, elevations of the approximated Gaus-sian function, which are indicated by red solid lines, arevery similar to perfect circles. Therefore we can use theapproximated Gaussian function as an almost-rotatablefilter function.

Figure Elevation and control points

Page 18: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Outline of Algorithm Chapter 5 of 7

Chapter 5. Outline of Algorithm November 12, International Conference on Pattern Recognition 2012 18

Page 19: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Outline of Algorithm 1. Pre-compute J once an image in linear time to the area of the image. 2. Compute a Gaussian filtered value in constant time (tens operations) for any combinations a, b.

Chapter 5. Outline of Algorithm November 12, International Conference on Pattern Recognition 2012 19

(�̃ � I)(x, y) =m�

i=1

ai

m�

j=1

ajJ(x� bi, y � bi)

J(x, y) =�

(�x,�y)�Z2+

�xn�ynI(x��x, y ��y)

Page 20: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Experiments Chapter 6 of 7

Chapter 6. Experiments November 12, International Conference on Pattern Recognition 2012 20

Page 21: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Experiments

Chapter 6. Experiments November 12, International Conference on Pattern Recognition 2012 21

Method Precomputation Computation for all pixels Computation for one pixelNaı̈ve method No O(NM) O(M)FFT method No O(N log N) N/A

Proposed method O(N) at first O(N) O(1)

Table 1. Comparison of computational orderN and M is the size of a source image and the Gaussian filter respectively.

N/A indicates that the FFT method cannot compute values apart.

100 101 102 103 104

# of application pixels of the filter

10!8

10!7

10!6

10!5

10!4

Com

puta

tiona

ltim

e(s

ec.)

— Proposed method - - - Naı̈ve method

Figure 4. Computational time for one pixelon average

7. Experiments

Comparing with the naı̈ve method and the FastFourier Transform method, we evaluate the proposedmethod with a 1024 ! 1024 gray-scale image and theGaussian filter whose the parameter ! is 47.448 and theapplication area is 99 ! 99 pixels. We implementedthem in C++ and compiled them with GNU C++ Com-piler and execute them on Mac Pro (6-core 2.93GHzXeon). As the result of computation, the naı̈ve methodtook 13.7 seconds, and the FFT method took 0.373 sec-onds, and the proposed method took 0.102 seconds. Inthis case, the proposed method can do it more than 100times as fast as the naı̈ve method does.

Next, we evaluate computational time to figure outa filtered value of one pixel. Table 1 shows computa-tional order of the precomputation and computation ofall pixels and computation of one pixel for each method.Computational time of the naı̈ve method depends on ap-plication area of the filter. Figure 4 shows the proposedmethod is faster than the naı̈ve method if applicationarea of the filter is larger than 8 ! 8.

8. Conclusion

We proposed a fast method to apply the Gaussianfilter to a 2D image. In order to compute one Gaus-sian filtered pixel value, the naı̈ve method spends O(M)time, where M is the size of the Gaussian filter. Whilethe FFT method compute all Gaussian filtered pixel val-ues simultaneously in O(N log N) time, where N is thesize of a source image, it cannot compute them sparsely.The proposed method computes one Gaussian filteredpixel value in constant time on the size of a source im-age and the Gaussian filter.

The proposed method approximates the Gaussian fil-ter function using a spline function whose number of thecontrol points is small. Although precomputation takestime linear in the size of a source image, the precom-putation does not depend on the size of the Gaussianfilter, so we do not need to recalculate the precomputa-tion even if we use a different size of the Gaussian filter.

As a result, the proposed method is more than 100times as fast as the naı̈ve method when application areais 99! 99 pixels. Furthermore, unlike the FFT method,the proposed method can compute a filtered pixel valueat any position with any size of the Gaussian filter inconstant time.

References

[1] David G. Lowe. Object recognition from localscale-invariant features. The Proceedings of theSeventh IEEE International Conference on Com-puter Vision, 2:1150–1157, 1999.

[2] David G. Lowe. Distinctive image features fromscale-invariant keypoints. International Journal ofComputer Vision, 60(2):91–110, 2004.

[3] Herbert Bay, Andreas Ess, Tinne Tuytelaars, andLuc Van Gool. SURF: Speeded up robust fea-tures. European Conference on Computer Vision,110(3):346–359, 2006.

Figure Computational time for one pixel on average

For 70+ pixels our algorithm is faster

Diameter of 9 has 69 pixels

Page 22: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Conclusions Final Chapter

Chapter 7. Conclusions November 12, International Conference on Pattern Recognition 2012 22

Page 23: Fast Gaussian Filtering Algorithm Using Splines · -15 -12.5 -10 -7.5 -5 -2.5 0 2.5 5 7.5 10 12.5 15 80 160 240 ˜(x) = 3(x +11)2 + 11(x +3)2 + +11(x 3)2 + 3(x 11)2 +, 2.657 102 exp

/23

Conclusions With pre-computing once an image, the proposed algorithm computes any size of the Gaussian filter •  in constant time to size, •  faster than naïve for 70+ pixels, •  within 3% error.

Chapter 7. Conclusions November 12, International Conference on Pattern Recognition 2012 23