Image Processing in C.pdf

(9430 KB) Pobierz
23353112 UNPDF
Image Processing in C
Second Edition
Dwayne Phillips
23353112.001.png
This rst edition of \Image Processing in C" (Copyright 1994, ISBN 0-13-
104548-2) was published by
R & D Publications
1601 West 23rd Street, Suite 200
Lawrence, Kansas 66046-0127
R & D Publications has since been purchased by Miller-Freeman, Inc. which
has been purchased by CMP Media, Inc. I recommend reading \The C/C++
Users Journal" now published by CMP Media, Inc. See http://www.cuj.com.
The Electronic Second Edition of this text is Copyright c 2000 by Dwayne
Phillips. Dwayne Phillips owns the electronic rights of this text. No part of
this text may be copied without the written permission of Dwayne Phillips.
If you have purchased the electronic edition of this text, you may print a
copy.
Electronic Edition 1.0, 26 April 2000
The Source Code listed in this text is available at
http://members.aol.com/dwaynephil/cips2edsrc.zip
Preface
This book is a tutorial on image processing. Each chapter explains basic
concepts with words and gures, shows image processing results with pho-
tographs, and implements the operations in C. Information herein comes
from articles published in The C/C++ Users Journal from 1990 through
1998 and from the rst edition of this book published in 1994. This second
(electronic) edition contains new material in every chapter.
The goals of the rst edition of this book were to (1) teach image pro-
cessing, (2) provide image processing tools, (3) provide an image processing
software system as a foundation for growth, and (4) make all of the above
available to anyone with a plain, garden variety PC.
These goals remain the same today, but much else has changed. The
update to this text reects many of these changes. The Internet exploded,
and this brought a limitless supply of free images to those of us who like to
process them. With these images have come inexpensive software packages
that display and print images as well as convert le formats.
The operating systems on home desktop and laptop computers have come
of age. These have brought at, virtual memory models so that it is easy
to pull entire image les into memory for processing. This permitted the
software revisions that are the basis of this second edition.
The software presented in this book will run on any computer using a
32-bit operating system (Windows 95, 98, NT and all avors of UNIX). I
compiled it using D.J. Delorie's port of the (free) GNU C compiler (DJGPP,
see www.delorie.com). It should compile ne using commercially available
C/C++ compilers. The software works on 8-bit, gray scale images in TIFF
and BMP le formats. Inexpensive programs are available to convert almost
any image into one of these formats.
Chapter 0 introduces the C Image Processing System. This chapter ties
together many of the concepts of the software and how to use it.
i
ii
Chapter 1 presents the image le input and output (I/O) routines used
by the image operators in the remainder of the text. These I/O routines
underwent major changes from the rst edition of this text. The changes in
the I/O code means chapter 1 is much longer in this edition and the remaining
chapters and their source code are shorter.
Chapter 2 describes showing image numbers on a screen and dumping
them to a text le for printing. I now leave image viewing and printing in
today's windows systems to other, inexpensive programs.
Chapter 3 describes the halftoning technique that transform a gray scale
image to a black and white image that looks like it has shades of gray. This
chapter also shows how to use this to print wall posters of images.
Chapter 4 delves into histograms and histogram equalization. Histogram
equalization allows you to correct for poor contrast in images. It presents
a program that creates a picture of an image's histogram. It also gives a
program that pastes images together.
Chapter 5 introduces edge detection | a basic operation in image pro-
cessing.
Chapter 6 explains advanced edge detection techniques. We will use these
techniques later in the book for segmentation.
Chapter 7 addresses spatial frequency ltering. It shows how to use var-
ious high-pass and low-pass lters to enhance images by removing noise and
sharpening edges.
Chapter 8 considers sundry image operations. It demonstrates how to
add and subtract images and cut and paste parts of images.
Chapter 9 introduces image segmentation. Segmentation is an attempt to
divide the image into parts representing real objects in the image. Chapter
9 shows how to use simple histogram based segmentation.
Chapter 10 continues image segmentation with several advanced tech-
niques. It discusses using edges, gray shades, and complex region growing
algorithms.
Chapter 11 demonstrates morphological ltering or manipulating shapes.
It describes erosion, dilation, outlining, opening, closing, thinning, and me-
dial axis transforms.
Chapter 12 discusses Boolean operations and image overlaying. It shows
how to use Boolean algebra to place a label on an image and how to overlay
images for a double exposure eect.
Chapter 13 describes how to alter the geometry of images by displace-
ment, scaling, rotation, and cross products. It provides a utility I often use
iii
that stretches and compresses images.
Chapter 14 presents image warping and morphing. Warping is a 1960s
technique that Hollywood embraced in the early 1990s. It leads to morphing.
Chapter 15 looks at textures and texture operators. Texture is hard to
explain and harder to classify with computers. Nevertheless, there are a few
ways to work this problem.
Chapter 16 explains stereograms. These dot-lled images contain 3-D
objects if viewed correctly. Stereograms ooded the market in the early
1990s. The theory and techniques are simple and easy to use.
Chapter 17 examines steganography | the ability to hide information in
images. Steganography exploits the unnecessary resolution of gray in images.
Chapter 18 shows how to write DOS .bat programs to use the programs
of the C Image Processing System.
Chapter 19 shows the Windows interface I created for the C Image Pro-
cessing System. I used the tcl/tk language and the Visual Tcl tool to create
this. The tcl/tk scripting language is perfect for gluing together a set of
programs like the image processing ones in this book.
The appendices provide information on the programming aspects of this
book. They discuss the makele for the programs (appendix A) and the
stand alone application programs in CIPS (appendix B). Appendix C lists
the individual functions and the source code les containing them. Appendix
D gives all the image processing algorithms and the chapters in which they
appear. Appendix E is a bibliography enumerating the books that have been
of great help to me.
Appendix F contains all the source code listings. I struggled with putting
the listings in each chapter or all together at the end of thebook. I chose
the end as that makes it easier to print the text without lots of source code
listings. You may download a copy of the source code from
http://members.aol.com/dwaynephil/cips2edsrc.zip
Have fun with this. I had fun updating the software and the descriptions.
Thanks to the Internet (lots of free images) and newer operating systems
(32-bit), image processing is more fun than ever before. Everyone is doing
image processing today. Use the tools and techniques described here to join
in. Every technique brings with it ideas for other things to do. So much fun
and so little time.
Many thanks to the sta of The C/C++ Users Journal and Miller-
Freeman past and present. In particular I want to thank Howard Hyten,
Diane Thomas, Martha Masinton, Bernie Williams, P.J. Plauger, and Robert
Zgłoś jeśli naruszono regulamin