RAPID DEVELOPMENT OF RETINEX ALGORITHM ON TI
C6000-BASED DIGITAL SIGNAL PROCESSOR
Juan Zapata and Ram´on Ruiz
Departmento de Electr´onica, Tecnoloıa de Computadoras y Proyectos
Universidad Polit´ecnica de Cartagena,Muralla del Mar, s/n, Cartagena, Spain
Keywords:
Retinex Algorithm, Real-Time Signal Processing, Real-Time Workshop, MATLAB, Simulink.
Abstract:
The Retinex is an image enhancement algorithm that improves the brightness, contrast and sharpness of an
image. This work discusses an easy and rapid DSP implementation of the Retinex algorithm on a hard-
ware/software platform which integrates MATLAB/Simulink, Texas Instruments (TI) eXpressDSP Tools and
C6000 digital signal processing (DSP) target. This platform automates rapid prototyping on C6000 hard-
ware targets because lets use Simulink to model the Retinex algorithm from blocks in the Signal Processing
Blockset, and then use Real-Time Workshop to generate C code targeted to the TI DSP board by mean Code
Composer Studio (CCS IDE). The build process downloads the targeted machine code to the selected hard-
ware and runs the executable on the digital signal processor. After downloading the code to the board, our
Retinex application runs automatically on our target. It performs a non-linear spatial/spectral transform that
synthesizes strong local contrast enhancement. The library real time data exchange (RTDX) instrumentation
that contains RTDX input and output blocks let transfer image to and from memory on any C6000-based
target.
1 INTRODUCTION
With the rapid evolution in semiconductor technol-
ogy in the past several years, digital signal processing
systems have a lower overall cost compared to ana-
log systems. DSP applications can be developed, an-
alyzed, and simulated using software tools (Chacon
and Valenzuela, 2004)(Assis de Melo and La Neve,
2004)(Gan and Kuo, 2006).
Due to the fast-paced nature of the digital signal
processing applications and to the limited life span of
new products, the time to market (TTM) is a very im-
portant figure of merit that is often overlooked. The
rapid realization of an implementation from its con-
cept to a product is of utmost importance. The sci-
entific community in general, and the signal process-
ing community in particular, have developed a num-
ber of methods for the specification of higher level
algorithmic concepts and ideas. Two equivalents al-
ternatives are graphical methods and language-based
methods. Graphical method includes block diagrams,
state diagrams and schemes for the design of vir-
tual prototypes and language-based method includes
hardware description languages (HDLs). Simulink
uses graphical block diagrams to create models for
real-time implementation of applications and then use
Real-Time Workshop to generate C code targeted to
the TI DSP board by mean Code Composer Studio
(CCS IDE). The Retinex is an image enhancement al-
gorithm based on human perception which provides
color constancy and dynamic range compression. The
algorithm is inspired by the work of Lands model
for human vision. This algorithm was initially tar-
geted to process multi-spectral satellite imagery but
has found applicability in very diverse areas such
as medical radiography, medical ultrasound imagery,
aviation safety, and others. This paper presents the
rapid prototyping and implementation of Retinex im-
age enhancement algorithm on a platform based on
a TI C6000 DSP target and Simulink/MATLAB/CCS
development platform.
149
Zapata J. and Ruiz R. (2007).
RAPID DEVELOPMENT OF RETINEX ALGORITHM ON TI C6000-BASED DIGITAL SIGNAL PROCESSOR.
In Proceedings of the Second International Conference on Computer Vision Theory and Applications - IFP/IA, pages 149-152
Copyright
c
SciTePress
2 SCHEME OVERVIEW
The key aspect of rapid prototyping is automated code
generation. Under our scheme, the algorithm for a
given application is initially described with signal-
flow block diagrams with Simulink. Simulink is
a platform for multidomain simulation and Model-
Based Design for dynamic systems. It provides an
interactive graphical environment and a customizable
set of block libraries, and can be extended for spe-
cialized applications. Models built in Simulink can
be configured and made ready for code generation.
Using Real-Time Workshop, C code can be gener-
ated from the model for real-time simulation, rapid
prototyping, or embedded system deployment. Fig-
ure 1 shows the general scheme for rapid prototyping
based on MATLAB/Simulink and Texas Instruments
eXpressDSP tools.
Link for Code Composer Studio
MATLAB
Embedded Target
For TI C6000
RTDX
Target Language Compiler
Code Composer Estudio IDE
DSP C6000
C Code Model
Block Model
RTDX Comm.
Real-Time Workshop
Executable Model
Simulink
Figure 1: Development scheme of MathWorks and Texas
Instruments eXpressDSP tools.
Real-Time Workshop generates and executes
stand-alone C code for developing and testing al-
gorithms modeled in Simulink. The resulting code
can be used for many real-time and non-real-time
applications, including simulation acceleration, rapid
prototyping, and hardware-in-the-loop testing. Real-
Time Workshop uses target template files to trans-
late Simulink models into ANSI/ISO C code (Gan,
2002) (Chassaing, 2002). The target templates spec-
ify the environment on which this generated code
will run. Own custom targets can be develop or
use the ready-to-run configurations and third-party
targets supported by Real-Time Workshop. For-
tunelly, the Embedded Target for TI TMS320C6000
DSP (User Guide 3, 2006) consists of TI C6000 target
(C6000lib blockset) that automates rapid prototyping
on a C6000 hardware targets.
Embedded Target for TI TMS320C6000 DSP in-
tegrates Simulink and MATLAB with Texas Instru-
ments eXpressDSP tools. TI development tools
pick the C code generated with Real-Time Work-
shop (User Guide 6, 2006b) for a customized hard-
ware target supported for Embedded Target for TI
TMS320C6000 DSP and build an executable file for
this target-specific processor. Additionally, one of
Real-Time Workshop build options builds a Code
Composer Studio project from the C code generated
and, therefore, all features provided by Code Com-
poser Studio work to help develop the algorithm or
application.
Once target-specific executable is downloaded to
the hardware and run it, the code runs wholly on the
target and the running process can be accessed only
from Code Composer Studio or from MATLAB with
two powerful tools: Link for Code Composer Stu-
dio (User Guide 6, 2006a) and Real-Time Data Ex-
change (RTDX).
Link for Code Composer Studio lets use MAT-
LAB functions to communicate with Code Composer
Studio and with the information stored in memory and
registers on a target. With the links, information can
be transfered to and from Code Composer Studio and
with the embedded objects, information about data
and functions stored on the signal processor can be
retrieved. Within the collection of hardware that Link
for Code Composer Studio supports, some features of
the link cannot be applied.
3 SYSTEM CONFIGURATION
In our scheme, the building process is initiated from
Simulink, with a model or algorithm. Next, the Target
language Compiler from Real-Time Workshop builds
a program automatically for real-time application in
C6000 environment. Using the make utility, Real-
Time Workshop controls how it compiles and links
the generated source code. Data can be sent, or re-
ceived to the application through the RTDX channels.
3.1 Real-Time Workshop Configuration
Real-Time Workshop analyzes the block diagram and
compiles an intermediate hierarchical representation
in a file called
model.rtw
. The Target Language
Compiler reads
model.rtw
, translates it to C code.
Real-Time Workshop constructs a makefile from the
appropriate target makefile template. The make utility
reads the makefile to compile source code, link object
files and libraries, and generate an executable image,
called model (UNIX) or model.exe (Windows). Fig-
ure 2 illustrates the complete process. The box la-
beled ”Automated build process” highlights portions
of the process that Real-Time Workshop executes.
After generating the code, Real-Time Workshop
generates a customized makefile,
model.mk
. The
generated makefile instructs the make system utility
to compile and link source code generated from the
model, as well as any required harness program, li-
braries, or user-provided modules. Real-Time Work-
shop creates
model.mk
from a system template file,
system.tmf
and where system stands for the selected
target name. The system template makefile is de-
signed for a specific target environment. Exits the
option of modifying the template makefile to specify
compilers, compiler options, and additional informa-
tion used during the creation of the executable.
Real-Time Workshop creates the
model.mk
file
by copying the contents of
system.tmf
and expand-
ing lexical tokens (symbolic names) that describe a
model’s configuration. Real-Time Workshop pro-
vides many system template makefiles, configured
for specific target environments and development sys-
tems.
4 DEVELOPMENT OF RETINEX
ALGORITHM
4.1 Retinex
The general form of the center/surround retinex is
similar to the difference of Gaussian (DOG) function
widely used in natural vision science to model both
the perceptive and receptive processes. Expressed
mathematically, this take the form
R
i
(x,y) = logI
i
(x,y) log[F(x,y) I
i
(x,y)] (1)
where I
i
(x,y) is the image distribution in the ith color
spectral band, “*” denotes the convolution operation,
F(x,y) is the surround or kernel function, and R
i
(x,y)
is the associated retinex output.
F(x,y) is a Gaussian Filter defined by
F(x
1
,x
2
) = k exp[(x
2
1
+ x
2
2
)/σ
2
] (2)
where σ is the standard deviation of the filter and con-
trols the amount of spatial detail that is retained, and
model.c
model.h
...
model.mk
system.tmf
make -f model.mk
model.exe
model
private.h
Executable C Program
Program
Model Code Custom
Makefile
Makefile
Generate
Code
Generate
Set Parameters
Configuration
Template
Makefile
Model
Simulink
User-developed model and template makefile
Automated build process
make rtw.m
Figure 2: Automatic build process for Real-Time Work-
shop.
k is a normalization factor that keeps the area under
Gaussian curve equal to 1.
It is a direct result that color constancy (i.e., inde-
pendence from single source illuminant spectral dis-
tribution) is reasonably complete since the image dis-
tribution, I
i
(x,y), value can be expressed
I
i
(x,y) = S
i
(x,y)r
i
(x,y) (3)
where S
i
(x,y) is the spatial distribution of the source
illumination and r
i
(x,y), the distribution of scene re-
flectances, so that
R
i
(x,y) = log
S
i
(x,y)r
i
(x,y)
S
i
(x,y)r
i
(x,y)
(4)
where the bars denote spatially weighted average
value. As long as S
i
(x,y) S
i
(x,y), then
R
i
(x,y) log
r
i
(x,y)
r
i
(x,y)
(5)
4.2 Prototyping Retinex On Ti
C6000-based Dsp
Once the retinex model was simulated by passing of
different images and its performance was checked
then the real-time C code for a specific target was
generated through Real Time Workshop. Before two
channels for RTDX communication were added. In
this process, the executable application was built and
downloaded automatically by CCS IDE in the DSP
target. At last, real-time digital data was send for dig-
ital processing through two programs based on RTDX
instrumentation. Processed images were received for
the other channel in the same way for visualization
with different tools of MATLAB.
This is not an impediment to effective use of tools
provided for Code Composer Studio IDE. Moreover,
these tools may sometimes be necessary to use, fol-
lowing the traditional practice of development of real-
time applications using Code Composer Studio IDE
exclusively. Code Composer Studio provides tools
for configuring, building, debugging, tracing and an-
alyzing programs. Texas Instruments DSP’s provide
on-chip emulation support that enables Code Com-
poser Studio to control program execution and moni-
tor real-time program activity. Finally to point out that
the C code generated by this rapid prototyping plat-
form is not the most efficient. To obtain a better code
and increase the performance, there are techniques
to improve and modify the C code generated. How-
ever, these techniques are not rapid and easy pricessly
because designers must manually optimize the gen-
erated code in the code Composer Studio IDE. Al-
ternatively, the code can be optimized by modifying
the corresponding blocks of Simulink model and us-
ing others blocks from the preoptimized C62x and
C64x libraries. When the code is generated, the Em-
bedded Target for TI C6000 DSP produces function
calls to preoptimized assembler implementations of
the blocks, increasing the efficiency and performance
of critical zones of real-time application.
5 CONCLUSION
We have successfully implemented a real-time ver-
sion of simple scale Retinex image enhancement
algorithm using a digital signal processor. This
methodology allows an easy portability a other sim-
ilar processors. We have discussed in this paper a de-
sign methodology of retinex algorithm based on cut-
ting edge like MATLAB/Simulink, Code Composer
studio IDE, and EVM/DSK hardware based on C6000
DSP of Texas Instruments. The paper described and
illustrated the most important point to consider dur-
ing the application of this technology. This technol-
ogy lets develop and validate digital signal process-
ing designs from concept through code, in a typi-
cal professional vision design simulation implemen-
tation. Moreover, the above discussion illustrated the
use of the rapid prototyping system is a fully auto-
mated program building process, where the system is
tested prior to the generation of the executable file.
This saves tremendous amount of time, besides re-
ducing the hardware cost. In the continued effort to
train more DSP engineer, this type of technology in-
corporates an added profit to the formation of new ex-
perts in this knowledge area and can help to speed
up the learning curve and implementation of real-time
DSP applications. Another important benefit is that it
avoids low level hardware work that can be tedious
and very time consuming and therefore designers can
focus their efforts in another important aspects of de-
sign of real-time applications. This work describes
the steps needed to write and RTDX host application
using MATLAB and the Developer’s Kit for Texas
Instruments DSP. Finally we illustrated this process
with some applications presented in this paper and its
feasibility is proved.
REFERENCES
Allensworth, D. (2002). How to Write an RTDX Host Ap-
plication using Matlab. Technical report, Texas Instru-
ments.
Assis de Melo, M.A.; Leonardi, F. and La Neve, A. (2004).
Digital Signal Processing with Matlab and DSP Kits.
In Digital Signal Processing Workshop, 2004 and
the 3rd IEEE Signal Processing Education Workshop.
2004 IEEE 11th, pages 15–18.
Chacon, M. and Valenzuela, I. (2004). Fast Image Process-
ing Application Development Scheme for the DSK
C6711 using Matlab and Simulink. In Digital Signal
Processing Workshop, 2004, pages 79–83.
Chassaing, R. (2002). DSP Applications Using C and the
TMS320C6x DSK. John Wiley & Sons, New York.
Gan, W. (2002). Teaching and Learning the Hows and Whys
of Real-time Digital Signal Processing. IEEE Trans-
actions on Education, 45(4):336–343.
Gan, W.-S. and Kuo, S. M. (2006). Teaching DSP Software
Development: from Design to Fixed-point Implemen-
tations. IEEE Transactions on Education, 49(1):122
131.
User Guide 3 (2006). Embedded Target for TI
TMS320C6000. The MathWorks, Inc.
User Guide 6 (2006a). Link for Code Composer Studio De-
velopment Tools. The MathWorks, Inc.
User Guide 6 (2006b). Real-Time Workshop. The Math-
Works, Inc.