practical algos for image analysis

download practical algos for image analysis

of 299

Transcript of practical algos for image analysis

  • 8/7/2019 practical algos for image analysis

    1/299

    Practical Algorithl11sfor Imaqe AnalysisDESCRIPTION, EXAMPLES, AND CODE

    Michael Seul Lawrence O'Gorman Michael J. SammonBioArray Solutions, LLC Veridicom, Inc. Lucent TechnologiesPiscataway, New Jersey Chatham, New Jersey Liberty Corner, New Jersey

    '''''~'''''AMBRIDGE::: UNIVERSITY PRESS

  • 8/7/2019 practical algos for image analysis

    2/299

    PUBLISHED BY THE PRESS SYNDICATE OF THE UNIVERSITY OF CAMBRIDGEThe Pitt Building, Trumpington Street, Cambridge, United KingdomCAMBRIDGE UNIVERSITY PRESSThe Edinburgh Bui lding, Cambr idge CB2 2RU, UK http://www.cup.cam.ac.uk40 West 20th Street , New York, NY 10011-4211, USA http://www.cup.org10 Stamford Road, Oakleigh, Melbourne 3166, AustraliaRuiz de Alarc6n 13,28014 Madrid, Spain Cambridge University Press 2000, except computer programs,which are copyright by MLM SoftwareGroupThis book is in copyright. Subject to statutory exceptionand to the provisions of relevant collective licensing agreements,no reproduction of any part may take place wi thoutthe written permission of Cambridge University Press.First published 2000Printed in the United States of AmericaTypeface Times Roman 10.5/13 pt. System L,\TEX2E [ru]A catalog record for this book is avai lable fromthe British Library.Library of Congress Cataloging-in-Publication DataSeul, Michael.

    Practical algorithms for image analysis: description, examples,and code / Michael Seul, Lawrence O'Gonnan, Michael J. Sammon.

    p. cm.I. Image processing - Digital techniques. 2. Algorithms. 3. Image

    analysis - Data processing. 1. O'Gonnan, Lawrence. I I. Sammon,Michael J. Ill. Title.TA1637.S38 1999621.36/7 - dc21 98-18762

    CIPISBN 0 521 66065 3 hardback

    http://www.cup.cam.ac.uk/http://www.cup.org/http://www.cup.org/http://www.cup.cam.ac.uk/
  • 8/7/2019 practical algos for image analysis

    3/299

    Contents

    .~ Introduction page 11 . 1 Introduction 11 . 2 Annotated Section Overview 5l . 3 A Guided Tour 1 4

    l Global Image Analysis 2 12 . 1 Intensity Histogram: Global Features 2 32 . 2 Histogram Transformations: Global Enhancement 2 72 . 3 Combining Images 3 72 . 4 Geometric Image Transformations 4 32 . 5 Color Image Transformations 5 1

    3 Gray-Scale Image Analysis 5 63 . 1 Local Image Operations: Convolution 5 93 . 2 Noise Reduction 6 83 . 3 Edge Enhancement and Flat Fielding 7 53 . 4 Edge and Peak Point Detection 8 03 . 5 Advanced Edge Detection 9 03 . 6 Subsampling 9 73 . 7 Multiresolution Analysis 1 0 13 . 8 Template Matching 1 0 63 . 9 Binarization 1 1 0

    " Binary Image Analysis 1 1 8'* 4 . 1 Morphological and Cellular Processing 1 2 14 . 2 Binary Noise Removal 1 2 94 . 3 Region Detection 1 3 24 . 4 Shape Analysis: Geometrical Features and Moments 1 4 44 . 5 Advanced Shape Analysis: Fourier Descriptors 1 5 24 . 6 Convex Hull of Polygons 1 5 64 . 7 Thinning 1 6 04 . 8 Linewidth Determination 1 6 44 . 9 Global Features and Image Profiles 1 6 74 . 1 0 Hough Transform 1 7 2

    v

  • 8/7/2019 practical algos for image analysis

    4/299

    vi Contents

    Analysis of Lines and Line Patterns5.1 Chain Coding5.2 Line Features and Noise Reduction5.3 Polygonalization5.4 Critical Point Detection5.5 Straight-Line Fitting5.6 Cubic Spline Fitting5.7 Morphology and Topology of Line PatternsAnalysis of Point Patterns6.1 The Voronoi Diagram of Point Patterns6.2 Spatial Statistics of Point Patterns: Distribution Functions6.3 Topology and Geometry of Cellular Patterns6.4 The k-Nearest-Neighbor Ck-NN) ProblemFrequency Domain Analysis7.1 The 2D Discrete Fourier Transform7.2 Frequency Domain Filtering

    176178184191197201206210221222228235241246248265

    ~.~~Ll\!l)t\!\: Synopsis of Important Concepts 273Al The Fourier Transform: Spatial Domain Versus Frequency Domain 274A2 Linear Systems: Impulse Response, Convolution, and Transfer Function 278A3 Special-Purpose Filters 283A4 The Whittaker-Shannon Sampling Theorem 285A5 Commonly Used Data Structures 288

    295ndex

  • 8/7/2019 practical algos for image analysis

    5/299

    Introduction

    1.1 IntroductionIn this book, we offer guided access to a collection of algorithms for the digital manipu-lation of images. Our goal is to facilitate the solution of practical problems, addressingusers whose interest is in an informed how-to approach, whether in a technical or ina casual setting. Rather than attempting to be exhaustive, we address salient practicalconsiderations, guiding the selection of a particular approach to commonly encounteredimage processing and analysis tasks, and we present animplementation of our choice ofthe most suitable procedures. This selection of "Practical Algorithms" reflects our ownexperience as long-time users and developers of algorithms and software implemen-tations to process and analyze images in areas as diverse as magnetic domain patternformation and document analysis.

    HOW TO USE THIS BOOKOrganization of Chapters and SectionsThis book contains seven chapters and an appendix. Following this introduction, in

    Section 1.2, an annotated section overview is presented, and, in Section 1.3, a guide tothe use of the book and the accompanying collection of algorithms are given. Chapters2-7 present the material of the book in self-contained sections of identical format. Theappendix serves as a review of fundamental concepts to which we refer throughout thetext and provides reference material to the technical literature.

    Each section contains a header that illustrates the nature of the topic of interest bydescribing typical applications, identifying key words, and providing cross referencesto related topics treated in other sections. Next, the topic of interest is introduced bya description of typical situations requiring a particular processing step or analyticaloperation; the effect ofthe operation is illustrated by apictorial example that comprises apair ofbefore and after images. Possible strategies of implementation are then discussed,and a particular approach is selected for implementation. Annotated references providean introduction to further technical literature. Appended to each section is a display ofprogram usage for the code introduced in the section.Single-Step ProceduresEach section treats a single primary operation (histogram evaluation, low-pass fil-

    tering, edge detection, region detection, etc.) and introduces requisite algorithms. Each1

  • 8/7/2019 practical algos for image analysis

    6/299

    2 Introduction

    of the algorithms performs a single transformation on a given input image Cinimg") toproduce a modified output image Coutimg") and, in some cases, output data. Sectionsare self-contained to enable and encourage random access to the most suitable single-step procedure that solves the particular task of interest. Thus a reader interested in anexposition of simple edge detection techniques would open the book to Section 3.4,while a reader interested in the methodology of Fourier filtering would proceed directlyto Section 7.2.Multistep ProceduresThe analysis of images usually requires the successive application ofmultiple trans-

    formations. These may include simple preprocessing steps (noise removal, flat fielding,feature detection), followed by more complex analytical steps (object shape analysis,line pattern analysis, and point pattern analysis). Multiple individual transformationsmust be concatenated into multistep procedures.

    To facilitate the flexible design of multistep procedures, sections are grouped intochapters that bundle common types of analyses (global, local, frequency domain) andcommon types of operations according to the images (gray scale, binary) or classesof patterns within images (lines, points) to which they are applied. Each section pro-vides extensive cross references to enable a reader to construct a logical flow of relatedoperations.

    Chapters reflect the order in which procedures are ordinarily applied to any givenimage. For example, histogram analysis will precede binarization: filtering and/or flatfieldingwill precede object shape analysis, line coding will precede line pattern analysis,andVoronoi analysis will precede statistical analysis of point patterns. Spatial frequencyanalysis combines several operations in an alternative approach to the analysis of imagesin the spatial domain, and we choose to present it last. Within chapters, the order ofsections reflects increasing levels of task complexity. This organization suggests anoverall progression from simple and general to complex and specific tasks.CodeThe book is accompanied by a collection of C programs implementing the algo-

    rithms we discuss. All programs operate on existing images; the acquisition of imagesis not discussed here. Versions for two platforms are supplied, as shown below.Code Platforms

    PLATFORM C COMPILERMicroSoft DOS (under Windows95)LlNUX kernel v. 2.0.0

    MicroSoft Visual C++, v. 4.0GNU gcc, v. 2.7.2

    Code OrganizationSource code is organized in a directory structure such that modules required for

    building a particular program reside in a subdirectory corresponding to the book sectionin which the program is first invoked. For example, xconv would be stored in a

  • 8/7/2019 practical algos for image analysis

    7/299

    1.1 Introduction 3

    subdirectory referring to Section 3.1. Corresponding LINUX Makefi1es and VisualC++ Workspaces are provided to generate executab1es. Details relating to programcompilation and installation are described in a README.TXT file contained on thecode distribution disk. In some chapters, additional utilities are provided in a separatesubdirectory to generate test images or to analyze output data files.

    In addition, we provide three libraries: LIB TIFF, containing functions to handle input and output of image files in anuncompressed TaggedImage File (TIF) format; LIBTIFF 3.4, written by SamLefflerand made available by Silicon Graphics, Inc., was modified to remove support forLZW compression;

    LIBIMAGE, containing get opt (), a command line parser, aswell as a collectionof higher-level graphics functions to handle drawing, filling, and character gen-eration; portions of LlBIMAGE invoke gd 1.2, written by Tom Boutell and madeavailable by Quest Protein Database Center, Cold Spring Harbor Labs;

    LIBIP, containing image analysis functions such as poly_moments () andfind_area_hist () to handle common analytical tasks invoked by multiple pro-grams.All programs are executed from the command line from which a variety of argu-

    ments and options can be supplied to adjust and optimize program performance. Someprograms prompt for additional input during run time. When executed without ar-guments, each program displays the command with arguments and options definingprogram usage. This usage header also is reproduced at the end of each section forprograms introduced in that section.

    NoticesThis source code is distributed under a limited-use license that one may view byinvoking an appropriate option on the command line of each program. Unless otherwiseindicated in the source code, copyright is jointly held by the authors, as indicated bya copyright notice such as Copyright (C) 1997, 1998, 1999, M. Seul, L. O'Gorman,M. J. Sammon. In some instances, we use a third-party code in versions available frompublic sources. In those instances, the original authors, as identified in the source code,retain copyright.

    Except when otherwise stated in writing, the copyright holders and/or other partiesprovide each program as is without any warranty of any kind, either expressed orimplied, including, but not limited to, the implied warranties of merchantability andfitness for particular purpose. The entire risk as to the quality and performance of theprograms is with the user. Should the program prove defective, the user assumes thecost of all necessary servicing, repair, or correction.

    In no event shall any copyright holder be liable for damages including any direct,indirect, general, special, incidental, or consequential damages arising out of the useor inability to use the programs (including, but not limited to, loss of use or data, databeing rendered inaccurate, losses sustained by the user or third parties, or a failure

  • 8/7/2019 practical algos for image analysis

    8/299

    4 Introduction

    of the programs to operate with any other programs), however caused, and under anytheory of liability, whether in contract, strict liability, or tort.

    AcknowledgmentsWe would like to thank those individuals, most notably our editor, Lauren Cowles,

    who have contributed to this book. This publication includes images from Corel StockPhoto Library, which are protected by the copyright laws of the United States, Canada,and elsewhere and are used under license. Images and other printed materials havebeen reproduced with permission from the following sources, listed in the order of firstappearance and further identified in the referenced sections: [O'Gorman et al 85] -Figs. 2.1.1, 2.2.2, 2.2.5, 5.2.4, 5.3.1, 5.6.1; [CSPL - Corel Stock Photo Library/CorelGroup] - Figs. 2.2.1, 2.2.6, 2.5.1, 3.6.1, 3.7.1, 4.9.2, 5.5.1, 7.1.6, 7.1.7; [Morgan andSeul 95] - Figs. 2.3.1, 3.3.1; [Woodward and Zasadzinski 96] - Fig. 2.4.1; [The BellLabs Technical Journal] - Fig. 2.4.6; [Costello] - Figs. 3.1.1 B, 7.1.1; [Gonzalez andWoods 92] - Figs. 3.1.3, 3.1.4, 3.4.2; [Lucent Technologies - Bell Laboratories PhysicalSciences Image Library] - Figs. 3.2.1, 3.2.4, 4.3.1; [Seul et al 92] - Figs. 3.3.2, 5.3.2,5.7.2-5; [Canny 86] - Fig. 3.5.2; [Boie et al 86] - Figs. 3.5.3, 3.5.4; [Seul et al 91]-Figs. 4.3.2, 4.3.3, 4.5.2, 4.5.3; [Attneave 54] - Fig. 5.4.2; [Seul andWolfe 92B] - Fig.5.7.1; [Seul and Wolfe 92A] - Fig. 5.7.6; [Preparata and Shamos 85] - Figs. 6.1.2.,6.1.4; [Ashcroft and Mermin 76] - Fig. 6.1.2; [Fortune 87] - Fig. 6.1.5; [Sire and Seul95] - Figs. 6.3.1-3, 6.4.1; [Seul and Chen 93] - Fig. 7.1.8; [Goodman 68] - Figs. 7.2.1,A.3; [Bracewell 86] - Figs. A.l, A.2; [Sessions 89] - Fig. A.4; [Kruse et al 91] -Fig. A.5.

  • 8/7/2019 practical algos for image analysis

    9/299

    ~Q). s :. .Q)>oc.2. . . .C JQ)e n" C IQ). . . .

    c a. . . .occ< CN

    cot: : : : J"Co. . .. . . .e. . .. . .Q). . . .e,(II. . r : : :o

    ~e nc,oZ> -e n

    '"0ou"0@

    w_Jf-f=zof=uue n

    en.:o.~'",o

    (II.QoaN. . .Q)'E .(II. . r : : :o

    (IJu0 ::of-ou~_Jurr:

    e norr:oS> -u~

    zo~u: : : : ;n,n,_Ju0 ::~

    u_Jf-f=zof=uue n

    .~oo

    5

  • 8/7/2019 practical algos for image analysis

    10/299

    6

    (fJu0 ::of-DLlJ~--'LlJa: :

    (fJDa: :oS> -LlJ~

    zo~u: : : : ;n,n,

  • 8/7/2019 practical algos for image analysis

    11/299

    i~ c;j ~ ~) b O JJ 0) :1 \O JJ ~ ~ - . ~ 8 '" '" "0 ~ 2 ~ ~ () ~ ~ 00 s .~ .~ , . . . . , ~ :E ~ ~ !10) 0 e - o 0 ~N ~ 0) 0 '" " 0 g0 .g en .p 0 g 0) ~ O JJ '"d '" '" : : t B .2~ 0) .~ () ::i t:, 0 0) .S ~ >-. > -. O JJ .~ ~) c, ::i ~ c;j c;j B ~"0 '0 u B E s s en E~ b '"d 0) ~ O JJ 0 0 0 0 '" ~~ 0 '" 1 :l ..c 0) '" , . ) : : : : O JJ 0) 0 0 0 '" " 0) :E '" ' 0~ B 0) en ..c () '" ' 0) 0 ::i o :E ~ ~2 '"d .~ 2 B Ii..c ~ O JJ " B 0) '" ' . > : : : '"d ~ 0) 0) 0) ~~ ~ - . 'i3., s: ~~ 0 ~ "a t: 0'" ' en 0 '" " E bh ~E 1l .,p ~ ~ >- . 00) ::i 0 0 ~ c, s o ~.: l i = 1 O JJ "0 '" ~ 0 '" ci0) ~ en ~'" ' . 8 '" () 0 0 0 o.p 0) 0) 0 0 g .,p ~ '" " .. 9 ~) ~ '" " ~ '" ' ::i c ()s 0) ~ .: c, '0 "0 1 :l ~ ~ c;j ~~ 0)0) .S 0 0) '" '" l2 : .S 0 ~ I"d .,p () 0) 0) :al ~ '" ' '" " ~"a .: () en c, .p ~ '"d o "0 1 :l1 :l ::i ::i en 0)E '"d ;0' d ., '3 ..c C i : i ~ 0 ~2 : en 0) E S () S en 0.p s: '" " ~ "a C i : i 0) oc, '" " i:i o E - Ben en ~~)0) 0) ~'" " ~ ~: ::i ~B C i : i i$ 0) s0) ~ 0 S B ~- B '" ~ 00) '" " . . : . : 0 0) !' !.S O JJ 0 4- .~ c;j li~ . . . . II. 8 () 0 > ()~ 0) 0) en 0 '" ~en B tl 0) > - ..~ 0 4- >- . ~ ~0 0) '" "~ en 0)~ 4- 0 B 0 B 0 O JJ O JJ ~0 B 0 4- ~) 5 0 0 . 8 ~E 0) "0 ~ 4- ~tl 0 s 0 .S 0O JJ ::i B .3) ~ "0 0) ~ 0) >- . ~n 0) 0) 0) '"d 0 '" '" ") '" '" " B s tl .p " '" " ~ i>) 0) 0O JJ '" ' 0) ::i 0) () ~ > :E ~c, c;j '" '"d 0) s '" 0. o B 0) 0 . .en 0 '"d () i~~

    O JJ r1~ ~0) ~ :E ~O JJ 0 ~ ~"d O JJ 0 g 0'-'l 0 2:@ : '0 0 i"d 0 s .p0) 0 '" .~ ~() .,p 0) '" ~ N~ () ~ '" ' >- . 'i3., . > : : :~ 1 :l '" ~ "a E ~. 6 s: 0 ~0) ::i 2: ~ ~ ~Q so

  • 8/7/2019 practical algos for image analysis

    12/299

    8

    . . .C II'5 .CQJ:U

    CflUc : :of-owSwa:;;;bJlo'0

    e -oECfloa:oS> -w~

    zo~::Jc,c,_J

    C Sc : :> -f-

    u_Jf-f=zo~wCfl

    3~oo

  • 8/7/2019 practical algos for image analysis

    13/299

    0' 0) '" ~c, 0)oj ~f) ..c Cb i J en c;j ~~ E ~~ ~ IB .9 0) '" 't ; : : : : ~ en 8 ' 6 ~ ~ '") 0) ~ en 0) ..c ~ ~, c : ~ S ~ '" ojoj ~ ~ en _, 0' b ~.c : : t '6 t:, 0' '" '" "a ~en 6 ~ 0) '" el i c, ~0) '" " ~ . : ; < 0) c ~ l!c, 0) 0 oj ~ '" O JJ 0 0 i" c () c;j 'S ~ 0) oj ~:: ; 0 '" ' .. 0 ' ' " ~ ~ E'6 : B .an '" - = = 0) ' " .S en .;i 0 S ; : : ; ~ @"a "0 b E '" ~'" c, ~ '" "a 0) ~ b ~ 0) 0) ci ~ E ~a 8 ' 0 0 o t ; : : : : ..c) .p ~) ] S o 0 0 O JJc, @ 0) ..c 0) en E '" 'b en '" ' " E c, ; : : ;oj J ; l O JJ 0 if..c x ; : : ; ~ ~n 0) en oj en ~

    i : i ' 4- ;"0 4- 0 ..c0 - B 0 () ;l0) ~ .5fj '" '" " en "n 0 .~ O JJ ~ 4- ~ 0) ; : : ; 0) !\j 0) . S ~ ' " 0 0 en '" O JJ e: '" " '" " 0 .~ - B '" en oj0 0) O JJ 0 0) ~ ~ B ~ 0) .S c;j ; 0 ~j 8 ' .p .~ O 0 0) 8 ', 0) ~ '0 oj .~ ~ oj Ij @ 0 ..c N ' " 0) ..c ..c O JJ '" '" c, S E g en '"n ~ O JJ E () '" 0 ~.. . oj .S oj oj 0) '" "l () '" " -0 4- 2 0 . '" ' 4- tl en 0) ~~

    0) 4- .5fj 0 - B) ; : : ; c, 0 0 0 0) en en 0) 0)B B 0 c, '" ] 0) '" ' ; : : ; .S .~ B ~ 0 .S0 E 4- ~ '" ' ; : : ; @ 0 ~ il0 0 0 4- 0) "0 2 0) '" 0 4- O JJ '" ' s: - O JJ ~6 ; : : ; ~ ~ 0) E 0 ; : : ;0 -0 :E ~ 0) "0 00 : . : : l G ~ I:< '" - u 0... E -< c oj ~ ~0 ~r) \D r- oo 0\ _, ~., f .., f .., f ..,f .., f .., f

    9

  • 8/7/2019 practical algos for image analysis

    14/299

    CflUc ::of-oL J . J! ;(_JL J . Ja: :

    Cfloa: :oS> -L J . J> < : :

    tilc. . .Q):: :ctIe,Q)c::i"'CcctItilQ)e::i'0til'iii~ctIeL I ' i

    zo~::Ja,c,_Juc ::~

    L J . J_Jf-f=zof=uL J . JCfl

    . ..Q)actI. . r : : :o

    10

  • 8/7/2019 practical algos for image analysis

    15/299

    '"au" . : : ;"Co

    '")>3u'Hoo o .D0 .g coS 3" : ; < 0o ~ u

    11

  • 8/7/2019 practical algos for image analysis

    16/299

    i~ .~ ~:1 \'" Ia bJ j > -0) ~ c;jE 'S ~ - ~ '" 0 0 o oj ~J.J oj C/ O 0 0)> < : : 'P., ;a u ~ ~s~!' !liII

    4- 0) "@ c;j C/ O 8 '0 C/ O C) ~0 '" "0 '0 u 0) C/ O C/ O 0 0 ~ ~ ~0) s 'K '" > - '" 0'" s: 0) 0) '" 0) ~o S '" " "0 oj u . . . , ~ C/ O "@ = : ~ .~0 '0 0) c;j ~ 0) E ;a0) C/ O C/ O .~ ~ s: E ~ ' 0 ;j oj ~oj u : :: ~ bJl ~ E oj ~ bJl ~"0 4- U 0 C/ O 0 E en c, t ; : : : : "@ '"..c oj 0 .S oj I "0 'D ;a ;j '0 v; ~ ;0- oj .Sz c, o vi' $l '" .S c;j ~ ;j ~ C i : i ~ '2 ~ 0) 0) C/ O '" ~0 . . . , ;j S C/ O ~ oj '" " c, 0) en u ojoj '" v . . . , .;:l s: 'c; j ~ . . . , . . . , 0 0) ;0- ~ 'D 0) i>~ ~ 0) 0) C/ O C/ O " B 0 C/ O ' 0 0 oj en C/ O '" " ~~ o ~ c, ~ '" 4- oj ~ ~i' t 3 c, . . . , . . . , .~ oj ~ '" " C/ O '" " >- C/ O .~ 0 '3 oj oj :Q .S'P., 4- 0 ;j 0) ..c ;a '" " 0) 0 V; . .C/ O tl C/ O . a ~ 0) ~ ~ 4- U i:J o 0 vi' c, 0) o . . . , '" 4-4- .~ vi' oj '" " 4- ~ . . . , 0 E oj 0.. 0 C/ O 0) 0) . e c, 4- 0 0 '" en u "@ ~ '" bJl tJ ~0.. 0) "3 u 0 C/ O ~ 0 0) 4- ~ . . . , u C/ O '" " ~ ' " " "I ~ c, bJl , . ; : : '" ~ 0 S ~ 0 '0 0 0 S ~ ;j 0) E 0 ~oj u 0) '8 0 0 '2 uu > - 0 'D u 0) ~j u ' 0 .~ -0 '" ..c .~ '" ~ '0 C/ O 'D '0 c, ~ 'D 0 . . . , c, ~ '0. . . . 0) .S S 8 c, 0 > - ;j c 8 ~ '" C/ O 4- > - o f .5 oj 4- c 8 . e r1. . . c : : C/ O c, C/ O "0 ;0- C/ O c;j oj oj .~ c, 0 "0 c, 0CI I > - '" ;0- oj ~l. f- E 0) '" c,. . . . ~!: ~0Il. i. . .0VI' iii = : '" Vi C/ O Z~

    ~ ' 0 o E E;:J , ; ; ; :II 0... 0) "0 0) . . . ,'" 4- '": '0 4- 'D tl ~ @ 0 ~ 0) ~< t ~ 0 ~ oj 0 . . . , ~J.J 0... '" > - 0... oj . . . ,....J 0 E C/l ';:J ~ >- . . . , 0)c D f- . . . , C/ O = : ;j 0 bJl C) . . . , z 0 E ilif= ~ oj ~ c;j s: " B 0 oj s: 0) ~.. , '" " ' 0 " B -0 E E . . : : : ..c e f. . en 0) '. g en :: 0j z 0) oj tl 0... C/ O ~ p., 0 0) 0) '0 3 0 ~. . . 0 ..c Q oj p., 4- is ;j ~ 0) ..c . . . ,Q. f= E- o . . . C/l 0 ~ 0 U E- Z 0... ~II UJ: L J . J (1 (") " '" ~Cfl 0 0 0 0

    12

  • 8/7/2019 practical algos for image analysis

    17/299

    ~ ~~ ~n o8 0 ; : : ; .~ o n u 0 0 'oj E Zl !i'" - 5 u en U Z . . . . 0 E oj E ro) oj 0 ~ c, U en) < l : : ~l en U 'en c, C)'" " C) ~ ; : : ; I ~) E C) uc 2 > c, '5 b b1 l C) ~: : en ; : : ;en . . . . E b1 l :E < l : : IC) oj i : i : : 1 . . . .~ i$ 'R ~-. o n 1lJ 0 oj en 0 ~'" " '" - c, E bi ) oj :: ; t ; : : :C) e .S c, o ..c M ~c ~ ~ ~ p :, t ~ ~(J) ; : : ; E 0 en 0 ~ '0:; (1 j0 .~ 0 oj .3 ,9 ~ I'" " 0 g ~ i$ Err: '" - c 2 en0) b iJ .- d . . . . ~ 00 ~ en '0 ;; ~ cS 0 . . . . 0 0 Iioj . . . . en .~ c ; : : ; ~ ~'" " 0 C) oj > - o tJ u . . . . en 1l .D c o ~ u ~lJ en ~~ : . a ~ Ii ! C)~ ; : : ; ~I ~ 0E en u, 0 ~~ E ~ '0 5 ~C) ~~ ~ oj 0c, ~ ; : : ;"a c, ~ I '0:; '" - ID ~ 0 '" "0 'p E ~ ~lJ B C) l 0 en. . . . I c 0 oj 8 ~ oj I.D , , : : K C) oj ~- 2 :l E: . a r\ .~0 en ~ '0'p 4- ~ C) c, '2 0 0 en o:~ 0 B ~ ~ ~n . . . . ~z 0 0 0 s C) 00 o 'p 0 .g s 'oj ~ e n C) 'pC) oj C) . . . . ~ ; : : ;~ . . . . ; : : ; "0 '0 c, e, "0 E'0 "a > C) ~ ~ Q) C) C)e n u 5) 0 en CJ .D > . . . . ~iii : : : : ; 0 '0 0 ~ I: ~ 0 0~ u .~ 0 0 C)~ n, ;; C) ~ 0 U ..c ~:n, 0 bi) 0 0 E-ctI .~ . . . . bi) : : : I () !i l 8 . . . . o SI: 0 ~ C) . . . . C) b1 l ~-' : : : K c > en

  • 8/7/2019 practical algos for image analysis

    18/299

    14 Introduction

    1.3 A Guided TourPrograms in each section implementing single transformations are self-contained toenable the concatenation of multiple single-step operations. As illustrated in the GuidedTour below, readers are encouraged to compose their own sequences of operations,stepping from section to section by following cross references and proceeding in thegeneral direction from lower to higher chapters.

    Applied to the original image, the set of operations listed below produces the series ofimages shown in this section. We describe each step in turn with reference to specificsections in the book and reproduce a corresponding command line (with comments).

    Original The starting point for our tour is a raw image in the form of a micrographdepicting a set of small, roughly circular dark domains embedded in abright background(Fig. l.3.l). These domain patterns form in certain organic films floating on water,similar to soap films; different regions within the films are made visible by fluorescentdye molecules that avoid the interiors of the domains, which therefore remain dark;contrast in these images tends to be low.

    Reference Image The first processing step is to remove the significant spatialnonuniformities in the illumination profile that would otherwise introduce bias intothe intensity histogram and interfere with subsequent global processing steps such asbinarization. Nonuniformities in scene illumination are the rule, not the exception: forexample, microscope illuminators are notoriously nonuniform. The requisite correctionrequires a reference image showing the slow background variations (but not the objectsof interest). Unless otherwise available, for example, in the form of a separately storedimage of the scene background, a reference image is created from the original by

    Figure 1.3.1.

  • 8/7/2019 practical algos for image analysis

    19/299

    1.3 A Guided Tour '1 I)

    figure 1.3.2.low-pass filtering; xoonv (Section 3.1), used with a Gaussian low-pass filter (Section3.2), produced Fig. 1.3.2.

    :Keonv domains.tif domREF.tif -g65REM Section 3.1REM Generate 2D Gaussian of size 65x65REM Produce reference image ("background") by low-pass filteringREM Store output in domREF.tifREM Note: REM indicates comment line

    Background Correction With reference image in hand, we proceed to implementthe actual background correction by applying an operation known as fiat fielding.This involves the division of the original by the reference image (Section 3.3) andthe subsequent scaling of resulting intensities to enhance contrast; be (Section 3.3)produced Fig. 1.3.3.

    be domains.tif domREF.tif domBC.tifREM Section 2.3REM Correct background nonuniformities: divide by reference image;REM Scale intensitiesREM Store output in domBC.tif

  • 8/7/2019 practical algos for image analysis

    20/299

    16 Introduction

    Figure 1.3.3.

    Binerizetion Binarization represents the final step in processing the image to con-vert it into a form that is suitable for subsequent analysis of image content. threshm,an optimal thresholding routine (Section 3.9), was applied to a portion of the image,also referred to as area of interest (AOI); this is selected by supplying AOI boundariesas command line arguments. Binarization was followed by magnification (Section 2.4)by means of xscale to produce Fig. 1.3.4.

    . . . . . . --~ . . . ~..- . . . . . .'............ .~ . . . . . .........0 ~ .. . . . . - 4 4 .:~~.-..~._!_.:Figure 1.3.4.

  • 8/7/2019 practical algos for image analysis

    21/299

    1.3 A Guided Tour 17

    threshm domBC.tif domBIN.tifREM Section 3.9REM Specify A(rea)O(f)I(nterest)?yREM Input upper left, lower right AOI coordinates 300 200 850

    600REM Calculated threshold (by moment method) = 63.REM Note: only a portion of the input image, specified by AOI,

    is binarizedREM the binarized image appears magnified

    Optional: Edge Detection As an optional step, domain edges in the binarizedimage are readily identified and marked by applying xconv in conjunction with a 3 x 3Laplacian filter mask; the image is not displayed here. More typically, simple (Section3.4) or advanced (Section 3.5) edge detection would be performed before binarization.xconv domBIN.tif domLAP.tif -f laplac33.txtREM Section 3.4REM Perform edge detection by using 3x3 Laplacian, provided in

    laplac33.txtREM 0 .00000 -1. 00000 0 .00000REM -1 .00000 4.00000 -1. 00000REM 0 .00000 -1. 00000 0 .00000REM Doing image convolution ...REM NOTE: for demonstration only;REM edge detection usually applied to gray-scale image

    Analysis A variety of analytical steps may now be applied to the binarized imageto extract quantitative information regarding image content. The objective in analyzingthis type of image is twofold: analyze the shape of individual domains in order to measure deviations from circu-larity and to ascertain the balance of underlying forces,

    analyze positions of domains within the pattern to ascertain the presence or absenceof spatial correlations: for example, is the pattern of domains completely randomor does it reveal any regularity?Domain Contours: Shape Descriptors First, in pursuing the detailed analysis of

    individual domain shapes, wemay wish to determine suitable shape descriptors to revealthe degree of distortion of domains away from a circular reference state (Sections 4.4and 4.5).

    We may accomplish this, for example, by invoking xcp (Section 4.3), which per-forms region encoding, or by invoking xprn (Section 4.4), which combines region en-coding with contour analysis in terms of geometrical shape descriptors and moments;or, as shown here, by invoking xbdy (Section 4.5), which goes beyond xprn to providea spectral representation of shape features in terms of Fourier descriptors.

  • 8/7/2019 practical algos for image analysis

    22/299

    18 Introduction

    -- -.p .. ~ - ..' t . . . . . .........0 ~ .. . . 4 1 . 0 . . . . . 4 '.t-:_.e !_.:Figure 1.3.5.

    xbdy domBIN.tif domBDY.tif -w domBIN.acmREM Sections 4.4, 4.5REM Scan, link edge points, encode contour(s);REM Select domain(s) for shape analysis;REM Select various options (in response to prompting);REM Evaluate various shape descriptors;REM Create output image, containing:REM resampled contour/edge points; centroid, principal axes;REM Write data to domBIN.acm file;REM NOTE: output image (domBDY.tif) not shownREM use XOR (see IMGBOOL, sect. 2.3) to overlay onto

    original

    Domain Pattern: Region Filling, Centroids An alternative mode of analysis wouldbe to focus on the spatial configuration of domains within the pattern rather thanon individual domain shapes. Accordingly, to locate domains in the pattern, an AOIwithin the image is scanned. The AOI is identified by means of coordinates sup-plied as command line arguments to xah (Section 4.3), a routine that scans the pat-tern, fills regions (Section 4.3), and produces a point pattern composed of domaincentroids; this is shown superimposed on a binarized domain pattern in Fig. 1.3.5,a figure produced by addition (Section 2.3) of the point pattern and the binarizedimages.xah domBIN.tif domAH.tifREM Sections 4.3, 4.5REM Scan, fill regions, and generate point pattern of centroids;REM Produce area histogram;

  • 8/7/2019 practical algos for image analysis

    23/299

    1.3 A Guided Tour 19

    figui' 1.3.6.

    combine domBIN.tif damAR.tif domBV.tifREM Section 2.3REM Superimpose (arithm addition) point pattern onto binary

    domain pattern

    Point Pattern: vorono! Analysis A detailed quantitative analysis of the degreeof order present in the pattern of centroids may be based on the Voronoi diagram,a graphical representation of the pattern generated by xv-or. The output created byxah (Section 4.3) in the format of .vin files serves as input for xvor. Alternatively,coordinates of points in a given image may be scanned by sppto produce a .vin fileforsubsequent Voronoi analysis. In Fig. 1.3.6, the Voronoi diagram is shown superimposedon the point pattern produced by xah. The Voronoi output may be further analyzed byxv-ora and other programs introduced in Sections 6.2-6.4.spp domAR.tif -w domAH.vinREM Section 6.1REM Extract point coordinatesREM Write data to file domAH.vin (for input to XVOR)

    xvor domVOR.tif -r domAH.vin -w domVOR.vdtREM Section 6.1REM Perform Voronoi analysis, create output image domVOR.tifREM Write data to file domVOR.vdt (for analysis by XVORA)

    Other multistep procedures are feasible: as with the Guided Tour, these will gen-erally follow the same progression from lower to higher chapters, with alternative or

  • 8/7/2019 practical algos for image analysis

    24/299

    20 Introduction

    multiple analytical paths opening subsequent to binarization. For example, we wouldhave analyzed a raw image containing line patterns primarily by subjecting it to thin-ning (Section 4.7), encoding by means ofpee (Section 5.1), feature analysis (Section5.2), polygonalization (Section 5.3), line and critical point analysis (Sections 5.4-5.6),and perhaps segment cluster analysis (Section 5.7), as well as Fourier transformation(Section 7.1).

    Programs performing quantitative image analysis frequently provide for the option,either on the command line or during run time, to save output data to a file that maybe required input for other programs performing further analysis. We use a varietyof file suffixes to facilitate the interaction between such programs. The input/outputfile interdependencies in Table 1.3.1 identify programs calling for data input and listsprograms producing requisite data output.

    Table 1.3.1. list of Programs and Input/Output interdependenciesINPUT OUTPUT OUTPUT

    SECTION PROGRAM FILE SUFFIX FILE SUFFIX PROCESSED BY4.3 xah .gdt spp;xsgt

    xep .zdt xphxrg .vm

    5.1 pee .pee peede, etc .peede .peepccfeat .pee

    5.2 1inerid .pee .pee1inefeat .pee1inexy .pccstructrid .peestructfeat .pee

    5.3 fitpo1yg .pee5.4 fitcrit .pee5.5 fit1ine .pee5.6 fitsp1ine .pee5.7 fitpo1yg .pee .seg eh_seg,xsg11

    eh_seg .seg .hdtxsg11 .seg .sgl eh_sg1eh_sg1 .sgl .hdt

    6.1 SPI> .vm :!

  • 8/7/2019 practical algos for image analysis

    25/299

    Global Image Analysis

    In this chapter, we describe global operations for image analysis. A global operation isperformed in an equivalent manner to all pixels in the image; it may be independent ofthe pixel values in an image, or itmay reflect statistics calculated for all pixels, but not alocal subset of pixels. In contrast, a local operation is performed on a pixel with respectto only its own value and those of its neighbors. In this sense, a local operation canbe adaptive because results depend on the particular pixel values encountered in eachimage region. Local operations will be treated in Chap. 3. A typical application of aglobal operation is to increase overall image contrast orbrightness; a typical applicationof a local operation is to enhance preferentially certain regions of low contrast or lowbrightness without affecting other regions.

    Although a particular task can often be addressed by either a global or a localoperation - for instance, contrast can be enhanced globally or locally - there is anoverriding trade-off between the two approaches. When both global and local operationsare available, the user must make a choice based on experimentation that is guided byan understanding of the general differences in applicability mentioned above.

    Requiring no location-dependent computation, global operations are generally sim-pler to implement but are also less flexible than local operations, which provide adaptiveimage modification. Because global operations treat all pixels equivalently, it may beimpossible to improve parts of the image without deleteriously affecting other parts.Thus a global increase in brightness will cause dark regions to be more visible, butmay cause very bright regions to clip at the top range of brightness. Reflecting thestatistics of the entire image, global operations effectively average over local features.Noise effects are thus reduced, but features associated with a desired signal also areaveraged. This is acceptable if only a single type of signal is distributed uniformlythroughout the image. However, it is a disadvantage in the more frequent case in whichthe signal reflects objects of various sizes in nonuniform distribution, as, for example,in microscope images of biological cells.

    Although this book does not deal with computer architectures, we note that globaloperations can be implemented by using special-purpose hardware such as single-input-multiple-data (SIMD) computers. The design of SIMD computers is optimizedto enhance the speed of performing global operations; most special-purpose boardswill not perform general, more complex, image analysis operations.Section OverviewSection 2.1 discusses the intensity histogram as a tool for the examination of statisticalcharacteristics of the image intensity distribution, including the average intensity, therange of pixel intensities represented in the image, and the predominant intensities.

    21

  • 8/7/2019 practical algos for image analysis

    26/299

    22 Global Image AnalysisSection 2.2 describes the use of the histogram in transforming the intensity distributionof an image. The purpose of such transformations is to enhance the visible contrast ofan intensity range about an object of interest, sometimes at the expense of intensityregions that are not of interest. Weprovide several methods of histogram transformationfor automatic or interactive enhancement.Section 2.3 introduces elementary operations for combining images including arith-metic operations (addition, subtraction, andmultiplication) and logical operations (AND,OR, XOR). These operations address such tasks as comparing images and eliminatingknown background noise.Section 2.4 describes several important geometric image transformations involving achange of size (scaling) and orientation (rotation). These transformations are used inimage analysis to reposition the image for better visual inspection and for reductionof distortions introduced by cameras or other image recording devices. The process ofinterpolation between neighboring pixels plays an essential role in these transformationsand is also described here, although it is not properly a global operation.Section 2.5 presents a discussion of image color. Color can be represented in a computerimage by the combination of three different color components, usually red, green, andblue. Itis shown here how transformation to different three-component representationscan aid analysis. The most popular and useful transformation is to intensity, hue, andsaturation components. Veryoften it is sufficient toperform analysis just on the intensityimage. All operations described elsewhere can be applied separately toone, two, or threeof the three image components constituting a color image. Accordingly, color-specificmethods are usually not needed.We defer the discussion of additional global operations to later sections to provideappropriate context. Specifically, the following topics and sections are of interest:Binarizatlon - The process of reducing a gray-scale image to a binary, two-levelimage, usually for the purpose of separating foreground objects from a background.Binarization can be performed by global or local methods. Both of these are describedin Section 3.9.Image Profiling - The image profile is a histogram of ON-valued pixels summedacross rows or columns of a binary image. The profile serves to examine the densityand distribution of pixels in a binary image as well as to determine whether a rowwiseor a columnwise pattern exists in the image; an example of the latter is text on a page,which is written in horizontal text lines. Image profiling is described in Section 4.9.Frequency Analysis - Images are often characterized not by particular objects, but bythe global configuration of all image objects and resulting patterns or texture. Theseglobal features can be effectively analyzed on the basis of a spatial frequency represen-tation of the image. The frequency domain also permits spatial filtering and statisticalanalysis. Chapter 7 introduces the Fourier transform, or the fast Fourier transform (FFT),as the tool to interconvert between spatial domain and spatial frequency representationsand discusses spatial frequency analysis.

  • 8/7/2019 practical algos for image analysis

    27/299

    2.1 Intensity Histogram: Global FeaturesTypical Appiicatiol1(s) - image quality test, objectlocation.Key Words - intensity histogram, global image features.Related Topics - global enhancement (Section 2.2);binarization (Section 3.9).

    (a) (b)figillre 2.1.1. Pictorial Exampie. Illustration of intensity histogram: (a) image of a liver tissuebiopsy, (b) intensity histogram computed from the image in (a). Note the two peaks: the largerpeak represents the large area of gray background, and the much smaller peak (almost a plateau)to the right of the large peak represents the small, black regions. (Reprinted with Permission from[O'Gorman and Sanderson 85], Copyright 1986 by IEEE. )A useful initial characterization of an image may be based on statistics derived from theentire set of constituent pixels. The so-obtained descriptors, usually constructed froman intensity histogram of the image, are referred to as global features.

    The most basic feature is the average pixel value Iin an image. This represents ameasure of image brightness. In particular, I=0 identifies an empty image. A secondfeature is the spread, or variance, of pixel values about the average. This represents ameasure of image contrast: the narrower the spread, the lower the contrast. A convenientapproach to determine such global features is to extract them from an analysis of animage intensity histogram.

    The image intensity histogram is a plot showing the number of image pixels thatdisplay each of the possible discrete intensity values (see Fig. 2.1.1). We construct theintensity histogram by examining the intensity value of each pixel in the image andcounting the number of pixels displaying each of the possible values. On the histogramplot, each intensity value is represented by a histogram bin whose height represents thenumber of image pixels displaying that intensity. Therefore the process of constructingthe histogram corresponds to the filling of histogram bins.

    23

  • 8/7/2019 practical algos for image analysis

    28/299

    24 Global Image AnalysisHistograms of other image characteristics, such as pixel color or object size, etc.,

    may be compiled in corresponding fashion; in each case, the histogram represents thenumber of instances of each feature versus the discrete set of possible values this featurecan assume.The intensity histogram offers a concise representation of the global intensity char-acteristics of an image and facilitates the determination of global features. In statisticalterms, the histogram is a distribution of sample values for a population of intensities.Just as for any distribution, a statistical analysis may be performed for a histogram toextract what we refer to as global image features. In the remainder of this section, wediscuss some common histogram features describing global image characteristics.

    2.1.1 HISTOGRAM FEATURESThe simplest of histogram features is the very presence of occupied bins. Ifonly one binis occupied, then the corresponding image is completely featureless (uniformly white,black, or gray). This may indicate that there is nothing of interest in this image or thatthe camera has found an empty portion of a larger scene (or that the lens cap of thecamera was not removed!).

    A very useful feature is the range of intensity levels, defined as the differencebetween maximum and minimum pixel values represented in the histogram (see Fig.2.1.2). This often serves as a means for feedback in the image acquisition stage to attainthe best image quality. Appropriate adjustments can be made to the camera or scanningdevice to optimize contrast by taking advantage of the full range of intensity values

    (a) (b)Figure 2.1.2. Comparison of (a) l iver tissue image and (b) corresponding histogram with Fig.2.1.1 reveals a wider range of contrast in the present image. The histogram range here is 0-255, whereas the range in Fig. 2.1.1 is 71-255. This image also appears lighter, and this can beseen by two measures, the peak intensity bin: 0 versus 130 for the image in Fig. 2.1.1 and theaverage intensity level; 82 versus 135 for the image in Fig. 2.1.1. (Reprinted with Permission from[O'Gorman and Sanderson 85], Copyright 1986 by IEEE.)

  • 8/7/2019 practical algos for image analysis

    29/299

    2.1 Intensity Histogram: Global Features 25

    figure 2.1.3. Histogram for same imageas in Fig. 2.1.1, except originally digitizedby 7 bits instead of 8 bits, as in Fig. 2.1.1.The histogram shows 128 occupied binsthat are spread across the fuII 256 levels.Since each occupied bin is separated byan unoccupied bin, the histogram appearsas a series of impulses rather than as asmooth plot. (Reprinted with Permissionfrom [O'Gorman and Sanderson 85], Copy-right 1986by IEEE.)

    available for a given display device; specifically, n-bit intensity resolution translatesinto a dynamic range of 2n levels. For example, 8-bit intensity resolution per pixelyields 28 =256 levels.

    The number of image intensity levels is apparent from the histogram plot. In somecases, the digital camera by which the image was acquired has fewer intensity levelsthan the display device. For example, if the camera has 4 levels, then the image canhave 24 = 16 levels, and the histogram a maximum of 16 occupied bins. If,on the otherhand, the display device has 28 = 256 levels, then the image values will usually bemultiplied as 16 x 16 =256 so that the intensities cover the full display range. Whilethis operation spreads the recorded bins over the entire available display intensity range(see Fig. 2.1.3), it leaves the number of bins unchanged.Contrast enhancement (or histogram stretching) techniques of this type may beinvoked in the processing stage should image reacquisition not be possible. Thesetechniques are described in Section 2.2.

    It is also useful to determine the location of the majority of occupied bins withinthe histogram. If the occupied set of histogram bins falls near the upper end of thedynamic range of the display, the image may appear too light; otherwise, the image mayappear too dark (assuming high intensity is white and low is black). As before, eitherproblem can be remedied by improved reacquisition or by histogram transformation(Section 2.2).

    An examination of bin heights can reveal certain image features. The presence of asingle bin with large occupancy indicates that the camera has captured a non-black, butfeatureless region within the image. In such a case, additional bins with low occupancyusually indicate slight nonuniformity or noise in the image.

    The most commonly examined histogram feature is the number of peaks; a his-togram peak usually comprises a group of adjacent bins whose respective counts exceeda baseline level. Histograms frequently display one predominant peak correspondingto either the lowest or the highest intensity. The large pixel count represents the imagebackground and indicates that the fraction of the field of view occupied by background

  • 8/7/2019 practical algos for image analysis

    30/299

    26 Global Image Analysis

    exceeds that occupied by foreground objects. For example, in a biomedical image ofblood cells on a white background or in a document image of black text on white paper,the white background will predominate and will generate the maximally occupied his-togram bin.Aside from a peak representing background pixels, there will often be a distinctsecond peak representing foreground objects. In the example of the blood cell image,this peak will be located at an intensity level that may represent the level of dye stainingused to make a particular cell type visible. Binarization is an important and commonimage processing operation that relies onhistogram analysis: A valley location is foundthat best separates the two peaks representing foreground and background. Foregroundobjects are set to one value, for example, 1 or 255, and background pixels are set toanother value, usually O.Binarization is described in more detail in Section 3.9.

    Histograms may have multiple peaks. For example, if a blood cell specimen hastwo types of cells that are stained with dyes of different colors, the histogram willhave three peaks representing the background and each of the two cell types. Morecomplex histograms, such as those corresponding to images of outdoor scenes, willcontain overlapping peaks corresponding to multiple, possibly overlapping, objectsthat display a large variance in intensities. While it is generally impossible in suchcases to match individual bin peaks to specific objects or object types, the histogrammay still provide some image clues, such as lightness, darkness, or the presence of asingle predominating object.

    Another feature that can be derived from the histogram is entropy. The entropymeasures the average, global information content of an image in terms of average bitsper pixel. For an S-hit image, an entropy approaching 8 indicates an information-richimage, that is, pixel intensities cover the full range and do so throughout the image. Anentropy approaching 0 indicates the presence of predominating regions in the image inwhich there is little variation in pixel values.References and Further Reading[O'Gorman et al., 1985] L. 0'Gorman, A. C. Sanderson and K. Preston, Jr., "A system forautomated liver tissue damage analysis: methods and results," IEEE Trans. Biomedical En-gineering Vol. BME-32(9), pp. 696-706 (Sept 1985).

    Programhiststats

    determines image intensity histogram and yields someglobal image histogram statistics.

    USAGE: histstats inimg [-f file] [-L]ARGUMENTS: inimg: input image filename (TIF)

    OPTIONS: -f file: write output data file holding histogram values-L: print Software License for this module

  • 8/7/2019 practical algos for image analysis

    31/299

    2.2 Histogram Transformations: Global EnhancementTypical Application(s) - enhancement of image contrastby global histogram transformations.Key Words - histogram transformations, expansion,equalization, mapping function.Related Topics - global features (Section 2.1); localoperations (Section 3.1).

    (a )

    (e)

    (b)

    (d)Figure 2.2.1. Pictorial Example. Illustration of contrast enhancement by histogram expan-sion: (a) original image with poor contrast; (b) histogram of (a), the narrow range of occupiedhistogram bins indicating poor contrast, the concentration of intensities at the high end indicatingdark image; (c) result of enhancing contrast in (a); (d) histogram of (c). (This product/publicationincludes images from Corel Stock Photo Library, which are protected by the copyright laws ofthe U.S., Canada, and elsewhere. Used under license.)

    27

  • 8/7/2019 practical algos for image analysis

    32/299

    28 Global Image Analysis

    Image enhancement is discussed here as a processing technique to increase the visualcontrast of an image in a designated intensity range or ranges. Although the degree ofenhancement may be subjective, procedures to perform a given type of enhancementcan be directly related to the desired purpose. The methods described here are histogramtransformations: These generate a new output histogram by modifying the shape ofthe input histogram according to a specific mapping function that is chosen to enhancecontrast in the range of interest. The gray-scale values of the original image are modifiedtomatch the so-obtained output histogram. The result of this is that the gray-scale valuesof the original image are modified to improve its appearance or effectiveness for visualanalysis.

    Several definitions of contrast are in use in such different fields as psychology,optics, and photography. For present purposes, we define image contrast at a pixel asthe difference between its intensity value I(x, y) and the average background intensityInormalized by the full intensity range, i.e.,

    C( ) _ I(x, y) - Ix,y - .I m a x -

    This equation implies that the most direct way to enhance image contrast is to stretchor expand the occupied intensity range, as shown in Fig. 2.2.1 and discussed below.

    In this chapter, we have restricted ourselves to global image enhancement tech-niques. In contrast to local techniques (Section 3.3), these do not alter the informationcontent of the image. That is, the histogram transformations discussed here conservethe number and heights of occupied intensity bins. In practice, certain transformationsmay lead to inadvertent merging of bins so that pixels of different input intensities aremapped to a single output intensity; in such a case, the information content of the orig-inal image is reduced. Conservation of information content may be important for someapplications, such as medical diagnostics, in which it is imperative that the observedimage be true and that no artifacts or information reduction be introduced in the courseof processing. This can be checked by measurement of the entropy before and aftertransformation (as discussed in Subsection 2.1.1).

    In contrast to global methods, local methods such as spatial filtering (Section 3.3)require the empirical choice of a size for the locally applied filter window. Because ofsignificant variations among images, and even within a single image, local techniqueswarrant the choice of filter size. By definition, global techniques apply to the entireimage and thus require no such choice. Three types of histogram transformations aredistinguished here and introduced below.

    2.2.1 HISTOGRAM EXPANSION (HE)Histogram expansion, denoted by H E , is the most straightforward and conservativeof the transformations introduced here. This is a linear transformation that entailsstretching the nonzero input intensity range, x E [Xmin, xmax], to an output intensityrange, y E [0, Y m a x ] , to take advantage of the full dynamic range, typically to Y m a x =255.

  • 8/7/2019 practical algos for image analysis

    33/299

    2.2 Histogram Transformations: Global Enhancement 29

    As a result, the interval [Xmin, xmax] is stretched to cover the new, larger interval[0, Ymax]. Each intensity value x is thus mapped to an output value Y according to thefollowing linear mapping function:

    x - XminY = Ymax'Xmax - XminH E increases contrast without modifying the shape of the original histogram. Thetransformation can be applied broadly without concern for deleteriously altering theimage appearance. This is the histogram expansion transformation chosen for contrastenhancement shown in Fig. 2.2.1.

    Some images may have low contrast even though their lowest and highest occupiedintensity bins are close to the minimum and the maximum of the full range. Theseimages are characterized by a histogram with a narrow peak and long tails to eitherside of the peak. The simple histogram expansion H E will not be effective here insignificantly enhancing image contrast. However, a suitable modification is readilymade by introduction of a user-selected cutoff percentage p. This is chosen such thatthe mid-p% of intensities will be stretched to the maximum range, thus eliminating(or compressing to one bin each) the upper and the lower histogram tails comprising(100 - p)j2% of the pixels each. That is, p serves to determine new lower and upperbounds, X ; " i n and x;"ax' to be placed on the input histogram: intensity values below x : m nand above x ; " a x are clipped, that is, they are set to the minimum and the maximumvalues, respectively. H~ is a very useful transformation: While still fairly conservative,given that the shape of most of the histogram is left unchanged, H~ accomplishesgreater enhancement than does simple histogram expansion.

    The lower x : m n and upper x;"ax bounds of the input range are determined in relationto p as follows:

    I (100 - p) _ 100 ~ h )xmin 2 - T Z:: (x,X=Xmm

    Xmaxwhere T =Lh(x);Xmm

    I (100 - p) _ 100 ~xmax' - Z:: hex).2 T _,X-XmaxThus the modified expansion H~ compresses the tails of the input histogram in orderto expand the central histogram range, which is occupied by pixels contributing to thecentral intensities. The percentage p is selected interactively; common values for prange from p =98% down to p =85%. The lower the chosen percentage, the moresignificant the effect on the image. The onus is on the user to select p so as to preservesalient information.2.2.2 OUTPUT HISTOGRAM SPECIFIED (Ha)A second class of histogram transformations is defined by specification of the shape ofthe output histogram and is designated as Ho. This produces a mapping to an outputhistogram that has the shape of a linear ramp. For a positive slope, the range of occupied

  • 8/7/2019 practical algos for image analysis

    34/299

    30 Global ImageAnalysis

    ( a )

    ( e )

    (b)

    (d)figure 2.2.2. Histogram transformation, HQ, to a negatively sloped ramp function to enhancecontrast in light intensity range. The Original and its histogram are shown in (a) and (b), thetransformed image and its histogram are shown in (c) and (d). respectively. (Reprinted withPermission from [O'Gorman et al. 85], Copyright 1986 by IEEE.)

    bins in the low-intensity range is stretched and contrast is enhanced there (Fig. 2.2.2).For negative slope, the range of occupied bins in the high-intensity range is stretchedand contrast is enhanced there (Fig. 2.2.3). The case of zero slope corresponds tohistogram equalization, which is a popular transformation whose results lie betweenthe two extremes of sloped ramps (Fig. 2.2.4).

    Ho is particularly useful for automatic (noninteractive) enhancement because theoutput shape is independent of input shape. For instance, H0 thus provides a conve-nient way to normalize the intensity distribution - to that specified output shape. This

  • 8/7/2019 practical algos for image analysis

    35/299

    2.2 Histogram Transformations: Global Enhancement 31

    (a ) (b)figure 2.2.3. Histogram transformation, HQ, to a positively sloped ramp function to enhancecontrast in dark intensity range. The original and its histogram are shown in (a) and (b), thetransformed image and its histogram are shown in (c) and (d), respectively. (Reprinted withPermission from [O'Gorman et al. 85], Copyright 1986 by IEEE.)normalization facilitates comparison among a number of different images. For thisreason, it is often applied as a preprocessing step, when subsequent analysis is to beapplied to images with normalized intensity statistics.

    The function that maps the input histogram to a ramp-shaped histogram will dependon the slope m, of the ramp, on the range of output intensity Y E [0, Ymax ] , and on the

    (a) (b)figure 2.2.4. Histogram transformation, HQ, to azero-sloped, uniform, function to treat contrastequally over all intensity range. The original and its histogram are shown in (a) and (b), thetransformed image and its histogram are shown in (c) and (d). respectively. (Reprinted withPermission from [O'Gorman et al. 85], Copyright 1986by IEEE.)

  • 8/7/2019 practical algos for image analysis

    36/299

    32 Global Image Analysispartial sum T(x) of bins from x =Xmin to x in the input histogram:

    x 1T(x) =Lh(x) - 2 [h(Xmin) + h(xmax)],Xmm

    where h(x) denotes bin heights and Xmin and Xmax denote the positions of the lowest andthe highest occupied bins, respectively, in the input histogram, Tmax = = T(xmax) . For agiven value of the slope m the requisite transformation has the form

    ( Tmox _ Yma x ) 2 + 2T(x) ,mYmax 2 m m < m =0,

    ( Tm,;x _ Ymo x ) 2 + 2T(x) ,mYmax 2 m m > In our experience, transformations specified by three particular values for m cover mostpractical situations. Thus, to enhance.. high intensities, set m = -2T /Y ~ax'.. low intensities, set m =2T /Y~ax '.. all intensities equally, set m = (histogram equalization).

    These choices ensure transformations to an output histogram with maximum negativeslope, maximum positive slope, and zero slope, respectively.

    2.2.3 HISTOGRAM TRANSFORMATION SPECIFIED (HT)The third class of histogram transformations, H T, requires the explicit specificationof a mapping function. Applied to a range of input intensities, the mapping functiondirectly produces the output histogram. This mode of histogram modification is mostuseful in a setting that permits visual inspection of the output histogram and interactiveoptimization of parameters specifying the mapping function.

    The variable enhancement of intensities, orhistogram stretching, around a particularvalue of the input intensity - with the goal of enhancing image contrast - calls for thistype of histogram transformation.

    Specifically, the requisite mapping function should stretch the given range of inputintensities into a wider range of output intensities. A particular intensity value, or arange of input intensities, is chosen; let x = x, denote the chosen intensity valueor the average intensity in a region of interest. Histogram stretching is achieved byspecification of an additional parameter, namely the desired degree of stretching; thiscorresponds to setting the local slope of the mapping function to m > 1.

    Given a range of input intensities, x E [Xmin, xm ax ], and output intensities, Y E[ 0, Y m ax], a third-order polynomial can be specified to meet these criteria, mappinginput intensities x to output intensities Ys according to

    vs =Ax3 + BX2 + ex +

  • 8/7/2019 practical algos for image analysis

    37/299

    2.2 Histogr~m Transformations: Global Enhancement 33

    whereI-m

    A= 2 2'X max - 3x cxm ax + 3xcB=-3Axn

    C=m + 3Ax;,D=O.

    By design, y(x) will be limited to a range of output intensities between 0 and an upperbound of Ymax' However, when actual output intensity values produced by the mappingfunction exceed Yma x , the output range must be artificially clipped at Yma x , and thisclipping often leads to an undesirable appearance. The severity of clipping can bereduced by a gradual tapering toward upper and lower bounds; this is achieved by aramp function of the form

    lower bound: Ylower (X) =kx;upper bound: Yupper (x ) =k(x - xmax ) + Ymax,

    where k, the slope of the ramp, is an additional adjustable parameter. We choose thevalue of k by bearing in mind that, as k is increased from zero, the severity of clippingwill be reduced, but that, as k approaches 1, the range of contrast enhancement isnarrowed, and the overall effect of the transformation is diminished, eventually leavingthe input image unaltered. A typical value of k is 0.2.

    Taking into account the tapered bounds, we may thus specify the H T mappingfunction in the following form:

    IYlower (X) , Ys(x) < Ylower(X)Y = Yupper (X) , Ys(x) > Yupper (x ) .Ys(x) , otherwiseThis mapping function is shown in Fig. 2.2.5 for low, medium, and high valuesof XC' A typical value for the slope of the mapping function is m =2; results of thistransformation are shown in Fig. 2.2.6.

    XXmax 0 Xmaxx, x,

    (c)a) (b)Figure 2.2.5. Histogram mappings for Hr transformation (a) to enhance low intensities, (b) toenhance middle intensities, (c) to enhance high intensities.

  • 8/7/2019 practical algos for image analysis

    38/299

    34 Global Image Analysis

    (a)

    (c)

    (b)

    (d)Figure 2.2.6. Histogram transformation Hr to enhance low intensities. (a) Original, (b) its his-togram, (c) the transformed image, (d) its histogram. Note the greater contrast within cells,revealing structure within dark nuclei.

    This transformation can also enhance the upper- and the lower-intensity ranges atthe expense of the midrange. When the slope is less than unity,m < 1,the range aroundXc loses contrast, while higher- and lower-intensity ranges gain contrast. In this case,for practical reasons, the requisite choice for Xc is Xc =xmax/2.References

  • 8/7/2019 practical algos for image analysis

    39/299

    Programs 35V. T . Tom and G. J. Wolfe, in "Adaptive histogram equalization and its applications," in Appli-cations of Digital Image Processing IV, A. G. Tescher, ed., Proc. SPIE 359,204-209 (1982).

    J. S. Lim, "Image Enhancement," in Digital Image Processing Techniques, M. P.Ekstrom, ed.(Academic, Orlando, FL, 1984), pp. 1-51.L. O'Gorman and L. Shapiro Brotman, "Entropy-constant image enhancement by histogramtransformation," Proceedings of 29th Annual SPIE, San Diego, Aug. 1985, pp. 106-113.

    Programshistex (Histogram Expansion)

    enhances image contrast by performing histogram expansion.USAGE: histex inimg outimg [-p PCT_KEEP] [-m MAXVAL] [-L]

    ARGUMENTS: inimg: input image filename (TIF)outimg: output image filename (TIF)

    OPTIONS: -p PCT_KEEP: percent of histogram to keep: tails atupper and lower edges of histogram areremoved equally; default = 98%;

    -m MAXVALUE: maximum value of image intensity (ifdifferent than 255); default = 255.

    -L: print Software License for this modulehistrmnp (Histogram Ramp)

    transforms image intensity distribution to enhancecontrast in dark, medium, or light intensities.

    USAGE: histramp inimg outimg [-s SLOPE_SIGN] [-L]ARGUMENTS: inimg: input image filename (TIF)

    outimg: output image filename (TIF)OPTIONS: -s SLOPE_SIGN: value of -1, 0, or 1, connoting the sign

    of the intensity histogram shape;corresponding increase in contrast inhigh- (-1), medium- (0), or low- (1)intensity ranges; the default SLOPEis 0, which yields uniform contrastdistribution across all intensities(also known as histogram equalization)

    -L: print Software License for this modulehistexx

    expands intensity range about a chosen value.USAGE: histexx inimg outimg [-x X_CENTER] [-s SLOPE] [-tTAPER_SLOPE] [-L]

    ARGUMENTS: inimg: input image filename (TIF)outimg: output image filename (TIF)

    OPTIONS: -x X_CENTER: intensity value about which to increasecontrast (default = 128);

    -s SLOPE: slope of enhancement transform; as thevalue is set above 1, contrast becomes

  • 8/7/2019 practical algos for image analysis

    40/299

    36 Global Image Analysis

    greater about X_CENTER, but contrastis reduced at other intensities; if slopeis set below 1, contrast is reducedat X_CENTER and increased at high and lowintensities. If slope is 1, intensitiesremain unchanged (default = 2.0)

    -t TAPER_SLOPE: slope of bounds of transformation;values> 0 produce more tapering;default = 0.2

    -L: print Software License for this module

  • 8/7/2019 practical algos for image analysis

    41/299

    2.3 Combining ImagesTypical Applicathm(sl- image overlays, backgroundsubtraction; X OR binary operation to control compositeimage.Key Words - addition, subtraction; AND, OR , X OR.Related Topics - histogram operations (Section 2.1), colorimage transformation (Section 2.5); flat fielding(Section 3.3), binarization (Section 3.9); morphological andcellular processing (Section 4.1).

    figure 2.3.1. Pictorial Example. An example of arithmetic image addition. Left, image ofcircular domains observed in atwo-dimensional monomolecular film by means of fluorescencemicroscopy; right, original with superimposed edge contour image. Note: methods for producingthe domain contours overlaid on the original images are discussed in Sections 3.4 and 3.5.(Reprinted with Permission from [Morgan and Seul 95], Copyright 1995 American ChemicalSociety.)

    The elementary process of creating an image from a combination of two separate inputimages finds frequent use in the processing of gray-scale as well as binarized images.The former case calls for arithmetic operations, notably addition, subtraction, and, inrare cases, division (Section 3.3); the latter case requires the application of logical,or Boolean, operations, notably AND, OR, and (ejxtclusivejon. While the majority ofthe image processing operations discussed in Chaps. 2 and 3 apply to groups of pixels(neighborhoods) in a single image, the binary operations described below are appliedto pairs of corresponding individual pixels in separate images.

    31

  • 8/7/2019 practical algos for image analysis

    42/299

    38 Global Image Analysis

    2.3.1 ARITHMETIC OPERATIONSAddition and Subtraction The most commonly required arithmetic operations

    for combining two separate input images are (pixel-by-pixel) addition and subtrac-tion:Addition le x , y ) =min[h(x, y) + 12(x , y) ; lmax ] ,

    Subtraction le x , y) =max[h(x, y) - /z(x , y); lm in ] .Given the finite range of gray values, limited by l r r i ln= and lmax=255, the most im-portant point to be aware of is the possibility of overflow and underflow, respectively, inconnection with addition and subtraction. In either case, clipping of the image intensitywill result. That is, in the first case, if the sum of two image intensities exceeds lmax , itwill be set to lmax ; in the second case, if the difference L, - /z falls below 0, it will beset to 0.

    Clipping can be avoided if the range of intensity values encountered in both inputimages is rescaled before the images are combined. This entails scanning the two inputimages and computing all pixel sums and differences to identify maximal and minimaloutput intensity values, (h + 12)maxand (h - /z)min, respectively. These values are thenapplied as scale factors according to the following prescription:

    ModifiedAddition le x , y) = [f1(X, y) + /z(x , y)] x 255/(11 + / z )max ,Modified Subtraction le x , y) = [f1(X, y) - 12(x , y) + (II - /z)min]

    x 255/[255 + (h - /z )min] .An example of addition is that of combining an original (gray-scale) image with asuperimposed edge map as illustrated in Fig. 2.3.1. This facilitates the evaluation ofthe accuracy of edge detection procedures; these procedures are discussed in Sections3.4 and 3.5. In the experimental sciences, subtraction of a reference image (back-ground) from an incoming raw image (foreground) is a common operation to eliminateblemishes or inhomogeneities of the scene illumination, as discussed in more detailin Section 3.3. It is often possible to record a standard reference image, for example,by defocusing the imaging optics and to store this background image for subsequentuse.Division While less commonly required than addition and subtraction, division

    of one image by another is often called for in video microscopy when images arerecorded with cameras that exhibit nonlinear output characteristics (see also modifiedflat fielding, Subsection 3.3.1). In such a case, subtraction can introduce distortions inthe image intensity distribution:

    Division le x , y) = l l(x , y )//z (x , y): lz(x , y) = f. o.Implementation of the division of an image II by a second image I z requires two

  • 8/7/2019 practical algos for image analysis

    43/299

    References and Further Reading 39

    modifications of this simple prescription. First, pixels of zero intensity are removedfrom [2, adding a constant of unity to produce [~ = = Iz + C, C = 1. Second, divisionof two images with comparable intensity distribution leads to small (and generallynoninteger) output values and therefore requires the scaling of the output image to thefull dynamic range of the display device, say [0, 255], as follows:

    Modified Division lex, y) = [hex, y)/ l~(x, y)] x 255/(111 I~)max.

    2.3.2 LOGICAL (BOOLEAN) IMAGE OPERATIONSReferring to the two possible values of pixels in a binary image as ON and OFF,respectively, we may summarize the most commonly encountered Boolean operationsas follows:

    AND a AND b =ON if a =b =ON,OR a OR b =ON if a =ON or if b =ON,XOR a XOR b = ON if a = ON and b = OFF or

    if a =OFF and b =ON.The primary use oftheAND operatoris to findall ONpixels common to two inputimages.The OR operator is useful in combining all ON pixels of both images into a single outputimage, thereby producing the Boolean equivalent of the arithmetic addition operation.The XOR operator is used to highlight positions whose pixel values in the two imagesdiffer. Boolean operations also are encountered in connection with morphological andcellular logic operations, applied to pixel neighborhoods (Section 4.1).

    As we have indicated, all operations are applied to individual pairs of pixels frominput images II and h so that, for any of the Boolean operators, represented here by0, the output image Iis composed as follows:

    lex, y) =hex, y) 0 hex, y) (1)for all positions (x, y) in the input images. Figures 2.3.2 and 2.3.3 illustrate theresults.

    These Boolean operators are readily combined (or concatenated) to achieve addi-tional effects. Other Boolean operations, such as NOT, NAND, and NOR, are not com-monly encountered in the context of image processing.

    References and Further Reading[Morgan and Seul, 1995] N. Y. Morgan and M.. Seul, "Structure of disordered drop-let domain patterns in a monomolecular film," J. Phys. Chern. 99, 2088-2095(1995).

  • 8/7/2019 practical algos for image analysis

    44/299

    40 Global Image Analysis

    (b)

    (a)

    (c)figure 2.3.2. Illustration of Boolean AND operation: (a)the fingerprint pattern and (b) the circulardisk (assumed here to be composed of ON pixels) were combined to produce (c) the croppedimage.

    (a) (b) ( c )figure 2.3.3. Illustration of Boolean OR and XO R operations: The pattern in (a) was combinedwith asquare grid composed of ON pixels (not shown) to produce (b) by OR and (c) by XOR .

  • 8/7/2019 practical algos for image analysis

    45/299

    Progmms 41Programsimgarith

    performs arithmetic combination of two images: addition,subtraction, or multiplicationUSAGE: imgarith inlimg in2img outimg [-0 OPERAND] [-x X] [-y Y]

    [-L]ARGUMENTS: imlimg, in2img: input image filenames (TIF)

    outimg: output image filename (TIF)OPTIONS: -0 OPERAND: for addition, subtraction, or

    multiplication; default is addition (+).-x X: X-offset of second image relative to first-y Y: Y-offset of second image relative to first;

    default = (0,0).NOTE: for images of different sizes,

    the output image will have thesize of the first specified image.

    -L: print Software License for this moduleimgbool

    performs Boolean combination of two images: OR, AND, orXOR

    USAGE: imgbool inlimg in2img outimg [-0 OPERAND] [-x X] [- y Y][-L]

    ARGUMENTS: imlimg, in2img: input image filenames (TIF)outimg: output image filename (TIF)

    OPTIONS: -0 OPERAND: for OR, AND, or XOR; defaultis OR (0).

    -x X: X-offset of second image relative to first-yY: Y-offset of second image relative tofirst; default = (0,0).NOTE: for images of different sizes,

    the output image will have thesize of the first specified image

    -L: print Software License for this modulecombine

    adds two images and writes the resulting imageto the specified output file.

    USAGE: combine inlimg in2img outimg [-c clip] [-L]ARGUMENTS:inlimg: first input image filename (TIF)

    in2img: second input image filename (TIF)outimg: output image filename (TIF)

    OPTIONS:-c clip: clipping factor for output image 0-255 (default=255)

    -L: print Software License for this module

  • 8/7/2019 practical algos for image analysis

    46/299

    42 Global Image Analysisinv

    inverts the input image and writes the resulting imageto the specified output file.

    USAGE: inv inimg outimg [-LJARGUMENTS:

    inimg: input image filename (TIF)outimg: ouput image filename (TIF)

    OPTIONS:-L: print Software License for this module

  • 8/7/2019 practical algos for image analysis

    47/299

    Geometric Image Transformath::msTypical Application!s) - scaling: magnification andreduction; rotation.Key Words - nearest-neighbor interpolation, bilinearinterpolation; resampling; scaling, rotation.Related Topics - convolution (Section 3.1), subsampling(Section 3.6), multi resolution analysis (Section 3.7),adaptive thresholding (Section 3.9); morphology andcellular processing (Section 4.1); sampling (Section A,4).

    (a) (b)figure 2.4.1. Pictorial Example. Imageclipping introduced by direct (forward) rotation. Asa result of rotation, portions of the original image (a) are placed out of bounds, while otherregionsof thefield of view areleft vacant (b).Remediesto this problemarediscussedin thetext.(Reprintedwith Permissionfrom [Woodward and Zasadzinski96], Copyright 1996AmericanPhysicalSociety.)

    This section addresses changes in image scale and orientation that are applied to facil-itate processing (see, e.g., Section 3.7) or to correct misorientation of an image, suchas a page of text on a scanner, before further analysis. Other corrective transformationsinclude shearing and warping (not discussed here) that can be necessary to compensatefor shape distortions introduced by recording devices.

    2.4.1 GEOMETRIC INTERPOLATIONOperations such as scaling, rotation (see Fig. 2.4.1), and corrective warping rely fortheir proper implementation on interpolation and image resampling. Interpolation maybe visualized as a process generating a continuous function g(t) from a given discretesample g [m ] by application of a suitable fitting function to a number n of nearest neigh-bors at each of the sample points. The interpolation function may then be evaluated atthe desired target points to complete a process known as resampling. In this section,

    43

  • 8/7/2019 practical algos for image analysis

    48/299

    44 Global Image Analysis

    Spatial Transformationf(x, y)

    g(x', y')Gray-Level Assignment:

    to (Ix'], [y']), the grid point closest to (x', y')figure 2.4.2. Interpolation is called for to assign approximate gray levels to pixels that aremapped to noninteger target coordinates under spatial transformations.

    we describe the two most common interpolation schemes that have the benefit of speedand simplicity of implementation. Resampling will be discussed again in Sections 3.6and 3.7, which also contain a more general presentation of interpolation based on linearfilters.

    InterpolationAn image transformation of the form

    where x' = = hAx, y) and y ' = = hy(x, y) denote pixel coordinates in the target image,prescribes the mapping of each original pixel value, I(x, y), into a new pixel value,I(x' , y'). However, as illustrated in Fig. 2.4.2, the transformation H will generally yieldnoninteger target coordinates x' and y', a problem encountered in the specific cases ofscaling and rotation. Geometric interpolation is invoked to provide gray-level valuesat valid - that is, at integer - pixel coordinates. We evaluate the requisite new pixelintensities by relying on the values at one or several actual (noninteger) target imagelocations.

    The simplest form of interpolation relies on the inspection of nearest-neighborlocations. That is, each integer location in the target image is assigned the gray levelof the transformed pixel (x', y') in its most immediate proximity. We obtain smootherimages by considering the shell of (four) nearest neighbors and computing a newgray-level value on the basis of a weighted average of these four input values. Thestandard bilinear interpolation relies on weights derived by simple integer truncationin both x- and y directions: a = x - [x] and b = y - [y], respectively, where [x]denotes the largest integer not exceeding x. Alternatively, weights can be based onthe actual distance R between target location (x', y') and the (integer) pixel locationof interest. These most commonly used nearest-neighbor (order n =1) and bilinear(n =2) interpolation schemes are illustrated in Fig. 2.4.3 and summarized in Fig. 2.4.4.

    Weperform higher-order interpolation by considering the shell of the (four) nearest,as well as the shell of the (twelve) next-nearest neighbors (n =3). Wemay implementthis scheme by invoking cubic spline functions [Hagan, 1991], but the computationaleffort involved diminishes its practical role and it is not included here. In general,the preferred choice of interpolation function depends on the nature of the requisite

  • 8/7/2019 practical algos for image analysis

    49/299

    2.4 Geometric Image Transformations 45

    BilinearInterpolationNearest NeighborInterpolation

    Figure 2.4.3. Graphical illustration of nearest-neighbor and bilinear interpolations.

    transformation, keeping in mind the rapidly increasing computational cost of higher-order interpolation schemes.

    Bnterpolation and ResamplingResampling must bepreceded by conversion of the (discrete) original to a continuous

    representation by means of convolution with a suitable interpolation function. Whilefigure 2.4.4. Common Geometric Image Interpolation Procedures (input image: /[]; outputimage: o[]).

    Nearest-Neighbor Interpolation (SimpleRounding):ordern = 1" s tr ate gy : assign gray value of closest pixel" c om m en ts : image shifted by up to 112pixel; gray values remain unchanged. . e xp re s si o n:

    Olx',y ']

    Bilinear Interpolation: n =2

    II (int)(y + 0.5), (int)(x + 0.5)]

    . . s tr at eg y : select weighted sum of 4 nearest pixels in I(a) weights proportional to distance(b) weights proportional to square of distance

    @ comment s : new gray values appear. , e xp re s si o n:

    (a) : Olx',y '] abI[y , xl + (1 - a )b I(y , x + 1]+a(1 - b) I[y + 1, x] + (1 - a) (1 - b)J[y + 1, x + 1]i=4 l, i=4 1

    ( b) : O [ y' ,x '] = LR~2/L R2i=l r i=l I

    where, in (a) , a =x - jlo o r(x) , b =Y - flo or(y ).

  • 8/7/2019 practical algos for image analysis

    50/299

    46 Global Image Analysis

    conceptually distinct, the two operations may be combined to attain greater efficiency.This is accomplished by restriction of the evaluation of the interpolation function tothe target points of interest. In cases such as image rotation, we determine the desiredlocations at which to resample the input image by invoking the inverse H-1 of theprescribed geometric transformation, as discussed below.

    A more general perspective of this combined interpolation and resampling is possi-ble but relies on the concept of convolution, introduced in Section 3.1. The convolutionoperator facilitates the modification of images by application of linear filter masks.Proper masks may be constructed to combine resampling and interpolation into a sin-gle step. Interpolation and resampling operations are discussed again in Section 3.6[Hagan, 1991].

    2.4.2 IMAGE SCALINGMagnification and ReductionAdjustment of the scale in an image is often desirable either to zoom in on details by

    magnification or to zoom out to gain an overall overview by reduction. Magnificationpermits closer inspection of feature details, usually at the expense of excluding fromview other parts of the image. Reduction facilitates displaying large images ormultipleimages such as a collection of thumbnail sketches on one screen.

    Simple integer scaling is accomplished by expansion or reduction of the dimensionof the displayed image by an integer factor k; for magnification, k > 1. Scaling maybe performed separately for horizontal and vertical image dimensions with respectivescale factors k, and ky ; preservation of the aspect ratio requires that k, = ky = k.

    Magnification requires an increase in the number of pixels. The simplest procedureto create the requisite additional pixels is to replicate each existing pixel k, times and kytimes, respectively, to fill in the additional columns and rows of the magnified image.Conversely, reduction requires deletion of pixels from the original: k - 1 of every kpixels are removed to achieve a k-fold image reduction.

    This simple single-pixel replication or deletion procedure often results in an ob-jectionable, blocky appearance. In the case of image magnification, we often achievean improvement by invoking interpolation. That is, rather than simply replicating ex-isting pixels, we combine their values to compute intermediate values for the newlyrequired pixels in the magnified image. The simplest and most common procedures forgeometric interpolation are described in Subsection 2.4.1.

    General Scaling: The Binary CodeThe scaling of images by noninteger factors requires a generalization of the simplereplication and deletion of pixels just described for scaling by an integer factor. While

    this can be achieved by interpolation, an approach based on the representation of linesand curves onpixel grids provides analternative solution that yields very fast algorithms.

    Consider the representation of a line with fractional slope on a pixel grid: The setof pixels selected to provide the closest discrete approximation to the ideal continuousline will form a staircase of varying step widths and heights, as illustrated in Fig. 2.4.5for a line of slope 5/9.

  • 8/7/2019 practical algos for image analysis

    51/299

    2.4 Geometric Image Transformations 41

    v15 10 15 x

    16

    , I , !! , , I . , ! . . . . . . . . .

    i I I I i I I A' I ,! , I ! I II I ! I I ../1 i

    I ! I I I I I i -I ,I ! I ,~I I I I.r~I I, I iI I , II I I I

    I ! i II I !i I I I110101010

    figure 2.4.5. Binary code for a line of slope 5/9. Columns in which the continuous line intersectshorizontal lines in the grid are indicated by o. The corresponding binary code, a string of length9, is indicated for two successive intervals.

    This approximation is readily constructed by the marking of all columns in whichthe ideal line intersects a horizontal line in the pixel grid; once this threshold is reached,a new step is introduced in the staircase. This procedure thus defines a binary sequenceby assigning 0 and 1,to unmarked and marked columns, respectively. For example, asillustrated in Fig. 2.4.5, a line of slope 5/9 generates the binary code 110101010.

    This graphical construction corresponds to integer truncation, i.e., to the assignmenty = [y], where [ ] denotes the largest integer not exceeding y. That is, if an image ofq columns is to be expanded to a width of p columns, the corresponding binary codewould show q < p set bits that are uniformly distributed throughout the string of pbits. As the target image is constructed column by column, each set bit in the codeindicates that the corresponding column in the target image is to receive an originalsource image column, while each unset bit indicates that the corresponding column isto receive a duplicate of the most recently copied source image column. This procedurethus spreads p source image columns over q target image columns. Conversely, in ahorizontal reduction, each source image column marked by 0 is eliminated.

    Vertical scaling proceeds analogously, based on a binary code evaluated on the basisof vertical grid-line intersections, and the resulting binary code gives instructions forthe handling of image rows.

    Based on a generalization of this idea to two dimensions, the implementation pro-vided here also avoids floating-point calculations by a simple trick and thus achievesvery fast execution [Clark, 1997]. The images in Fig. 2.4.6 illustrate noninteger reduc-tion and enlargement.

    2.4.3 IMAGE ROTATIONImage rotation is a transformation to change the orientation of the original image onthe screen. In general, rotation alters image size.

    A special case is the rotation by multiples of 90 and the related reflection about thehorizontal or the vertical center lines. These operations have the special property thatthe overall rectangular shape of the image is preserved. Implementation simply relieson appropriate translations of rows and columns. In particular, rotation by 180 can be

  • 8/7/2019 practical algos for image analysis

    52/299

    48 Globa! Image Analysis

    (a)

    (b)

    figure 2.4.6. Illustration of noninteger scaling. The original in (a) was enlargedby a factor of 1.7 t o produce (b) and was reduced by 1.7 to produce (c). (Reprintedwith Permission from [BL-TJ 98l-Copyright 1988 by LucentTechnologies Inc. )

    (c)

    performed in place, i.e., without creating additional copies of the image in memory; ifthe input image is square, in-place rotation is also possible for multiples of 90.

    Rotation by an arbitrary angle is more complex. The transformation of interest,x' = = Rx(x, y) and y' = = Ry(x, y) is explicitly specified in the form of an orthogonaltransformation:

    -sin] .cosThe naive way to proceed would be to use the transformation R to find target locationsfor all pixels in the original image. However, as illustrated in Figs. 2.4.1 and 2.4.7,this approach encounters two problems. First, target coordinates may fall on noninte-ger locations. Simply ignoring noninteger target coordinates would create holes in therotated image, not a desirable result. The alternative is to invoke interpolation: Pixelvalues in the target image are computed on the basis of values assigned to nearby non-integer target coordinates. Second, rotation of a rectangular input image will generate ashape that is no longer congruent with the display: Some portions of the display regionwill be left unassigned and some portions of the rotated image will extend beyond theboundaries of the screen.

    In fact, a preferable strategy is to work backwards. That is, rather than the use of Rwith the attendant problems discussed above, each screen pixel is regarded as an outputpixel (x', y') whose source coordinates we evaluate by invoking R-1, the inverse ofR:R-1( ) =[cosx, y -sin sin]cos .

    The assigned source coordinates (x, y) will generally not correspond to integer values,

  • 8/7/2019 practical algos for image analysis

    53/299

    References and further Reading 49

    Forward Transformation(-2, -2) ,-------r,,----,----,---,-----, (2, -2)

    (x~-2,y~-I) (2, -1)A B C D EF G H I JK L M N 0

    Rotation by30 degrees !

    x' ~ 00.866x - 0.5yy' ~ 0.5x + 0.866y

    (-2,1) (2,1)

    (-2, -2)Inverse Transformation

    ,-----,--_.---------,_:;;-----, (2, -2)(-2, -1) (2, -1)

    Rotation by30 degrees

    F G B C DK L H D EL M N I J'J-?Ar--h7"'P,--I----'v"'l x~ 0.866x' + 0.5y'Y~ -O.Sx ' + 0.866y'

    (-2, 1) (2,1)

    figure 2.4.1. Illustration of difficulties encountered in implementing rotation of a rectangularinput image (here of dimensions 3 x 5) by if; = 30 so that x' = 0.866x - 0.5Vand V' = 0.5x +0.866Y. The forward transformation (top) requires a 5 x 5 output array for displaying the rotatedimage, In contrast, a strategy relying on the inverse transformation, x = 0.866x' + 0.5V' andY= -0.5x' + 0.