Image Processing With VHDL PDF
Image Processing With VHDL PDF
U. Chuks
6/1/2010
Copyright © 2010 by U. Chuks
U. Chuks
Visit my page at
http://www.lulu.com/spotlight/Debarge
Contents
Table of Contents
Contents............................................................................................ iii
Preface ............................................................................................... vi
Chapter 1 .......................................................................................... 1
Introduction...................................................................................... 1
1.1 Overview of Digital Image Processing .................................. 1
1.1.1 Application Areas .................................................... 2
1.2 Digital Image Filtering .......................................................... 2
1.2.1 Frequency Domain .......................................................... 2
1.2.2 Spatial Domain ................................................................. 4
1.3 VHDL Development Environment ......................................... 6
1.3.1 Creating a new project in ModelSim .............................. 7
1.3.2 Creating a new project in Xilinx ISE ............................. 14
1.3.3 Image file data in VHDL image processing ................. 18
1.3.4 Notes on VHDL for Image Processing ......................... 20
References................................................................................... 23
Chapter 2 ........................................................................................ 25
Spatial Filter Hardware Architectures ............................................ 25
2.1 Linear Filter Architectures .................................................... 25
2.1.1 Generic Filter architecture ............................................. 28
2.1.2 Separable Filter architecture ......................................... 30
2.1.3 Symmetric Filter Kernel architecture ............................ 32
iii
2.1.4 Quadrant Symmetric Filter architecture ....................... 34
2.2 Non-linear Filter Architectures ............................................. 35
Summary...................................................................................... 35
References................................................................................... 36
Chapter 3 ........................................................................................ 37
Image Reconstruction .................................................................. 37
3.1 Image Demosaicking .......................................................... 37
3.2 VHDL implementation........................................................... 44
3.2.1 Image Selection ............................................................. 49
Summary...................................................................................... 57
References................................................................................... 57
Chapter 4 ......................................................................................... 59
Image Enhancement....................................................................... 59
4.1 Point-based Enhancement................................................... 60
4.1.1 Logarithm Transform ..................................................... 60
4.1.2 Gamma Correction ........................................................ 62
4.1.3 Histogram Clipping ........................................................ 62
4.2 Local/neighbourhood enhancement .................................... 64
4.2.1 Unsharp Masking ........................................................... 64
4.2.2 Logarithmic local adaptive enhancement .................... 65
4.3 Global/Frequency Domain Enhancement ........................... 65
4.3.1 Homomorphic filter......................................................... 66
4.4 VHDL implementation........................................................... 66
Summary...................................................................................... 68
References................................................................................... 68
Chapter 5 ......................................................................................... 70
iv
Image Edge Detection and Smoothing ......................................... 70
5.1 Image edge detection kernels.............................................. 70
5.1.1 Sobel edge filter ............................................................. 71
5.1.2 Prewitt edge filter ........................................................... 72
5.1.3 High Pass Filter.............................................................. 73
5.2 Image Smoothing Filters ...................................................... 74
5.2.1 Mean/Averaging filter..................................................... 75
5.2.2 Gaussian Lowpass filter ................................................ 75
Summary...................................................................................... 77
References................................................................................... 77
Chapter 6 ......................................................................................... 78
Colour Image Conversion............................................................... 78
6.1 Additive colour spaces ......................................................... 78
6.2 Subtractive Colour spaces ................................................... 79
6.3 Video Colour spaces ............................................................ 82
6.4 Non-linear/non-trivial colour spaces .................................... 91
Summary...................................................................................... 95
References................................................................................... 95
Circuit Schematics .......................................................................... 97
Creating Projects/Files in VHDL Environment ............................ 106
VHDL Code ................................................................................... 118
Index............................................................................................... 123
v
Preface
The relative dearth of books regarding the know-how involved in implementing
several algorithms in hardware was the motivating factor in writing this book,
which was written for those with a prior understanding of image processing
fundamentals who may or may not be familiar with programming environments
such as MATLAB and VHDL. Thus, the subject is addressed very early on,
bypassing the fundamental theories of image processing, which are better
covered in several contemporary books given in the references sections in the
chapters of this book.
Though the book does not discuss the vast theoretical mathematical processes
underlying image processing, it is hoped that by providing working examples
of actual VHDL and MATLAB code and simulation results of the software, that
the concepts of practical image processing can be appreciated.
This first edition of this book attempts to provide a working aid to readers who
wish to use the VHDL hardware description language for implementing image
processing algorithms from software.
vi
Chapter 1
Introduction
Digital image processing is an extremely broad and ever
expanding discipline as more applications, techniques and
products utilize digital image capture in some form or the
other. From industrial processes like manufacturing to
consumer devices like video games and cameras, etc,
image processing chips and algorithms have become
ubiquitous in everyday life.
1
Introduction
Image Reconstruction, Enhancement and Colour Image
Processing and the VHDL implementation of selected
algorithms from these areas.
(1.2.1-1)
(1.2.1-2)
Fourier Inverse
Transform Fourier
Transform
(a) (b)
Figure 1.2.1(ii) – (a) Image in spatial domain (b) Image in frequency
domain
4
Introduction
each pixel in an image. Examples include the median and
variance filters used in image restoration. Figure 1.2.2(i)
show the basics of spatial domain processing where
is the input image and is the processed output
image.
Pre- Filter Post-
Ii ( x, y) processing Function processing Io(x, y)
(a) (b)
(c) (d)
Figure 1.2.2(ii) – Low-pass filter in the (a) frequency domain (b) spatial
domain and High-pass filter in the (c) frequency domain (d) spatial
domain
5
Introduction
This gives an idea of the span of the spatial domain filter
kernels relative to their frequency domain counterpart.
6
Introduction
1.3.1 Creating a new project in ModelSim
Before proceeding, ModelSim software from Mentor
Graphics must be installed and enabled. Free ModelSim
software can be downloaded from internet sites like Xilinx
website or other sources. The one used for this example is
a much earlier version of ModelSim (version 6.0a) tailored
for Xilinx devices.
Close the welcome page and click on File, select New ->
Project as shown in Figure 1.3.1(ii).
7
Introduction
store all project files to have a more organized work folder.
Thus, click on Browse and the dialog box shown in Figure
1.3.1(iv) appears. Now we can navigate to an appropriate
folder or create one if it doesn‟t exist. In this case, a
previously created folder called „colour space converters‟
was created to store the project files. Clicking „OK‟ returns
us to the „Create a New Project‟ dialog box and now we
name the project as „Colour space converters‟ and click
„OK‟.
8
Introduction
A small window appears for us to add a new or existing file
as shown in Appendix B, Figure B1.
9
Introduction
10
Introduction
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
11
Introduction
The “IEEE.std_logic_1164” and the
“IEEE.std_logic_arith” are the standard logic and the
standard logic arithmetic libraries, which are the minimum
libraries needed for any VHDL logic design since they
contain all the necessary logic functions.
clk
rst example_file output_port
input_port
12
Introduction
The code in Figure 1.3.1(vii) is the textual or code
description of the black box diagram shown in Figure
1.3.1(vi).
begin ---start
process(clk, rst) --process which is
triggered by clock or reset pin
begin
if rst = '0' then --reset all output ports
intermediate_port <= '0'; --initialize
output_port <= '0'; --initialize
elsif clk'event and clk = '1' then --operate
on rising edge of clock
intermediate_port <= not(input_port); -
-logical inverter
output_port <= intermediate_port or
input_port; --logical or operation
end if;
end process; --self-explanatory
end behaviour; --end of architectural behaviour
13
Introduction
The first line of code in Figure 1.3.1(viii) defines the
beginning of the behavioural level of the architecture. The
next line defines a signal or wire that will be used in
connecting the input port to the output port. It has been
defined as a single bit and initialized to zero.
14
Introduction
15
Introduction
We then click „OK‟ on the welcome dialog box to access the
project workspace. Then click on File, select New Project
as shown in Figure 1.3.2(ii) and enter a new name for the
project as shown in Figure 1.3.2(iii). Then click „Next‟ and
the next window shown in Figure 1.3.2(iv) prompts you to
select the FPGA hardware device family your final design is
going to be implemented in. We select the Xilinx Spartan 3
FPGA chip which is indicated by the chip number xc3s200
and the package is ft256 and the speed grade is -4. This
device will be referred to as 3s200ft256-4 in the Project
Navigator.
16
Introduction
17
Introduction
20
Introduction
When using these fourth generation languages like C# and
MATLAB, writing programs to perform mathematical tasks
and operations is much easier and users can make use of
existing libraries to build larger scale systems that perform
more complex mathematical computations without thinking
much about them.
Most of the images used in this book are well known in the
image processing community and were obtained from the
University of South Carolina Signal and Image Processing
Institute website and others from relevant research papers
and online repositories.
References
R. C. Gonzalez and R. E. Woods, Digital Image Processing, 2
ed.: Prentice Hall, 2002.
R. C. Gonzalez, R. E. Woods, and S. L. Eddins, Digital Image
Processing Using MATLAB: Prentice Hall, 2004.
W. K. Pratt, Digital Image Processing, 4 ed.: Wiley-Interscience,
2007.
U. Nnolim, “FPGA Architectures for Logarithmic Colour Image
Processing”, Ph.D. thesis, University of Kent at Canterbury,
Canterbury-Kent, 2009.
MathWorks, "Image Processing Toolbox 6 User's Guide for use
with MATLAB," The Mathworks, 2008, pp. 285 - 288.
[6] Mathworks, "Designing Linear Filters in the Frequency
Domain," in Image Processing Toolbox for use with MATLAB,
T. Mathworks, Ed.: The Mathworks, 2008.
Mathworks, "Filter Design Toolbox 4.5," 2009.
Weber, "The USC-SIPI Image Database," University of South
Carolina Signal and Image Processing Institute (USC-SIPI),
1981.
Zuloaga, J. L. Martín, U. Bidarte, and J. A. Ezquerra, "VHDL
test bench for digital image processing systems using a new
image format."
Cyliax, "The FPGA Tour: Learning the ropes," in Circuit Cellar
online, 1999.
T. Johnston, K. T. Gribbon, and D. G. Bailey, "Implementing
Image Processing Algorithms on FPGAs," in Proceedings of the
Eleventh Electronics New Zealand Conference (ENZCon‟04),
Palmerston North, 2004, pp. 118 - 123.
EETimes, "PLDs/FPGAs," 2009.
Digilent, "http://www.digilentinc.com," 2009.
E. R. Davies, Machine Vision: Theory, Algorithms, Practicalities
3rd ed.: Morgan Kaufmann Publishers, 2005.
Xilinx, "XST User Guide ": http://www.xilinx.com, 2008.
23
Introduction
www.xilinx.com, "FPGA Design Flow Overview (ISE Help)." vol.
2008: Xilinx, 2005.
24
Chapter 2
Spatial Filter Hardware Architectures
Prior to the implementation of the various filters, it is
necessary to lay the groundwork for the design of spatial
filter hardware architectures in VHDL.
25
Linear Spatial filter architectures
Figure 2.1(ii) shows the line buffer array unit which consists
of long shift registers composed of several flip flops. Each
line buffer is set to the length of one row of the image.
Thus, for a 128 x 128 greyscale image with 8 bits per pixel,
each line buffer would be 128 wide and 8 bits deep.
27
Linear Spatial filter architectures
c0
×
c1
×
c2
× ∑ Data_out
c3
×
c4
×
c5
×
c6
×
c7
× ∑ Data_out
c8
×
c9
×
c10
×
Line Buffer FF FF FF FF FF
c11
×
Line Buffer FF FF FF FF FF
c12
× ∑ Data_out
Line Buffer FF FF FF FF FF
c13
×
Line Buffer FF FF FF FF FF
c14
×
c15
×
c16
×
c17
× ∑ Data_out
c18
×
c19
×
c20
×
c21
×
c22
× ∑ Data_out
c23
×
c24
×
30
Linear Spatial filter architectures
31
Linear Spatial filter architectures
33
Linear Spatial filter architectures
34
Linear Spatial filter architectures
Table 2.1.4 – MAC operations and filter kernel size and type
KEY
*/pixel – Multiplications per pixel
+/pixel – Additions per pixel
GFKA – Generic Filter Kernel Architecture
SFKA – Separable Filter Kernel Architecture
Sym FKA – Circular Symmetric Filter Kernel Architecture
Summary
In this section, we discussed several linear spatial filter
hardware architectures used for implementing algorithms in
FPGAs using VHDLs and analyzed the cost savings of
each architecture with regards to use of processing
elements in hardware.
35
Linear Spatial filter architectures
References
U. Nnolim, “FPGA Architectures for Logarithmic Colour Image
Processing”, Ph.D. thesis, University of Kent at Canterbury,
Canterbury-Kent, 2009.
Cyliax, "The FPGA Tour: Learning the ropes," in Circuit Cellar
online, 1999.
E. Nelson, "Implementation of Image Processing Algorithms on
FPGA Hardware," in Department of Electrical Engineering. vol.
Master of Science Nashville, TN: Vanderbilt University, 2000, p.
86.
T. Johnston, K. T. Gribbon, and D. G. Bailey, "Implementing
Image Processing Algorithms on FPGAs," in Proceedings of the
Eleventh Electronics New Zealand Conference (ENZCon‟04),
Palmerston North, 2004, pp. 118 - 123.
S. Saponara, L. Fanucci, S. Marsi, G. Ramponi, D. Kammler,
and E. M. Witte, "Application-Specific Instruction-Set Processor
for Retinex-Like Image and Video Processing," IEEE
Transactions on Circuits and Systems II: Express Briefs, vol.
54, pp. 596 - 600, July 2007.
EETimes, "PLDs/FPGAs," 2009.
Google, "Google Directory," in Manufacturers, 2009.
Digilent, "http://www.digilentinc.com," 2009.
E. R. Davies, Machine Vision: Theory, Algorithms, Practicalities
3rd ed.: Morgan Kaufmann Publishers, 2005.
Xilinx, "XST User Guide ": http://www.xilinx.com, 2008.
www.xilinx.com, "FPGA Design Flow Overview (ISE Help)." vol.
2008: Xilinx, 2005.
Mathworks, "Designing Linear Filters in the Frequency
Domain," in Image Processing Toolbox for use with MATLAB,
T. Mathworks, Ed.: The Mathworks, 2008.
Mathworks, "Filter Design Toolbox 4.5," 2009.
36
Chapter 3
Image Reconstruction
The four stages of image retrieval from camera sensor
acquisition to display device comprise of Demosaicking,
White/Colour Balancing, Gamma Correction and Histogram
Clipping. The process of interest in this chapter is the
demosaicking stage and the VHDL implementation of the
demosaicking algorithm will also be described. The steps of
colour image acquisition from the colour filter array are
shown in Figure 3.
B G B G B
G R G R G
B G B G B
G R G R G
38
Image Demosaicking
The equation for the basic linear interpolation demosaicking
algorithm is shown for one image channel of an RGB colour
image in (3.1-1 to 3.1-5).
(3.1-1)
(3.1-2)
(3.1-3)
Yielding
(3.1-4)
1+ (3.1-5)
and respectively.
39
Image Demosaicking
B channels modified for the G channel as will be explained
further in the following subsections.
R Convolution Redundant R
G Interpolatio Summation ’G’
B Demosaicking B
n
’
Figure 3.1(ii) – Image Demosaicking process
’
(a) (b)
Figure 3.1(iii) – (a) Original undersampled RGB image overlaid with
bayer colour filter array and (b) demosaicked image
40
Image Demosaicking
(a) (b)
Figure 3.1(iv) – (a) Original undersampled R,G and B channels (b)
Interpolated R, G and B channels
41
Image Demosaicking
The images in Figure 3.1(iv) show the gaps in the image
channel samples. The checkerboard pattern indicates the
loss of colours in between colour pixels by black
spaces/pixels in each channel.
(a) (b)
Figure 3.1v) – (a) Image with Bayer pattern (b) Demosaicked image
43
Image Demosaicking
enables users to accurately demosaick images using
software without restricting them to the camera‟s hardware.
R R’
G Demosaicking G’
B B’
Figure 3.2(i) –Black Box system top level description of demosaicking
Interpolation Stage 2
Rs Linear Rc
Spatial Filter2 s Σ R’
The block diagrams shown in the Figure 3.2(ii) and (iii) can
also be used for the B channel. For the G channel, only the
first stage of the interpolation is needed as shown in the
original algorithm equations. Thus, the system level
description for G is as shown in Figure 3.2(iv).
Interpolation Stage 1
Linear Gc
G Spatial Filter1 Σ G’
46
Image Demosaicking
complete circuit would look that shown in Figure 3.2(v).
Rs
Rs interp_filter_r2 R_prime
R interp_filter_r R
R1
Embedded
R Embedded R
MATLAB Function3
MATLAB Function Video
dc168_lenna_bayer.png
G G interp_filter_g G_prime
G
Viewer
B B
47
Image Demosaicking
multipliers. Building on the spatial filter architectures
discussed in Chapter 2, all that needs to be modified in the
filter architecture are the coefficients for the filter and the
divider settings. Skeleton VHDL codes, which can be
modified for this design can be found in the Appendices.
Figure 3.2(vi) – VHDL code snippet for specifying interpolation filter for
R channel
48
Image Demosaicking
top_clk dat_out
top_rst Interp_filter_r D_out_valid
dat_in
Figure 3.2(vii) – Visual system level description of the VHDL code
snippet for specifying interpolation filter for R channel
49
Image Demosaicking
(a) (b)
(c) (d)
Figure 3.2.1(ii) – Demosaicked R image channel from left to right
(software simulation) (a) original R channel, (b) filtered channel, Rc,
from first stage interpolation (c) filtered channel, Rcs, from second
stage interpolation (d) demosaicked image
50
Image Demosaicking
In Figure 3.2.1(ii), we can observe the intermediate
interpolation results of the spatial filter from left to right. Red
image is the original red channel, (R) of the image in Figure
3.2.1(i). Red1 image is the interpolated image from the first
stage or Rc from the diagram in Figure 3.1.2(i). Red2 image
is the second interpolated image (Rcs) from Figure 3.1.2(iii)
while (d) is the final demosaicked R channel, R‟.
51
Image Demosaicking
(a) (b)
Figure 3.2.1(iii) – Demosaicked images with (a) software simulation
and (b) hardware simulation: first row: R channel, second row: G
channel and third row: B channel
52
Image Demosaicking
(a) (b)
Figure 3.2.1(iv) – Demosaicked colour image: (a) software simulation
(b) hardware simulation
The next level of the top level system shows the major
components of the system for each of the R, G and B
channels.
55
Image Demosaicking
56
Image Demosaicking
Using this formula yields 1135 frames/sec, which is
exceedingly fast.
Summary
In this chapter, the demosaicking process using linear
interpolation was described and implemented in software
and followed by the VHDL implementation of the linear
interpolation algorithm for demosaicking.
References
W. K. Pratt, Digital Image Processing, 4 ed.: Wiley-Interscience,
2007.
Henrique S. etal, “HIGH-QUALITY LINEAR INTERPOLATION
FOR DEMOSAICING OF BAYER-PATTERNED COLOR
IMAGES”, Microsoft Research, One Microsoft Way, Redmond
WA 98052
Alexey Lukin and Denis Kubasov, “An Improved Demosaicing
Algorithm”,Faculty of Applied Mathematics and Computer
Science, State University of Moscow, Russia
Rémi Jean, “Demosaicing with The Bayer Pattern”, Department
of Computer Science, University of North Carolina.
Robert A. Maschal Jr., etal, “Review of Bayer Pattern Color
Filter Array (CFA) Demosaicing with New Quality Assessment
Algorithms”, ARMY RESEARCH LABORATORY,ARL-TR-5061,
January 2010.
Yang-Ki Cho, etal, “Two Stage Demosaicing Algorithm for Color
Filter Arrays”, International Journal of Future Generation
Communication and Networking, Vol. 3, No. 1, March, 2010.
57
Image Demosaicking
Rajeev Ramanath and Wesley E. Snyder, “Adaptive
demosaicking”, Journal of Electronic Imaging 12(4), 633–642
(October 2003).
Boris Ajdin, etal, “Demosaicing by Smoothing along 1D
Features”, MPI Informatik, Saarbr¨ucken, Germany.
Yizhen Huang,“Demosaicking Recognition with Applications in
Digital Photo Authentication based on a Quadratic Pixel
Correlation Model”, Shanghai Video Capture Team, ATI
Graphics Division, AMD Inc.
58
Chapter 4
Image Enhancement
This chapter explores some image enhancement concepts,
algorithms, their architectures and implementation in VHDL.
59
Image Enhancement
(4.1-1)
Offset
60
Image Enhancement
Figure 4.1.1(ii) show the results of using the design in
Figure 4.1.1(i) to enhance the original cameraman image
(top left) to produce the log-transformed image (top right)
and the double precision, floating point log-transformed
image (bottom left) while the error image (bottom right is
shown).
(a) (b)
Figure 4.1.2 – (a) Original image (b) Gamma Corrected image
(a) (b)
Figure 4.1.3(i) – (a) Histogram clipped image and (d) Gamma
Corrected image after Histogram Clipping
1 1 1 0 1 0
1 5 1
L1 = 1 9 1 and L2 = respectively.
1 1 1 0 1 0
64
Image Enhancement
4.2.2 Logarithmic local adaptive enhancement
This algorithm uses the logarithmic transform and local non-
linear statistics, (local image variance) to enhance the
image. The method is similar to a spatial filtering operation
in addition to using a logarithm transform. Figure 4.2.2
shows an image processed with the algorithm.
(a) (b)
Figure 4.2.2 – (a) Original image (b) Image processed with LLAE
65
Image Enhancement
4.3.1 Homomorphic filter
The operation of the Homomorphic filter is based on the
Illuminance/Reflectance image model and was developed
by Allan Oppenheim initially for filtering of audio signals and
has found numerous applications in digital image
processing. This filtering technique achieves enhancement
by improving the contrast and dynamic range compression
of the image scene. The process follows the scheme in
Figure 1.2 and the equation for the operation is given as
follows:
(4.3.1-1)
66
Image Enhancement
In implementing this, the main components are the
logarithm transformation components and the spatial
domain filter. By building each individual component
separately, debugging and testing becomes much easier.
Once more, we describe the top level system.
Thus, we have the RGB input and output ports in the top
level. Then the next level in Figure 4.4(ii) shows the inner
main components of the top level system.
Red(15:0) Red(15:0)
Red(7:0) 1
A1
1
a1 b1
5 1
A1
1
a1 b1
5 1
A1
1
a1 b1
5 1
A1
Red(7:0)
Green(15:0) Green(15:0)
Green(7:0) 1
A1
2
a2 b2
6 1
A1
2
a2 b2
6 1
A1
2
a2 b2
6 1
A1 Green(7:0)
3x3
LIN2LOG LOG2LIN
Blue(15:0) Spatial Filter Blue(15:0)
Blue(7:0) 1
A1
3
a3 b3
7 1
A1
3
a3 b3
7 1
A1
3
a3 b3
7 1
A1
Blue(7:0)
4 8 4 8 4 8
a4 b4 a4 b4 a4 b4
A1
1
A1
1 1
A1
1
A1
1
A1 Data_Valid
Clk 1
A1
1
A1
1
A1
A1
1
A1
1
67
Image Enhancement
FPGA. The hardware simulation image result is also shown
alongside the original image for comparison.
(a) (b)
Figure 4.4(iii) – (a) Original image (b) processed image with RGB
Homomorphic filter (hardware simulation)
Summary
We discussed several image enhancement algorithms and
implemented the more effective and popular ones in VHDL
and analysed the image results of implemented
architectures of the system.
References
U. Nnolim, “FPGA Architectures for Logarithmic Colour Image
Processing”, Ph.D. thesis, University of Kent at Canterbury,
Canterbury-Kent, 2009.
68
Image Enhancement
W. K. Pratt, Digital Image Processing, 4 ed.: Wiley-Interscience,
2007.
R. C. Gonzalez, R. E. Woods, and S. L. Eddins, Digital Image
Processing Using MATLAB: Prentice Hall, 2004.
R. C. Gonzalez and R. E. Woods, Digital Image Processing, 2
ed.: Prentice Hall, 2002.
MathWorks, "Image Processing Toolbox 6 User's Guide for use
with MATLAB," The Mathworks, 2008, pp. 285 - 288.
Weber, "The USC-SIPI Image Database," University of South
Carolina Signal and Image Processing Institute (USC-SIPI),
1981.
Zuloaga, J. L. Martín, U. Bidarte, and J. A. Ezquerra, "VHDL
test bench for digital image processing systems using a new
image format."
Xilinx, "XST User Guide ": http://www.xilinx.com, 2008..
G. Deng and L. W. Cahill, "Multiscale image enhancement
using the logarithmic image processing model," Electronics
Letters, vol. 29, pp. 803 - 804, 29 Apr 1993.
G. Deng, L. W. C., and G. R. Tobin, "The Study of Logarithmic
Image Processing Model and Its Application to Image
Enhancement," IEEE Transaction on Image Processing, vol. 4,
pp. 506-512, 1995.
S. E. Umbaugh, Computer Imaging: Digital Image Analysis and
Processing. Boca Raton, FL: CRC Press, Taylor & Francis
Group, 2005.
A. Oppenheim, R. W. Schafer, and T. G. Stockham, "Nonlinear
Filtering of Multiplied and Convolved Signals," Proceedings of
the IEEE, vol. 56, pp. 1264 - 1291, August 1968.
U. Nnolim and P. Lee, "Homomorphic Filtering of colour images
using a Spatial Filter Kernel in the HSI colour space," in IEEE
Instrumentation and Measurement Technology Conference
Proceedings, 2008, (IMTC 2008) Victoria, Vancouver Island,
Canada: IEEE, 2008, pp. 1738-1743.
F. T. Arslan and A. M. Grigoryan, "Fast Splitting alpha - Rooting
Method of Image Enhancement: Tensor Representation," IEEE
Transactions on Image Processing, vol. 15, pp. 3375 - 3384,
November 2006.
S. S. Agaian, K. Panetta, and A. M. Grigoryan, "Transform-
Based Image Enhancement Algorithms with Performance
Measure," IEEE Transactions on Image Processing, vol. 10, pp.
367 - 382, March 2001.
69
Chapter 5
Image Edge Detection and
Smoothing
This chapter deals with the VHDL implementation of image
edge detection and smoothing filter kernels using the
spatial filter architectures from Chapter 2.The original
greyscale images to be processed are shown in Figure 5.
All the filters are modular in their design, thus the RGB
colour versions are simply triplicate instantiations of the
greyscale filters.
70
Image Edge Detection and Smoothing
(a) (b)
(c) (d)
Figure 5.1.1 – Comparison between (a) & (b) VHDL-based hardware
simulation of Sobel filter (x and y direction) processed image and (c)
and (d) MATLAB-based software simulation of Sobel filter (x and y
direction)
0 1 0 1 0 1
2 0 2
P X = 1 5 1 , P Y =
0 1 0 1 0 1
72
Image Edge Detection and Smoothing
(a) (b)
Figure 5.1.2 – VHDL-based hardware simulation of (a) & (b) Prewitt
filter (x and y direction) processed image.
The image results for the edge filters and the high-pass are
in this form because most of the (negative) image pixel
values are outside the unsigned 8-bit integer display range
73
Image Edge Detection and Smoothing
The kernel for the default high-pass filter used is defined as;
1 1 1
HPF = 1 8 1
1 1 1
1 / 9 1 / 9 1 / 9
LPF= 1 / 9 1 / 9 1 / 9
1 / 9 1 / 9 1 / 9
75
Image Edge Detection and Smoothing
(a) (b)
Figure 5.2.2 – VHDL-based hardware simulation of (a) mean filter & (b)
Gaussian low-pass filtered images
76
Image Edge Detection and Smoothing
Summary
In this chapter, we introduced spatial filters used for edge
detection and smoothing and showed the VHDL
implementation of the algorithms compared with the
software versions.
References
U. Nnolim, “FPGA Architectures for Logarithmic Colour Image
Processing”, Ph.D. thesis, University of Kent at Canterbury,
Canterbury-Kent, 2009.
W. K. Pratt, Digital Image Processing, 4 ed.: Wiley-Interscience,
2007.
R. C. Gonzalez, R. E. Woods, and S. L. Eddins, Digital Image
Processing Using MATLAB: Prentice Hall, 2004.
R. C. Gonzalez and R. E. Woods, Digital Image Processing, 2
ed.: Prentice Hall, 2002.
Weber, "The USC-SIPI Image Database," University of South
Carolina Signal and Image Processing Institute (USC-SIPI),
1981.
77
Chapter 6
Colour Image Conversion
This chapter deals with the VHDL implementation of colour
space converters for colour image processing.
78
Colour Image Conversion
The CIELAB Colour space system was developed to be
independent of display devices and is one of the more
complete colour spaces since it approximates human
vision. Additionally, a lot of colours in the L*a*b* space
cannot be realized in the real world and so are termed
imaginary colours. This implies that this colour space
requires a lot of memory for accurate representation, thus
conversion to 24 bit RGB is a lossy process and will require
at least 48 bit RGB for good resolution.
(6.2-1)
, and (6.2-2)
(6.2-3)
(6.2-4)
(6.2-5)
(6.2-6)
(6.2-7)
(6.2-8)
80
Colour Image Conversion
(6.2-9)
(6.2-10)
(a) (b)
Figure 6.2(iii) –(a)CMY image (b) CMYK image (K not added)
81
Colour Image Conversion
The VHDL implementation of the CMYK converter is trivial
and is left as an exercise for the interested reader using the
design approach outlined for the more complex designs.
(6.3-1)
(6.3-2)
83
Colour Image Conversion
The detailed system is shown in Figure 6.3(iii).
84
Colour Image Conversion
(6.3-3)
85
Colour Image Conversion
values to fixed point representation in VHDL. The use of
fixed-point math is necessary since this system must be
feasible and synthesizable in hardware. The RTL level
system description generated from the synthesized VHDL
code is shown in Figure 6.3.
86
Colour Image Conversion
hardware simulation are shown and compared in Figure
6.3(viii).
(6.3-4)
(a) (b)
Figure 6.3(ix) – (a) Software and (b) VHDL hardware simulation results
of YIQ2RGB converter
R Y
G RGB to YCbCr Cb
converter
B Cr
(6.3-5)
88
Colour Image Conversion
The architecture is also similar except that there are
additional adders for the constant integer values.
89
Colour Image Conversion
RG B
I (6.4-1)
3
3 min R, G, B
S 1 (6.4-2)
RG B
91
Colour Image Conversion
if B G
H (6.4-3)
360 if B G
1
R G R B
cos 1 2 (6.4-4)
R G 2 R B G B
0.5
R
- ×
G +
| . |2 / cos-1(.)
- + √
- MUX
/
B
× 2π
2π
H
-
comparator 1
- S
×
3
+ / I
3
S V min( R, G, B) (6.4-6)
G B
S , for R V
BR (6.4-7)
H 2 , for G V
S
RG
4 S , for B V
2
- + MUX
/ H
B
/ 6
-
/
Max
- S
Min
v
Figure 6.4(iii) – Hardware architecture of RGB2HSV converter
94
Colour Image Conversion
The implementations of these non-linear colour converters
are quite involved and much more complicated than the
VHDL implementations of the other colour conversion
algorithms.
Summary
In this chapter, several types of colour space conversions
were investigated and implemented in VHDL for analysis.
The architectures show varying levels of complexity in the
implementation and can be combined with other
architectures to form a hardware image processing pipeline.
It should also be kept in mind that the architectures
developed here are not the most efficient or compact but
provide a basis for further investigation by the interested
reader.
References
W. K. Pratt, Digital Image Processing, 4 ed.: Wiley-Interscience,
2007.
R. C. Gonzalez, R. E. Woods, and S. L. Eddins, Digital Image
Processing Using MATLAB: Prentice Hall, 2004.
R. C. Gonzalez and R. E. Woods, Digital Image Processing, 2
ed.: Prentice Hall, 2002.
U. Nnolim, “FPGA Architectures for Logarithmic Colour Image
Processing”, Ph.D. thesis, University of Kent at Canterbury,
Canterbury-Kent, 2009.
MathWorks, "Image Processing Toolbox 6 User's Guide for use
with MATLAB," The Mathworks, 2008, pp. 285 - 288.
Weber, "The USC-SIPI Image Database," University of South
Carolina Signal and Image Processing Institute (USC-SIPI),
1981.
E. Welch, R. Moorhead, and J. K. Owens, "Image Processing
using the HSI Colour space," in IEEE Proceedings of
Southeastcon '91, Williamsburg, VA, USA, 1991, pp. 722-725.
T. Carron and P. Lambert, "Colour Edge Detector using jointly
Hue, Saturation and Intensity," in Proceedings of the IEEE
95
Colour Image Conversion
International Conference on Image Processing (ICIP-94),
Austin, TX, USA, 1994, pp. 977-981.
Andreadis, "A real-time color space converter for the
measurement of appearance," Journal of Pattern Recognition
vol. 34 pp. 1181-1187, 2001.
EETimes, "PLDs/FPGAs," 2009.
Xilinx, "XST User Guide ": http://www.xilinx.com, 2008.
96
APPENDIX A
Circuit Schematics
97
Appendix A
.
98
Appendix A
99
Appendix A
100
Appendix A
101
Appendix A
102
Appendix A
103
Appendix A
104
Appendix A
105
APPENDIX B
Creating Projects/Files in VHDL Environment
106
Appendix B
107
Appendix B
108
Appendix B
109
Appendix B
110
Appendix B
111
Appendix B
113
Appendix B
115
Appendix B
116
Appendix B
117
APPENDIX C
VHDL Code
Appendix C lists samples of relevant VHDL code sections.
118
Appendix C
example_file.vhd
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
----TOP SYSTEM LEVEL DESCRIPTION-----
entity example_file is
port ( ---the collection of all input and output
ports in top level
Clk : in std_logic; ---clock for
synchronization
rst : in std_logic; ---reset signals for new
data
input_port : in bit; ---input port
output_port : out bit); ---output port
end example_file;
---architecture and behaviour of TOP SYSTEM
LEVEL DESCRIPTION in more detail
architecture behaviour of example_file is
---list signals which connect input to output
ports here
---for example
signal intermediate_port : bit := '0'; --
initialize to zero
begin ---start
process(clk, rst) --process which is
triggered by clock or reset pin
begin
if rst = '0' then --reset all output ports
intermediate_port <= '0'; --initialize
output_port <= '0'; --initialize
elsif clk'event and clk = '1' then --operate
on rising edge of clock
intermediate_port <= not(input_port); -
-logical inverter
output_port <= intermediate_port or
input_port; --logical or operation
end if;
end process; --self-explanatory
end behaviour; --end of architectural behaviour
119
Appendix C
colour_converter_pkg.vhd
------------------------------------------------
------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
package colour_converter_pkg is
--Filter Coefficients---------------------------
--------------------------------------------
---NTSC CONVERSION COEFFICIENTS USING Y, I, Q
------------------------------------------------
------------------------------------------------
constant coeff0 : std_logic_vector(15 downto
0):= "0001001100100011"; -- 0.299
constant coeff1 : std_logic_vector(15 downto
0):= "0010010110010001"; -- 0.587
constant coeff2 : std_logic_vector(15 downto
0):= "0000011101001100"; -- 0.114
constant coeff3 : std_logic_vector(15 downto
0):= "0010011000100101"; -- 0.596
constant coeff4 : std_logic_vector(15 downto
0):= "1110111001110111"; -- -0.274
------------------------------------------------
constant coeff5 : std_logic_vector(15 downto
0):= "1110101101100100"; -- -0.322
constant coeff6 : std_logic_vector(15 downto
0):= "0000110110000001"; -- 0.211
constant coeff7 : std_logic_vector(15 downto
0):= "1101111010000111"; -- -0.523
constant coeff8 : std_logic_vector(15 downto
0):= "0001001111111000"; -- 0.312
----------------------------------------------
--End colour Coefficients-----------------------
------------------------------------------------
constant data_width : integer := 16;
end colour_converter_pkg;
------------------------------------------------
------------------------------------------------
----------------------------
120
Appendix C
colour_converter.vhd
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use work.colour_converter_pkg.all;
entity colour_converter is
generic (data_width: integer:=16);
port (
Clk : in std_logic;
rst : in std_logic;
R, G, B : in integer range 0 to 255;
X, Y, Z : out integer range -511 to 511;
Data_out_valid : out std_logic
);
end colour_converter;
begin
Data_out_valid <= '1';
x11 <= conv_std_logic_vector(R, 16);
x21 <= x11; x31 <= x21;
x12 <= conv_std_logic_vector(G, 16);
x22 <= x12; x32 <= x22;
x13 <= conv_std_logic_vector(B, 16);
x23 <= x13; x33 <= x23;
----multiplication------------------------------
-----------------------------------
m0 <= signed('0'&x11)*signed(coeff0);
m1 <= signed('0'&x12)*signed(coeff1);
m2 <= signed('0'&x13)*signed(coeff2);
m3 <= signed('0'&x21)*signed(coeff3);
121
Appendix C
m4 <= signed('0'&x22)*signed(coeff4);
m5 <= signed('0'&x23)*signed(coeff5);
m6 <= signed('0'&x31)*signed(coeff6);
m7 <= signed('0'&x32)*signed(coeff7);
m8 <= signed('0'&x33)*signed(coeff8);
----addition------------------------------------
-----------------------------
a10 <= (m0(32)&m0)+m1+m2;
a20 <= (m3(32)&m3)+m4+m5;
a30 <= (m6(32)&m6)+m7+m8;
----output--------------------------------------
---------------------------
Data_out_valid <= '1';
X <= conv_integer(a10(24 downto 14));
Y <= conv_integer(a20(24 downto 14));
Z <= conv_integer(a30(24 downto 14));
end struct;
122
Index
Index
124
Index
sRGB................................... 79 70, 71, 72, 73, 74, 76, 77,
Symmetric filter .................... 32 78, 82, 83, 85, 86, 87, 88,
textio.................................... 18 89, 90, 94, 95, 97, 106, 115,
tone ..................................... 59 116, 118
Unified Model Language (UML) weak edges .......................... 74
........................................ 19 window generator 26, 27, 29, 47
un-sharp masking ................ 64 Xilinx .... 6, 7, 14, 15, 16, 17, 18,
Unsharp masking ................. 64 23, 24, 36, 54, 56, 68, 69,
unsigned ........................ 54, 73 96, 97, 106
Variable Number Gradients .. 42 Xilinx Project Navigator . 14, 15,
Verilog ................................... 6 17
VHDL..... vi, 2, 6, 12, 13, 14, 16, YCbCr ............................ 82, 88
18, 19, 20, 21, 23, 25, 37, YIQ NTSC ............................ 82
44, 45, 48, 49, 54, 55, 56, YUV ..................................... 82
57, 59, 64, 66, 67, 68, 69,
125