Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Implementation of A 2D Real-Time Correlator Based on a DSP



  Texas Instruments Audio and Video/Imaging Series

Image correlation plays an important roll in vision systems and it can be used for autonomous navigation, tracking systems, detection of environment changes, and automatic pattern recognition. The correlation between images must usually be calculated in a very short period of time to be integrated in real-world applications. In this project, the operation of a 2D correlator is tested by implementing a pattern recognition system based on the real-time location of a vehicle model moving along a square-shaped area. This system uses some traditional filter designs for correlation-based pattern recognition.

2D Correlation
The correlator presented in this article evaluates the correlation in frequency domain, an alternative that has been widely studied and exhibits noticeable advantages in regard to its direct domain calculation, such as the reduction of computational load [1],[8],[9]. The implementation of the correlation is based on the Image Development Kit (IDK) for the TMS320C6000 series from Texas Instruments, which includes a specific model for digital image processing [4].

Correlation evaluation begins when an input image is presented. Eventually it could need some preprocessing, which usually includes operations such as size adjustment, color space transformations, or image compression [1]. After preprocessing, we must calculate a 2D Fourier Transform of the image. In the case of an image consisting of M rows by N columns (M+N) we need a 1D Fourier Transform. A 1D Fast Fourier Transform (FFT) for N samples needs about Nlog2N complex products, thus a 2D FFT for an M*N image involves about N*M*log2MN complex multiplications [3],[5],[10]. We can achieve additional speed up considering that the input image is a real signal and hence its Fourier Transform is an Hermitic function (F(s) = F*(-s)) [3].

Then, the 2D Fourier Transform of the input image is multiplied by the conjugation of the filter's frequency response. We obtain the classical matched-filter (MF) when the Fourier Transform of the target is taken as a filter [7]. When all the magnitudes of the frequency response are set to 1 the filter is called a Phase-only Filter (POF). Also, we can use a circular harmonic component of the target's spectrum as a filter which leads to the Circular Harmonic Filter (CHF) [7]. These are only a sample of some of the filter designs available. The product between the spectrum of the image and the conjugation of the filter is used as input for a 2D Inverse Fourier Transform and the result is the desired correlation. The correlator implemented in this work follows Equation 1 for its calculations.

   (1)

Where the terms represent:

C:Correlation matrix
ƒs:Diagonal swap of the matrix's quadrants
FFT, IFFT:Direct and inverse 1D Fast Fourier Transforms along the rows of a matrix
T:Matrix transpose
H(u,v):Filter built from target image
ƒ:Input image (scene)
max:Maximum value of a matrix

We can analyze the correlation result in several ways to make a decision about possible locations of the target in the input scene. The filter H(u,v) is previously calculated and stored in memory. We can calculate FFTs faster for real data if the values are arranged in a special way, because the length of the vector is reduced in half [6].

IFFT operations are performed without additional optimization while quadrants swap (ƒs) and matrix transpose (T) are accomplished using channels for Direct Memory Access (DMA) available in the IDK. Table 1 demonstrates results on the time invested in each process for the evaluation of Equation 1 using the DSP TMS320C6711.

Size of Input Image 256x256 512x512
Operation Time (s) % Time (s) %
Image acquisition ƒ 0.00481 5.6 0.0250 6.2
First ƒs 0.00015 0.1 0.0030 0.7
First FFT 0.00637 7.4 0.0510 12.4
First T 0.01002 11.7 0.0316 7.7
Second FFT 0.01125 13.2 0.0369 8.9
Multiplication by H * (u,v) 0.01193 14.0 0.0578 14.0
First IFFT 0.01411 16.5 0.0744 18.1
Second T 0.01049 12.3 0.0564 13.7
Second IFFT 0.01187 14.0 0.0663 16.1
Third ƒs 0.00400 4.7 0.0074 1.8
TOTAL 0.08506 100 0.4109 100

Table 1:  Processing time for each step involved in (1)

Basic Pattern Recognition System
A basic recognition system involves additional processes besides correlation. Figure 1 includes a block diagram showing those operations required for a real-time pattern recognition system. We must binarize the correlation matrix in order to identify target location(s) in the input scene. In this article, we have used a fraction of the maximum value of the magnitude of the correlation matrix as threshold.


Figure 1:  Stages involved in a basic pattern recognition system

After binarizing the magnitude of the correlation matrix, a labeling is done in which an integer number is assigned to the pixels of each non-zero region of the matrix. Then, centers of mass are calculated for each of the labeled regions and those values are stored in memory. Finally, the display process consists of showing a mark (for example, a small cross) at each of the coordinates at the centers of mass stored in memory. All these operations must be done in real-time. We haveimplemented them with the DSP TMS320C6711 and tested in real-time conditions; mean values for processing time results for a single frame are demonstrated in Table 2.

Input Image Size 256x256
Operation Time (s) %
2D Correlation 0.08506 86.6
Binarization 0.00338 3.4
Labeling and Center of Mass 0.00919 9.4
Display 0.00055 0.6
TOTAL 0.09818 100

Table 2:  Processing time for each stage involved in Figure 1

As Table 2 illustrates, additional processing for the pattern recognition system leads to an increase of 13.12 milliseconds which is about 13.4% of computational load. Most of the additional load is concentrated in the process of labeling and calculation of center of mass which takes 9.4% of the whole processing time.

Testing of the Pattern Recognition System
We have designed a simple pattern recognition application for testing the implemented real-time correlation system. The setup includes a limited rectangular zone painted in black where different cars run in random directions. The track size is 64x72 cm2. Input images are captured using a digital camera aimed to -90 degrees azimuth, located 1.2 meters over the track. Three different car models (shown in Figure 2) were selected for the application. Figure 3a shows the track with two of the vehicles on it.


Figure 2:  Car models used as target pattern

This proposed application requires rotation invariant response of the filter because target location must be given independently of the orientation of the vehicle given that car models move in random directions. Circular Harmonic Filters (CHFs) exhibit this feature an were appropriated for this requirement.

Circular Harmonic Filters
Circular Harmonic Filters (CHFs) are developed from decomposition of a two-dimensional target ƒ(r,Θ) in its Circular Harmonic Components (CHCs) given by the following expression:

   (2)

we can calculate the order m radial component, ƒm(r) according to

   (3)

From Equation 2, when the target is rotated by α degrees, all its CHCs will include a phase term of the form eimα. Using Equation 3, we can conclude that only radial components are affected when the target is scaled. Particularly, the first feature is used by CHFs to obtain rotation invariance, which guarantees a constant correlation peak value even when the target is rotated in the input scene. Order mth classical CHFs have the following impulse and frequency response:

   (4)

   (5)

There are many filter designs based on CH decomposition. Some of the most important versions include the following designs:

Phase-Only CHF:    (6)
Optimum Trade-Off CHF:    (7)
Phase-Derived CHF:    (8)

Where K is a tunable constant while m is the order of the filter.

We tested and evaluated the recognition performance of Classical, Phase-Only, Optimum Trade-Off, and Phase-Derived CHFs on the implemented system. Second order filters (m=2) lead in all cases to the best results.


Figure 3:  (a) Input scene and (b) magnitude of the correlation matrix between the scene and target in Figure 2a

We tested the performance of the four filter designs in real-time conditions with the pattern recognition system. The target was perfectly located almost all of the time independently of its orientation (Figure 3). This figure shows the intensity distribution of the correlation between the phase-derived CHF of target (Figure 2a) and the scene (Figure 3a). Sometimes the system lost the target, usually when the car model was located at the borders of the track, while a non-target vehicle was located at the central region. This situation is caused by a change in perspective.

In order to compare the general performance of the different filter designs, an 18 minute video clip of the cars moving randomly along the track was recorded and used as input for the recognition system. The video was processed with the recognition system, changing the filter design and the target, so a total of 12 specific situations were tested. The output of the pattern recognition system was recorded and the probabilities of success in target location were estimated by randomly sampling a representative number of output frames. These probabilities are shown in Figure 4.


Figure 4:  Probabilities of success for target location with different filter designs

From Figure 4, we concluded that Phase-Derived CHF shows the best performance. Also, when the car model in Figure 2c was used as target, the probability of success for all the filters was very high, close to 100%. This is because target in Figure 2c exhibits the highest mean intensity value among all three targets. Targets 2a and 2b showed a probability of detection close to 80% when detected with Phase-derived CHF. In the remaining 20% of the cases, when the target was missed, a false detection was generated due to the presence of the car model corresponding to Figure 2c, which is brighter than all the other images.

Conclusions
This research work deals with the implementation and characterization of a real-time 2D correlator based on a DSP. Two image resolutions were tested, 256x256 and 512x512. The system can yield 12 fps and only 2 fps, respectively. A basic pattern recognition system implemented with the correlator, has shown a slight lower performance of 10 and 1.5 fps respectively, mainly due to the additional processing besides correlation.

We idetified some limitations on the use of DSPs for digital image processing. DSPs are very well suited for basic image processing operations, such as binarization or spatial filtering, and they take advantage of software and hardware resources. However, the architecture of the DSP used in this implementation does not allow a peak performance when operations such as 2D filtering in frequency domain or 2D correlation are performed.

The implementation of the pattern recognition system allowed us to compare four filter designs that guarantee rotation-invariant results for correlation. Particularly, phase-derived CHFs achieved the best results when we measured probability of detection. Future work will be focused on including invariance to small perspective variations generated when the target is far away from the vertical axis of the camera. Also, a superior resistance to noise presence and changes in illumination will improve the performance of the system.

About the Authors
Oscar Gualdrón González is presently directing Universidad Industrial de Santander (UIS) investigation department. He is associated in the Department of Electrical, Electronic and Telecommunications at the UIS. He received his Ph.D degree from Laval University.

Henry Arguello Fuentes is associated in the Department of Electrical, Electronic and Telecommunications at the UIS. He received his B.S and M.S. degrees in 2000 and 2003, respectively, in electrical engineering from the same department.

References


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.