




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































Shehrzad Qureshi
The following list includes commercial and intellectual trademarks belonging to holders whose products are mentioned in this book. Omissions from this list are inadvertent.
Texas Instruments, TI, Code Composer Studio, RTDX, TMS320C6000, C6000, C62x, C64x, C67x, DSP/BIOS and VelociTI are registered trademarks of Texas Instruments Incorporated. MATLAB is a registered trademark of The Math Works, Inc. ActiveX, DirectDraw, DirectX, MSDN, Visual Basic, Win32, Windows, and Visual Studio are trademarks of Microsoft. Intel, MMX, Pentium, and VTune are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
Product information contained in this book is primarily based on technical reports and documentation and publicly available information received from sources believed to be reliable. However, neither the author nor the publisher guarantees the accuracy and completeness of information published herein. Neither the publisher nor the author shall be responsible for any errors, omissions, or damages arising out of use of this information. No information provided in this book is intended to be or shall be construed to be an endorsement, certification, approval, recommendation, or rejection of any particular supplier, product, application, or service.
Copyright 2005, Springer. All Rights Reserved. This CD-ROM is distributed by Springer with ABSOLUTELY NO SUPPORT and NO WARRANTY from Springer. Use or reproduction of the information provided on this CD-ROM for commercial gain is strictly prohibited. Explicit permission is given for the reproduction and use of this information in an instructional setting provided proper reference is given to the original source.
The Author and Springer shall not be liable for damage in connection with, or arising out of, the furnishing, performance or use of this CD-ROM.
To my family, for instilling in me the work ethic that made this book possible, andLubna, for her continued support
The question might reasonably be asked when first picking up this book
xiv Preface
efficient two-dimensional Discrete Wavelet Transform (DWT) on a DSP, a topic covered extensively in Chapter 6 of this book. Such an algorithm might be needed in a digital camera to save images in the JPEG-2000 format or in a software-based MPEG4 system - wavelet coding of images has in the past few years supplanted the discrete cosine transform as the transform of choice for state-of-the-art image compression. The DWT, like many other similar transforms commonly encountered in signal and image processing, is a separable transform. This means that the two-dimensional (2D) form of the transform is computed by generalizing the one-dimensional (ID) form of it - in other words, by first performing the ID transform along one dimension (for example, each of the individual rows in the image), and then rerunning the transform on the output of the first transform in the orthogonal direction (i.e., the columns of the transformed rows). A software implementation of a 2D separable transform is relatively straightforward, if a routine exists that performs the ID transform on a vector of data. Such code would most likely march down each row, invoking the aforementioned routine for each row of image data, thus resulting in a matrix of row-transformed coefficients. This temporary image result could then be transposed (the rows become the columns and vice-versa), and the same process run again, except this time as the algorithm marches down the row dimension, the columns are now transformed. Lastly, a second transposition reshuffles the image pixels back to their original orientation, and the end result is the 2D transform. Both the 2D DWT and the 2D Fast Fourier Transform (FFT) can be computed in such a manner. This implementation strategy has the benefit of being fairly easy to understand. The problem is that it is also terribly inefficient. The two transposition operations consume processor cycles, and moreover lead to increased memory consumption, because matrix transposition requires a scratch array. On typical desktop platforms, with their comparatively huge memory footprint and multi-gigahertz clock frequencies, who cares? On these platforms, it is oftentimes possible to get away with such first-cut implementations, and still obtain more than acceptable performance. Of course, this is not always going to be the case but the name of the game in developing efficient code is to optimize only if needed, and only where needed. Thus if the initial implementation is fast enough to meet the desired specifications, there is little to gain from making algorithmic and subsequent low-level optimizations. The contrast is quite stark in the embedded DSP world however; embedded DSP cores increasingly find their way into real-time systems, with hard deadlines that must be met. And if the system happens to not be real-time, they are quite often memory and/or resource constrained, perhaps to keep costs and power consumption down to acceptable levels (consider,
xvi Preface
numbers and the decimal point is managed by the programmer, opens up a whole new can of worms. The algorithm developer must now contend with a slew of new issues, such as proper data scaling, quantization effects of filter coefficients, saturation and overflow, to name just a few. So not only has our optimized 2D DWT algorithm been tweaked so that it no longer requires matrix transpositions and is memory efficient through the usage of DMA block memory copies, but any floating-point data is now treated as bit- shifted integer numbers that must be managed by the programmer. And even still, there are many other issues that the preceding discussion omits, for example the inclusion of assembly language, vendor-specific compiler intrinsics, and a real-time operating system, but the general idea should now be clear. Even just a few of these issues can turn a straightforward image processing algorithm into a fairly complicated implementation. Taken together and all at once, these concerns may seem overwhelming to the uninitiated. Bridging this gap, between the desktop or workstation arena and the embedded world, is this book's raison d'etre. Developers must fully understand not only the strengths and weaknesses of the underlying technology, but also the algorithms and applications to the fullest extent in order to implement them on a DSP architecture in a highly- optimized form. I come from an image processing background, having developed numerous production-quality algorithms and software spanning the gamut of environments - from embedded DSPs to dual Pentium and SGI workstations - and my primary goal is to ease the transition to the embedded DSP world, which as evidenced by this case study presents itself with a set of very unique challenges. Another motivation for my writing this book, aside from the fact that there is not currently a book on the market covering embedded image processing, is to shed some light on the "black magic" that seems to accompany embedded DSP development. In comparison to developing non- embedded software, during the development of the software that accompanies this book I was continually stymied by one annoyance or another. Certain operations that would work with one DSP development platform seemingly would not work on another, and vice-versa. Or some simple examples from the TI online help tutorial would not work without certain modifications made to linker files, build settings, or the source code. There were so many issues that to be truthfully honest I have lost track of many of them. I hope that reading this book and using the code and projects that are on the CD-ROM will help you in that ever important, yet elusive, quest for "time to market."
Shehrzad Qureshi
There are many fine people who had a hand in this work, and I would like to acknowledge their effort and support. First and foremost, my soon-to- be wife, Lubna, provided invaluable feedback with regards to the composition of the book and spent countless hours reviewing drafts of the material. Without her constant encouragement and total understanding, it is doubtful this book would have ever seen the light of day and for that, I am forever grateful. I have also been blessed to have had the pleasure of working with many brilliant engineers and scientists at various employment stops along the way, and without them to learn from I could never have developed my love of algorithms and programming. I thank Steve Ling and others at Texas Instruments for their generosity in lending DSP development boards that made this book possible, as well as Cathy Wicks for her help along the way. I sincerely appreciate the support extended to me by the folks at The Math Works, in particular Courtney Esposito who disseminated early drafts of the manuscript for technical review. Finally, I would like to thank Springer for their continued support in this endeavor, especially Melissa Guasch, Deborah Doherty, and Alex Greene for their help in the final preparation of the manuscript.
2 Chapter 1
1.1 STRUCTURE AND ORGANIZATION OF THE BOOK
Because the whole thrust of this book are efficient implementations of image processing algorithms running on embedded DSP systems, it is not sufficient to simply present an algorithm and describe a first-cut implementation that merely produces the correct output. The primary goal is efficient algorithm implementations, while a secondary goal is to learn how to utilize the appropriate TI technologies that aid in the development and debugging of code that can be used in real-world applications. Achieving these goals takes time, and as such we are somewhat constrained by space. As a result, this book is not intended to be a complete coverage of image processing theory and first principles, for that the reader is referred to [1] or [2]. However, what you will find is that while such books may give you the mathematical and background knowledge for understanding how various image processing algorithms work in an abstract sense, the transition from theory to implementation is a jump that deserves more attention than is typically given. In particular, taking a description of an image processing algorithm and coding an efficient implementation in the C language on an embedded fixed-point and resource-constrained DSP is not for the faint of heart. Nowadays, given the proliferation of a variety of excellent "rapid- generation" high-level technical computing environments like MATLAB® (especially when coupled with the Image Processing Toolbox) and various software libraries like the Intel® Integrated Performance Primitives, it is not overtly difficult to put together a working image processing prototype in fairly short order. We will use both of the aforementioned software packages in our quest for embedded DSP image processing, but bear in mind that it is a windy road. The meat of this book is split amongst Chapters 3-6, with some ancillary material appearing in the two appendices. This chapter contains introductory material and Chapter 2 is important background information on the various tools employed throughout the rest of the book. Chapters 3-6 roughly cover four general categories of image processing algorithms:
Due to the challenging nature of embedded development, the strategy is to start off simple and then progressively delve deeper and deeper into the
Introduction 3
intricate implementation details, with the end game always being an efficient algorithm running on the DSP. The book follows a "cookbook" style, where an image processing algorithm is first introduced in its theoretical context. While this is first and foremost a practitioner's book, it goes without saying that a solid understanding of the theoretical underpinnings of any algorithm is critical to achieving a good implementation on a DSP. After the theoretical groundwork has been laid, examples in MATLAB are used to drive home the core concepts behind the algorithm in question, without encumbering the reader with the details that inevitably will follow. Depending on the situation, it may be the case that the MATLAB code is ported to C/C++ using Visual Studio .NET 2003. These Windows applications allow for interactive visualization and prove invaluable as parallel debugging aids, helping to answer the often posed question "Why doesn't my C code work right on my DSP, when it works just fine on the PC?" And of course, because this book is primarily targeted at those who are implementing embedded image processing algorithms, each algorithm is accompanied by an implementation tested and debugged on either the C Evaluation Module (EVM) or C6416 DSP Starter Kit (DSK). Both of these DSP platforms are introduced in 2.1.3. It should be noted that majority of the TI image-processing implementations that accompany this book use the C6416 DSK, as it contains a more recent DSP and TI appears to be phasing out the EVM platform.
1.2. PREREQUISITES
In order to get the most out of this book, it is expected that the reader is reasonably fluent in the C language and has had some exposure to MATLAB, C++, and the TI development environment. If the reader is completely new to embedded development on the TI DSP platform, but does have some experience using Microsoft Visual Studio or a similar integrated development environment (IDE), it should not be too difficult to pick up Code Composer Studio™ (CCStudio). CCStudio is heavily featured in this book and is TI's answer to Visual Studio. While one can always fall back to command-line compilation and makefiles, CCStudio incorporates many advanced features that make programming and debugging such a joy, as compared to the days of gdb, gcc, vi, and emacs. One does not need to be an expert C++ programmer in order to make sense of the Visual Studio projects discussed in the book. The use of C++ is purposely avoided on the DSP, however it is the language of choice for many programmers building scientific and engineering applications on Windows and UNIX workstations. For high-performance, non-embedded
Introduction 5
context in which they appear. The pseudo-code also assumes zero-based indexing into arrays, a la C/C++. Any reference to variables, functions, methods, or pathnames appear in a non-proportional C o u r i e r font, so that they stand out from the surrounding text. In various parts of the book, code listings are given and these listings use a 10-point non-proportional font so they are highlighted from the rest of the text. This same font is used wherever any code snippets are needed. Cascading menu selections are denoted using the pipe symbol and a bold- faced font, for example File|Save is the "Save" option under the "File" main menu. With any engineering discipline, there is unfortunately a propensity of acronyms, abbreviations, and terminology that may seem daunting at first. While in most cases the first instance of an acronym or abbreviation is accompanied by its full name, in lieu of a glossary the following is a list of common lingo and jargon the reader should be familiar with:
6 Chapter 1
- host: refers to the PC where CCStudio is running. The host PC is connected to a TI DSP development board via USB, PCI, or parallel port.
Finally, a few words regarding the references to TI documentation - the amount of TI documentation is literally enormous, and unfortunately it is currently not located in its entirety in a central repository akin to MSDN. Each TI document has an associated "literature number", which accompanies each reference in this book. The literature number is prefixed with a four-letter acronym - either SPRU for a user manual or SPRA for an application report. Some of these PDFs are included with the stock CCStudio install, but all of them can be downloaded from www.ti.com. For example, a reference to SPRU653.pdf (user manual 653) can be downloaded by entering "SPRU653" in the keyword search field on the TI web-site, if it is not already found within the d o c s \ p d f subdirectory underneath the TI install directory (typically C: \ T I ).
1.4 CD-ROM
All the source code and project files described in Chapters 3-6 and the two appendices are included on the accompanying CD-ROM. Furthermore, most of the raw data - images and in one case, video - can also be found on the CD-ROM. The CD is organized according to chapter, and the top-level README. t x t file and chapter-specific README. t x t files describe their contents more thoroughly. The host PC used to build, test, and debug the DSP projects included on the CD-ROM had two versions of CCStudio installed, one for the C EVM and another for the C6416 DSK. As a result, chances are that the projects will not build on your machine without modifications made to the