Fundamentals of Digital Image Processing A Practical Approach with Examples in Matlab Chris Solomon SchoolofPhysicalSciences,UniversityofKent,Canterbury,UK Toby Breckon SchoolofEngineering,CranfieldUniversity,Bedfordshire,UK Fundamentals of Digital Image Processing Fundamentals of Digital Image Processing A Practical Approach with Examples in Matlab Chris Solomon SchoolofPhysicalSciences,UniversityofKent,Canterbury,UK Toby Breckon SchoolofEngineering,CranfieldUniversity,Bedfordshire,UK Thiseditionfirstpublished2011,(cid:1)2011byJohnWiley&Sons,Ltd WileyBlackwellisanimprintofJohnWiley&Sons,formedbythemergerofWiley’sglobalScientific, TechnicalandMedicalbusinesswithBlackwellPublishing. Registeredoffice:JohnWiley&SonsLtd,TheAtrium,SouthernGate,Chichester, WestSussex,PO198SQ,UK EditorialOffices: 9600GarsingtonRoad,Oxford,OX42DQ,UK 111RiverStreet,Hoboken,NJ070305774,USA Fordetailsofourglobaleditorialoffices,forcustomerservicesandforinformationabouthowto applyforpermissiontoreusethecopyrightmaterialinthisbookpleaseseeourwebsiteat www.wiley.com/wileyblackwell Therightoftheauthortobeidentifiedastheauthorofthisworkhasbeenassertedinaccordancewith theCopyright,DesignsandPatentsAct1988. Allrightsreserved.Nopartofthispublicationmaybereproduced,storedinaretrievalsystem,or transmitted,inanyformorbyanymeans,electronic,mechanical,photocopying,recordingorotherwise, exceptaspermittedbytheUKCopyright,DesignsandPatentsAct1988,withoutthepriorpermission ofthepublisher. Wileyalsopublishesitsbooksinavarietyofelectronicformats. Somecontentthatappearsin printmaynotbeavailableinelectronicbooks. Designationsusedbycompaniestodistinguishtheirproductsareoftenclaimedastrademarks.Allbrand namesandproductnamesusedinthisbookaretradenames,servicemarks,trademarksorregistered trademarksoftheirrespectiveowners.Thepublisherisnotassociatedwithanyproductorvendormentioned inthisbook.Thispublicationisdesignedtoprovideaccurateandauthoritativeinformationinregardto thesubjectmattercovered.Itissoldontheunderstandingthatthepublisherisnotengagedinrendering professionalservices.Ifprofessionaladviceorotherexpertassistanceisrequired,theservicesofa competentprofessionalshouldbesought. MATLAB(cid:3)isatrademarkofTheMathWorks,Inc.andisusedwithpermission.TheMathWorksdoesnotwarrant theaccuracyofthetextorexercisesinthisbook.Thisbook’suseordiscussionofMATLAB(cid:3)softwareorrelated productsdoesnotconstituteendorsementorsponsorshipbyTheMathWorksofaparticularpedagogical approachorparticularuseoftheMATLAB(cid:3)software. LibraryofCongressCataloguinginPublicationData Solomon,ChrisandBreckon,Toby Fundamentalsofdigitalimageprocessing:apracticalapproachwithexamplesinMatlab/ChrisSolomonand TobyBreckon p.cm. Includesindex. Summary:FundamentalsofDigitalImageProcessingisanintroductorytextonthescienceofimageprocessing andemploystheMatlabprogramminglanguagetoillustratesomeoftheelementary,keyconceptsinmodern imageprocessingandpatternrecognitiondrawingonspecificexamplesfromwithinscience,medicineand electronics Providedbypublisher. ISBN9780470844724(hardback) ISBN9780470844731(pbk.) 1. Imageprocessing Digitaltechniques. 2. Matlab. I.Breckon,Toby. II.Title. TA1637.S651542010 621.36’7 dc22 2010025730 Thisbookispublishedinthefollowingelectronicformats:eBook9780470689783;WileyOnlineLibrary 9780470689776 AcataloguerecordforthisbookisavailablefromtheBritishLibrary. Setin10/12.5ptMinionbyThomsonDigital,Noida,India 1 2011 Contents Preface xi Using the book website xv 1 Representation 1 1.1 What is an image? 1 1.1.1 Image layout 1 1.1.2 Image colour 2 1.2 Resolution and quantization 3 1.2.1 Bit-plane splicing 4 1.3 Image formats 5 1.3.1 Image data types 6 1.3.2 Image compression 7 1.4 Colour spaces 9 1.4.1 RGB 10 1.4.1.1 RGB to grey-scale image conversion 11 1.4.2 Perceptual colour space 12 1.5 Images in Matlab 14 1.5.1 Reading, writing and querying images 14 1.5.2 Basic display of images 15 1.5.3 Accessing pixel values 16 1.5.4 Converting image types 17 Exercises 18 2 Formation 21 2.1 How is an image formed? 21 2.2 The mathematics of image formation 22 2.2.1 Introduction 22 2.2.2 Linear imaging systems 23 2.2.3 Linear superposition integral 24 2.2.4 The Dirac delta or impulse function 25 2.2.5 The point-spread function 28 vi CONTENTS 2.2.6 Linear shift-invariant systems and the convolution integral 29 2.2.7 Convolution: its importance and meaning 30 2.2.8 Multiple convolution: N imaging elements in a linear shift-invariant system 34 2.2.9 Digital convolution 34 2.3 The engineering of image formation 37 2.3.1 The camera 38 2.3.2 The digitization process 40 2.3.2.1 Quantization 40 2.3.2.2 Digitization hardware 42 2.3.2.3 Resolution versus performance 43 2.3.3 Noise 44 Exercises 46 3 Pixels 49 3.1 What is a pixel? 49 3.2 Operations upon pixels 50 3.2.1 Arithmetic operations on images 51 3.2.1.1 Image addition and subtraction 51 3.2.1.2 Multiplication and division 53 3.2.2 Logical operations on images 54 3.2.3 Thresholding 55 3.3 Point-based operations on images 57 3.3.1 Logarithmic transform 57 3.3.2 Exponential transform 59 3.3.3 Power-law (gamma) transform 61 3.3.3.1 Application: gamma correction 62 3.4 Pixel distributions: histograms 63 3.4.1 Histograms for threshold selection 65 3.4.2 Adaptive thresholding 66 3.4.3 Contrast stretching 67 3.4.4 Histogram equalization 69 3.4.4.1 Histogram equalization theory 69 3.4.4.2 Histogram equalization theory: discrete case 70 3.4.4.3 Histogram equalization in practice 71 3.4.5 Histogram matching 73 3.4.5.1 Histogram-matching theory 73 3.4.5.2 Histogram-matching theory: discrete case 74 3.4.5.3 Histogram matching in practice 75 3.4.6 Adaptive histogram equalization 76 3.4.7 Histogram operations on colour images 79 Exercises 81 CONTENTS vii 4 Enhancement 85 4.1 Why perform enhancement? 85 4.1.1 Enhancement via image filtering 85 4.2 Pixel neighbourhoods 86 4.3 Filter kernels and the mechanics of linear filtering 87 4.3.1 Nonlinear spatial filtering 90 4.4 Filtering for noise removal 90 4.4.1 Mean filtering 91 4.4.2 Median filtering 92 4.4.3 Rank filtering 94 4.4.4 Gaussian filtering 95 4.5 Filtering for edge detection 97 4.5.1 Derivative filters for discontinuities 97 4.5.2 First-order edge detection 99 4.5.2.1 Linearly separable filtering 101 4.5.3 Second-order edge detection 102 4.5.3.1 Laplacian edge detection 102 4.5.3.2 Laplacian of Gaussian 103 4.5.3.3 Zero-crossing detector 104 4.6 Edge enhancement 105 4.6.1 Laplacian edge sharpening 105 4.6.2 The unsharp mask filter 107 Exercises 109 5 Fourier transforms and frequency-domain processing 113 5.1 Frequency space: a friendly introduction 113 5.2 Frequency space: the fundamental idea 114 5.2.1 The Fourier series 115 5.3 Calculation of the Fourier spectrum 118 5.4 Complex Fourier series 118 5.5 The 1-D Fourier transform 119 5.6 The inverse Fourier transform and reciprocity 121 5.7 The 2-D Fourier transform 123 5.8 Understanding the Fourier transform: frequency-space filtering 126 5.9 Linear systems and Fourier transforms 129 5.10 The convolution theorem 129 5.11 The optical transfer function 131 5.12 Digital Fourier transforms: the discrete fast Fourier transform 134 5.13 Sampled data: the discrete Fourier transform 135 5.14 The centred discrete Fourier transform 136 6 Image restoration 141 6.1 Imaging models 141 6.2 Nature of the point-spread function and noise 142