|
1 |
| -Convolution forms a pillar in a large number of image processing applications. It is a mathematical |
2 |
| -operation which is applied in a same manner over the entire considered region in an image. |
| 1 | +Two dimensional convolution and correlation |
| 2 | +------------------------------------------- |
| 3 | + |
| 4 | + |
| 5 | +What is the role of convolution in image processing? |
| 6 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 | + |
| 8 | + |
| 9 | +Convolution forms a base pillar in a large number of image processing applications. It is a |
| 10 | +mathematical operation which is applied in a same manner over the entire considered region in an image. |
3 | 11 | Accessing all pixels in a similar manner creates the room for optimization in this algorithm.
|
4 | 12 | We have thus targeted our efforts towards improving the spatial access of pixel elements during
|
5 | 13 | 2D convolution and correlation.
|
6 | 14 |
|
7 |
| -There are many ways of performing 2D convolution, the naive one includes irregular access of source |
| 15 | + |
| 16 | +--------------------------------- |
| 17 | + |
| 18 | + |
| 19 | +What are we doing differently? |
| 20 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | + |
| 22 | + |
| 23 | +There are many ways of performing 2D convolution, the naive ones includes irregular access of source |
8 | 24 | image pixels. Due to this, a large number of cache misses occur which further in turn degrade the
|
9 | 25 | performance. We have tried to improve this access pattern and hence reduce the number of overall
|
10 | 26 | cache misses.
|
11 | 27 |
|
12 |
| -What are we doing differently? |
13 | 28 |
|
14 | 29 | Our strategy involves storing relevant 2D image data in a 1D buffer container. This container will
|
15 | 30 | then be used for accessing required patches of pixels during convolution. These patches will be
|
16 |
| -accessed by a sliding window algorithm so that their dot product with 1D aligned kernel can be stored |
| 31 | +accessed by a sliding window algorithm so that their dot product with 2D kernel can be stored |
17 | 32 | in destination image.
|
18 | 33 |
|
19 |
| -But how much data should be stored inside the buffer? |
| 34 | + |
| 35 | +--------------------------------- |
| 36 | + |
| 37 | + |
| 38 | +How much data should be stored inside the buffer? |
| 39 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 40 | + |
20 | 41 |
|
21 | 42 | We store only that much data which will be required by kernel during its one single horizontal slide.
|
22 |
| -In other words, the size of buffer container will be kernel_size * img_width + boundary_offset. |
23 |
| -Here boundary_offset is the addition in buffer size which will take place due to boundary |
| 43 | +In other words, the size of buffer container will be |
| 44 | + |
| 45 | +``buffer size = kernel_size * img_width + boundary_offset`` |
| 46 | + |
| 47 | +where ``boundary_offset = (extrapolation_required == 1) ? ((kernel_size - 1) * kernel_size) : 0`` |
| 48 | + |
| 49 | +Here, boundary_offset is the addition in buffer size which will take place due to boundary |
24 | 50 | extrapolation for corner pixels.
|
25 | 51 |
|
| 52 | + |
| 53 | +---------------------------------- |
| 54 | + |
| 55 | + |
26 | 56 | What to do after forming the buffer container?
|
| 57 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 58 | + |
27 | 59 |
|
28 | 60 | Once our data is present inside the buffer container, a sliding window algorithm is applied for
|
29 | 61 | calculating the dot product between kernel and image patch contained inside sliding window.
|
30 |
| - |
31 | 62 | Boundary extrapolation is taken care by changing elements of buffer container suitably.
|
32 | 63 |
|
| 64 | + |
| 65 | +---------------------------------- |
| 66 | + |
| 67 | + |
33 | 68 | How do we take care of variable anchor point positions?
|
| 69 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 | + |
34 | 71 |
|
35 | 72 | While filling the buffer container, we will take care of this by starting/ending the filling process
|
36 | 73 | at suitable points in source image.
|
37 |
| - |
38 | 74 | This will automatically take care of the problem and will achieve desired effect due to the followed
|
39 | 75 | pattern of pixel assignment.
|
| 76 | + |
| 77 | + |
| 78 | +------------------------------------------------------- |
| 79 | + |
| 80 | + |
| 81 | +What to do with spatial separable kernels? |
| 82 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 83 | + |
| 84 | + |
| 85 | +We have written a custom algorithm which can detect whether a two dimensional kernel can be |
| 86 | +spatially separated. It does separation as well as checking for separability |
| 87 | +simultaneously. If at any step during checking, the kernel is deemed non-separable, the separation |
| 88 | +algorithm stops, otherwise horizontal and vertical separated kernels are returned. |
| 89 | +The algorithm uses the fact that a separable 2D matrix is essentially a rank1 matrix. It further |
| 90 | +uses basic linear algebra for separating the kernel. |
| 91 | + |
| 92 | + |
| 93 | +------------------------------------------------------- |
0 commit comments