Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


Digital Image Processing Using Matlab - Gonzalez Woods, Notas de estudo de Engenharia Elétrica

Digital Image Processing Using Matlab - Gonzalez Woods

Tipologia: Notas de estudo

2016

Compartilhado em 21/10/2016

heitor-galvao-12
heitor-galvao-12 🇧🇷

4.6

(317)

384 documentos

1 / 302

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe Digital Image Processing Using Matlab - Gonzalez Woods e outras Notas de estudo em PDF para Engenharia Elétrica, somente na Docsity!

cg sa E a Eid a Contents 1.8 27 28 Preface xi Acknowledgments xii About the Authors xiii Introduction 1 Preview 1 Background 1 What Is Digital Image Processing? 2 Background on MATLAB and the Image Processing Toolbox 4 Areas of Image Processing Covered in the Book 5 The Book Web Site 6 Notation 7 The MATLAB Working Environment 7 1.71 The MATLAB Desktop 7 1,72 Using the MATLAB Editor to Create M-Files 9 173 Getting Help 9 1.74 Saving and Retrieving a Work Session 10 How References Are Organized in the Book 11 Summary 11 Fundamentals 12 Preview 12 Digital Image Representation 12 21.1 Coordinate Conventions 13 2.1.2 Images as Matrices 14 Reading Images 14 Displaying Images 16 Writing Images 18 Data Classes 23 Image Types 24 2.6.1 Intensity Images 24 262 Binary lmages 25 2.6.3 ANoteon Terminology 25 Converting between Data Classes and Image Types 25 271 Converting between Data Classes 25 272 Converting between Image Classes and Types 26 Array Indexing 30 . 281 Vector Indexing 30%, 2.8.2 Matrix Indexing 32 283 Selecting Array Dimensions 37 % Contents 29 210 31 3.2 33 35 al E 43 Some Important Standard Arrays 37 Introduction to M-Function Progtamming 38 2.101 M-Files 38 210.2 Operators 40 210.3 Flow Control 49 2.10.4 Code Optimization 55 2105 Interactive 1/0 59 210.6 A Brief Introduction to Cell Arrays and Structures 62 Summary 64 Intensity Transformations and Spatial Filtering 65 Preview 65 Background 65 Intensity Transformation Functions 66 32.1 Function inagjust 66 322 Logaritamic and Contrast-Stretching Transformations 68 323 Some Utility M-Funcions for Intensity Transformations 70 Histogram Processing and Function Plotting 76 331 Generaiing and Plotting Image Histograms 76 3.32 Histogram Equalization 81 333 Histogram Matching (Specification) 84 Spatial Filtering 89 34.4 Lincar Spatial Filtering 89 342 Nonlinear Spatial Filtering 96 Image Processing Toolbox Standard Spatial Filters 99 3.5.1 Lincar Spatial Filters 99 352 Nonlinsar Spatial Filters 104 Summary 107 Frequency Domain Processing 108 Preview 108 The 2-D Discrete Fourier Transform 108 Computing and Visualizing the 2-D DET in MATLAB 112 Filtering in the Frequency Domain 115 43.1 Fundamental Concepts 115 43.2. Basic Steps in DET Filicring 121 43.3 An M-unction for Filtering in the Frequency Domain 122 Obtaining Frequency Domain Filters from Spatial Filters 122 Generating Filters Directly in the Frequency Domain 127 451 Creating Meshgrid Arrays for Use in implementing Filters im the Frequency Domain 128 45.2 Lowpass Frequency Domain Filters 129 453 Wireframe and Surface Plotting 132 i : 4 É i 46 51 5.2 53 61 6.2 63 64 m Contents Sharpening Frequency Domain Filters 136 46.1 Basic Highpass Filtering 136 462 High-Frequency Emphasis Filtering 138 Summary 140 Image Restoration 141 Preview 141 A Model of the Image Degradation/Restoration Process 142 Noise Models 143 5.2.1 Adding Noise with Function imoise 143 522 Generating Spatial Random Noise with a Specified Distribution 144 5.23 Periodic Noise 150 5.24 Estimating Noise Parameters 153 Restoration in the Presence of Noise Only—Spatial Filtering 158 5.3.1 Spatial Noise Filters 159 532 Adaptive Spatial Filters 164 Periodie Noise Reduction by Frequency Domain Filtering 166 Modeling the Degradation Function 166 Direct Inverse Filtering 169 Wiener Filtering 170 Constrained Least Squares (Regularized) Filtering 173 Iterative Nonlinear Restoration Using the Lucy-Richardson Algorithm 176 Blind Deconvolution 179 Geometric Transformations and Image Registration 182 5.11.1 Geometric Spatial Transformations 182 511.2 Applying Spatial Transformations to Images 187 5.11.3 Image Registration 191 Summary 193 Color Image Processing 194 Preview 194 Color Image Representation in MATLAB 194 611 RGBlmages 194 612 Indexed Images 197 61.3 IPT Functions for Manipulating RGB and Indexed Images 199 Converting to Other Color Spaces 204 621 NISC Color Space 204 622 The YCbCr Color Space 205 6.23 The HSV ColorSpace 205 624 The CMY and CMYK Color Spaces 206 6.25 The HSI Color Space 207 The Basics of Color Image Processing 215 Color Transformations 216 vii a Contents 112 Representation 436 112.1 Chain Codes 436 11.22 Polygonal Approximations Using Minimum-Perimeter Polygons 439 11.23 Signatures 449 11.24 Boundary Segments 452 112.5 Skeletons 453 11.3 Boundary Descriptors 455 11.3.1 Some Simple Deseriptors: 455 11.3.2 Shape Numbers 456 11.33 Fourier Descriptors 458 11.3.4 Statistical Moments 462 TL4 Regional Descriptors 463 1.4.1 Functicn regionprops 463 11.42 Texture 464 114.3 Moment Invariants 470 11.5 Using Principal Components for Description 474 Summary 483 12 Object Recognition 484 Preview 484 121 Background 484 12.2 Computing Distance Measures in MATLAB 485 12.3 Recognition Based on Decision-Theoretic Methods 488 123.1 Forming Pattem Vectors 488 123.2 Patterr Matching Using Minimum-Distance Classifiers 489 12.3.3 Matching by Correlation 490 12.34 Optimam Statistical Classifiers 492 123.5 Adaptive Learning Systems 498 124 Structural Recognition 498 12.41 Working with Strings in MATLAB 499 12.42 String Matching 508 Summary 513 Anpendis À Function Summary 514 Anpendix B ICE and MATLAB Graphical User Interfaces 527 togendi ( M-Functions 552 Bibliography 594 ludex 597 stone maço Preface Solutions to problems in the field of digital image processing generally require extensive experimental work involving software simulation and testing with large sets of sample images. Aithough algorithm development typically is based on theoretical underpinnings, the actual implementation of these algorithms almost always requires parameter estimation and, frequently, algorithm revision and comparison of candidate solutions. Thus, selection of a flexible, comprehensive, and we!l-documented software development environment is a key factor that has important implications in the cost, development time, and portability of image processing solutions. In spite of its importance, surprisingly little has been written on this aspect of the field in the form of textbook material dealing with both theoretical principles and soft- ware implementation of digital image processing concepts. This book was written for just this purpose. Its main objective is to provide a foundation for implementing image processing algorithms using modern software tools. A complementary objective was to prepare a book that is self-contained and casily rcadable by individuals witb a basic background in digital image processing, mathematical analysis, and computer pro- gramming, all at à Iovcl typical of that found in a junior/senior curriculum in à techni- cal discipline. Rudimentary knowledge of MATLAB alsa is desirable. To achieve these objectives, we felt that two key ingredients were needed. The first was to select image processing material that is representalive of material cov- ered in a formal course of instruction in this field. The second was to selcct soft- ware tools that are well supported and documented, and which have a wide range of applications in the “real” world. To meet the first objective, most of the theoretical concepts in the following chapters were selected from Digital Image Processing by Gonzalez and Woods, which has been the choice introductory textbook used by educators all over the world for over two decades, The software tools selected are from the MATLAB Image Processing Toolbox (IPT), wixich similarly occupies a position of eminence in both education and industrial applications. A basic strategy followed in the preparation of the book was to provide a seamless integration of well-established theoretical concepts and their implementation using state-of-the-art software tools. The book is organized along the same lines as Digital Image Processing. In this way, the reader has easy access to a more detailed treatment of all the image processing concepts discussed here, as wel! as an up-to-date set of references for further reading. Following this approach made it possible to present theoretical material in a succinet manner and thus we were able to maintain a focus on the software implementation as- pects of image processing problem solutions. Because it works in the MATLAB com- puting environment, the Image Processing Toolbox offers some significant advantages, not only in lhe breadth of its computational tools, but also because it is supported under most operating systems in use today. A unique feature of this book is its empha- sis on showing how to develop new code to enhance existing MATLAB and IPT func- tionality. This is an important feature in an area such as image processing, which, as noted earlier, is characterized by the need for extensive algorithm development and experimental work. After an introduction to the fundamentals of MATLAB functions and program- ming, the book proceeds to address the mainstream areas of image processing. The xi 18 Proface linear spatial fil- major areas covered include intensity transformations, linear and non or tering, filtering in the frequency domain, image restoration and registration, co wavelets, image data compression, morphological image processing, image segmentation, region and boundary representation and description, and object recognition. This material is complemented by numerous illustrations of how to solve image processing problems using MATLAB and IPT functions. In cases where a fune- tion did not exist, a new function was written and documented as part of the instruc- tional focus of the book. Over 60 new functions are included in the foltowing chapters. These functions increase the scope of IPT by approximately 35 percent and also serve the important purpose of further ilustrating how to implement new image processing software solutions. “The material is presented in lextbook format, not as a software manual. Although the book is self-contained, we have established a companion Web site (see. Section 1.5) designed to provide support in à number of areas, For students following a formal course of study or individuals embarked on a program of self study, the site contains tutoriais and reviews on background material, as well as projects and image databases, including all images in the book. For instructors, the site contains classroom presenta- tion materials that include PowerPoint slides of all the images and graphics used in the book. Individuais already tamiliar with image processing and IPT fundamentais will find the site à useful place for up-to-date references, new implementation techniques, and a host of other support material not easily found elsewhere. Al) purchasers of the book are eligible to download executable files of all the new functions developed in the text. “Asis true of most writing eflorts of this nature, progress continues after work on the manuscript stops. For tbis reason, we devoted significant effort to the selection of ma- terial that we believe is fundamental, and whose value is likely to remain applicable in a rapidly evolving body of knowledge. We trust that readers of the book will benefit from this effort and thus find the material timely and useful in their work. image processing, Acknowledgments We are indebted to a number of individuals in academic circles as well as im industry and govermment who have contributed to the preparation of the book. Their contribu- tions have been important in so many different ways that we find it difficult to ac- knowledge them in any other way but aiphabetically. We wish to extend our appreciation to Mongi A. Abidi, Peter 1 Acklam, Serge Beucher, Ernesto Bribiesca, Michael W. Davidson, Courtney Esposito, Naomi Fernandes, Thomas R. Gest, Roger Heady, Brian Johnson, Lisa Kempler, Roy Lurie, Ashley Mohamed, Joseph E. Pascente, David. R. Pickens, Edgardo Felipe Riveron, Michael Robinson, Loren Shure, Jack Sklanski, Sally Stowe, Craig Watson. and Greg Wolodkin. We also wish to ac- knowledge the organizations cited in the captions of many of the figures in the book for their permission to use that material. Special thanks go to Tom Robbins, Rose Kernan, Alice Dworkin, Xiaohong Zhu, Bruce Kenselaar, and Jayne Conte at Prentice Hall for their commitment to excellence in all aspects of the production of the book. Their creativity. assistance, and patience are truly appreciated. RAFAEL C, GONZALEZ RicitarD E. WooDs STEVEN L. EDDINS iu About the Authors Rafael €. Gonzalez R.€. Gonzalez received the B.S.E.E. degree from the University of Miami in 1965 and the ME, and Ph.D. degrees in electrical engineering from the University of Florida. Gainesville, in 1967 and 1970, respectively. He joined the Electrical and Computer Engineering Department at the University of Tennessee, Knoxville (UTK) in 1970, where he became Associate Professor in 1973, Professor in 1978, and Distinguished Service Professor in 1984. He served as Chairman of the de- partment from 1994 through 1997. He is currently a Professor Emeritus of Electri- cal and Computer Engineering at UTK. He is the founder of the Image & Pattern Analysis Laboratory and the Robot- ics & Computer Vision Laboratory at the University of Tennessee. He also found- ed Perceptics Corporation in 1982 and was its president until 1992. The last three years of this period were spent under a full-time employment contract with West- inghouse Corporation. who acquired the company in 1989. Under his direction, Perceptics became highly successful in image processing, computer vision, and Jaser disk storage technologies, In its initial ten years, Perceptics introduced a se- res of innovative products, including: The world's first commercially-avaitable computer vision system for automatically reading the license plate on moving ve- hicles; a series of large-scale image processing and archiving systems used by the US, Navy at six different manutacturing sites throughout the country to inspect the rocket motors of missiles in the Trident Il Submarine Program: the market leading family of imaging boards for advanced Macintosh computers; and a line of trillion-byte laser disk products, He is a frequent consultant to industry and government in the areas of pattern recognition, image processing, and machine learning. His academic honors for work in these fields include the 1977 UTK College of Engineering Faculty Achievement Award; the 1978 UTK Chancellor's Research Scholar Award; thc 1980 Magnavox En- gineering Professor Award: and the 1980 M. E. Brooks Distinguished Professor Award. In 1981 he became an IBM Professor at the University of Tennessee and in 1984 he was named a Distinguished Service Professor there. He was awarded a Dis- tinguished Alumnus Award by the University of Miami in 1985, the Phi Kappa Phi Scholar Award in 1986, and the University of Tennessee's Nathan W. Dougherty Award for Excellence in Engineering in 1992. Honors for industrial accomplishment include the 1987 IEEE Qutstanding Engineer Award for Commercial Development in Tennessee: the :988 Albert Rose National Award for Excellence in Commercial Image Processing; the 1989 B. Otto Wheeley Award (or Exccllence in Technology Transier; the 1989 Coopers and Lybrand Entrepreneur of the Year Award; the 1992 IERE Region 3 Outstanding Engineer Award; and the 1993 Automated Imaging As- sociation National Award for Technology Development. o Dr. Gonzalez is author or co-author of over 100 technical articles, two edited books, and five textbooks in the fields of pattern recognition, image processing, and robotics. His books are used in over 500 universities and research institutions throughout the world. He is listed in the prestígious Marquis Who's Who in Amer- ica, Marquis Who's Who in Engineering, Marquis Who's Who in the World, and in 10 other national and international biographical citations. He is the co-holder of two U.S, Patents, and has been an associate editor of the ZEEE Transactions on xiii Chopter 1 3 Introduction from The MathWorks, Inc. (see Section 1.3). The material in the present book shares the same design, notation, and style of presentation as the Gonzalez- Woods book, thus simplifying cross-referencing between the two. The book is self-contained. To master its contents, the reader should have introductory preparation in digital image processing, either by having taken a formal course of study on the subject at the senior or first-year graduate level, or by acquiring the necessary background in a program of self-study. It is as- sumed also that the reader has some familiarity with MATLASB, as well as rudimentary knowledge of the basics of computer programming, such as that acquired in a sophomore- or junior-level course on programming in a techni- cally oriented language. Because MATLAB is an array-oriented language, basic knowledge of matrix analysis also is helpful. The book is based on principles. It is organized and presented in a textbook format, not as a manual, Thus, basic ideas of both theory and soflware are ex- plained prior to the development of any new programming concepts. The ma- terial is illustrated and clarified further by numerous examples ranging from medicine and industrial inspection to remote sensing and astronomy. This ap- proach allows orderly progression from simple concepts to sophisticated im- plementation of image processing algorithms. However, readers already familiar with MATLAB, IP, and image processing fundamentais can procced directly to specific applications of interest, in which case the functions in the book can be used as an extension of the family of IPT functions. All new func- tions developed in the book are fully documented, and the code for each is included either in a chapter or in Appendix C. Over 60 new functions are developed in the chapters that follow. These functions complement and extend by 35% the set of about 175 functions in IPT. In addition to addressing specific applications, the new functions are clear examples of how to combine existing MATLAB and IPT functions with new code to develop prototypie solutions to a broad spectrum of problems in digi- tal image processing. The toolbox functions, as well as the functions developed in the book, run under most operating systems. Consult the book Web site (sec Section 1.5) for a complete list. MBA what Is Digital Image Processing? An image may be defined as a two-dimensional function, (+, y), where x and » are spatial coordinates, and the amplitude of f at any pair of coordinates (x, 3) is called the intensity or gray level of the image at that point. When x, y. and the amplitude values of f are all finite, discrete quantities, we call the image a digital image. The field of digital image processing reters to processing digital images by means of a digital computer. Note that a digital image is com- posed of a finite number of elements, each of which hes a particular location and value, These elements are referred to as picture elements, image elements. peis, and pixels. Pixel is the term most widely used to denote the elements of a digital image. We consider these definitions formaliy in Chapter 2. 1.2 8 What Is Digital Image Processing? Vision is the most advanced of our senses, so it is not surprising that images play the single most important role in human perception. However, unlike hu- mans, Who are limited to the visual band of the clectromagnetic (EM) spec- trum, imaging machines cover almost the entire EM spectrum. ranging from gamma to radio waves, They can operate also on images generated by sources that humans are not accustomed to associating with images. These include ul- trasound, electron microscopy, and computer-generated images. Thus, digital image processing encompasses a wide and varied field of applications. There is no general agreement among authors regarding where image pro- cessing stops and other related areas, such as image analysis and computer vi- sion, start. Sometimes a distinction is made by defining image processing as a discipline in which both Lhc input and output of a process are images. We be- lieve this to be a limiting and somewhat artificial boundary. For example, under this definition, even the trivial task of computing the average intensity of an image would not be considered an image processing operation. On the other hand, there are fields such as computer vision whose ultimate goal ís to usc computers to emulate human vision, including learning and being able to make inferences and take actions based on visual inputs. This area itself is a branch of artificial intelligence (AI), whose objective is to emulate human in- telligence. The field of AT is in its carliest stages of infancy in terms of devel- opment, with progress having been much slower than originally anticipated. The area of image analysis (also called image understanding) is in between image processing and computer vision, There are no clear-cut boundaries in the continuum from image processing atone end to computer vision at the other, However, one useful paradigra is to consider three types of computerized processes in this continuum: low, mid-, and high-level processes. Low-level processes involve primitive operations such as image preprocessing to reduce noise, contrast enhancement, and image sharpening. A low-level process is characterized by the fact that both its inputs and outputs are images. Mid-level processes on images involve tasks such as segmentation (partitioning an image into regions or objecis), description of those objects to reduce them to a form suitable for computer processing, and classification (recognition) of individual objects. A mid-level process is charac- terized by the fact that its inputs generally are images, but its outputs are at- tributes extracted from those images (e.g., edges, contours, and the identity of individual objects). Finally, higher-level processing involves “making sense” of an ensemble of recognized objects, as in image analysis. and, at the far end of the continuum, performing the cognitive functions normaily associated with human vision. Based on the preceding comments, we see that a logical place ofoverlap be- tveen image processing and image analysis is the area of recognition of individual regions or objects in an image. Thus, what we callin this book dígira! image processing encompasses processes whose inputs and outputs are images and, in addition, encompasses processes that extract attributes from images. up to and including the recognition of individual objects. As a simple iliustration 3 Chapter 1 34 Introduction to clarify these concepts, consider the area of automated analysis of text. The processes of acquiring an image of the area containing the text, preprocessing, that image, extracting (segmenting) the individual characters, describing the characters in a form suitable for computer processing, and recognizing those individual characters, are in Lhe scope of what we call digital image processing in this book. Making sense of the content of the page may be viewed as being in the domain of image analysis and even computer vision, depending on the level of complexity implied by the statement “making sense.” Digital image processing, as we have defined it, is used successfully in a broad range of areas of exceptional social and economic value. EE Background on MATLAB and the Image Processing Toolbox MATLAB is a high-performance language for technical computing. Et inte- grates computation, visualization, and programming in an easy-to-use environ- ment where problems and solutions are expressed in familiar mathematical notation. Typical uses include the folowing: Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including grapbical user interface building MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows formulating solutions to many technical computing problems, especially those involving matrix representa- tions, in a fraction of the time it would take to write a program in a scalar non- interactive language such as C or Fortran. The name MATLAB stands for marrix laboratory, MATLAB was written originally to provide casy access to matrix software developed by the LIN- PACK (Linear System Package) and EISPACK (Eigen System Package) pro- jects. Today, MATLAB engines incorporate the LAPACK (Linear Algebra Package) and BLAS (Basic Linear Algebra Subprograms) libraries, constitut- ing the state of the art in software for matrix computation. In university environments, MATLASB is the standard computational tool for iniroductory and advanced courses in mathematics, engincering, and science. In industry, MATLASB is the computational tool of choice for research, develop- ment, and analysis. MATLAB is complemented by a family of application- specific solutions called oolboxes. The Image Processing Toolbox is a collection of MATLAB functions (called M-funcions or M-files) that extend the capabili- ty of the MATLAB environment for the solution of digital image processing problems. Other toolboxes that sometimes are used to complement IPT are the Signal Processing, Neural Network, Fuzzy Logic. and Wavelet Toolboxes, 1.4 8 Areas of Image Processing Covered in the Book The MATLAB Student Version includes a fullfeatured version of MATLAB. The Student Version can be purchased at significant discounts at university bookstores and at the MathWorks' Web site (wwwmathworks.com). Student versions of add-on products, including the Image Processing Toolbox, also are available. ZEa Areas of Image Processing Covered in the Book Every chapter in this book contains the pertinent MATLAB and IPT material necded to implement the image processing methods discussed. When a MAT- LAB or IPT function does not exist to implement a specific method, a new function is developed and documented. As noted earlier, a complete listing of every ncw function is included in the book. The remaining eleven chapters cover material in the following areas. Chapter 2: Fundamentals. This chapter covers the fundamentais of MATLAB notation, indexing, and programming concepts. This material serves as founda- tion for the rest of the book. Chapter 3: Intensity Transformations and Spatial Filtering, This chapter cov- ers in detail how to use MATLAB and IPT to implement intensity transfor- mation functions. Linear and nonlinear spatial filtors are covered and illustrated in detail. Chapter 4: Processing in the Frequency Domain. The material in this chapter shows how to use IPT functions for computing the forward and inverse fast Fourier transforms (FFTS), how to visualize the Fourier spectrum, and how to implement filtering in the frequency domain. Shown also is a method for gen- erating frequency domain filters from specified spatial filters. Chapter 5: Image Restoration, Traditional linear restoration methods, such as the Wiener filter, are covered in this chapter. Iterative, nonlinear methods, such as the Richardson-Lucy method and maximum-likelihood estimation for blind deconvolution, are discussed and ilustrated. Gcometric corrections and image registration also are covered, Chapter 6: Color Image Processing. This chapter deals with pseudocolor and full-color image processing. Color models applicable to digital image process- ing are discussed, and IPT functionality in color processing is extended via im- plementatíon of additional color models. The chapter also covers applications of color to edge detection and region segmentation. Chapter 7; Wavelets. In ils current form, IPT does not have any wavclet Lrans- forms. A set of wavelet-related functions compatible with the Wavelet Toolbox is developed in this chapter that will allow the reader to impilement all the wavelet-transform concepts discussed in the Gonzalez-Woods book. Chapter 8: Image Compression. The toolbox does not have any data compres- Sion functions. In this chapter, we develop a set of functions that can be used for this purpose. 5 3 Workspace Browser Chapter E Introduction 4/7 Marias Desktop Command Window Figure Window — e IGURE 1.1 The MATLAB desktop and its principal components, The Command Window is where the user types MATLAB commands and expressions at the prompt (>>) and where the outputs of those commands are displayed. MATLAB defines the workspace as the set of variables that the user creates in a work session. The Workspace Browser shows these variables and some information about them. Double-clicking on a variable in the Work- space Browser launches the Array Editor, which can be used to obtain infor- mation and in some instances edit certain properties of the variable. The Current Directory tab above the Workspace tab shows the contents of the current directory, whose path is shown in the Current Directory Window. For example, in the Windows operating system the path might be as follows: CiuMATLABWork, indicating that directory “Work” is a subdirectory of the main directory “MATLAB; which is installed in drive C. Clicking on the arrow in the Current Directory Window shows a list of recently used paths. Clicking on the button to the right of the window allows the uscr to change the current directory. 17 = The MATLAB Working Environment MATLAB uses a search path to find M-files and other MATLAB related files, which are organized in directories in the computer file system. Any file run in MATLAB must reside in the current directory or in a directory that is on the search path. By default, the files supplied wita MATLAB and MaihWorks toolboxes are included in the search path. The casiest way to see which directories are on the search path, or to add or modify a search path, is to select Set Path from the File menu on the desktop, and then use the Set Path dialog box. It is good practice to add any commonty used di- rectories to the search path to avoid repeatedly having the change the cur- rent directory. The Command History Window contains a record of the commands a user has entered in the Command Window, including both current and previous MATLAB sessions. Previously entered MATLAB commands can be selected and re-executed from the Command History Window by right-clicking on a command or sequence of commands. This action Iaunches a menu from which to select various options in addition to executing the commands. This is a use- ful feature when experimenting with various commands in à work session. 1.7.2 Using the MATLAB Editor to Create M-Files The MATLASB editor is both a text editor specialized for creating M-files and a graphical MATLAB debugger. The editor can appear in a window by itself, orit can be a subwindow in the desktop. M.files are denoted by the extension .m, as in pixeldup.m The MATLAB editor window has numerous pull-down menus for tasks such as saving, viewing, and debugging files. Because it per- forms some simple checks and also uses color to differentiate berween various elements of code, this text editor is recommended as the tool of choice for writing and editing M-functions. To open the editor, type edit at the promptin the Command Window. Similarly, typing edit fiLename at the prompt opens the M-file filename .m in an editor window, ready for editing. As noted earli- er, the file must be in the current directory, or in a directory in the search path. 17.3 Getting Help The principal way to get help online* is to usc the MATLAB Help Browser, opened as a separate window either by clicking on the question mark symbol (?) on the desktop toolbar, or by typing helpbrowser at the prompt in the Command Window. The Help Browser is a Web browser integrated into the MATLAB desktop that displays Hiypertext Markup Language (HTML) docu- ments The Help Browser consists of two panes, the Aelp navigaror pane, used to find information, and the display pare, used to view the information. Self-explanatory tabs on the navigator panc are used to perform a search. For example, help on a specific function is obtained by selecting the Search tab, selecting Function Name as the Search Type, and then typing in the func- tion name in the Search for field. It is good practice to open the Help Browser *Use af (he term onfine in this book refers to information. such as help files, available in a local computer system, not on the Internel. 9 Chapter 1 5% Introduction at the beginning of a MATLAB session to have help readily available during code development or other MATLASB task. Another way to obtain help for a specific function is by typing doc followed by the function name at the command prompt. For example, typing doc format displays documentation for the function called format in the display pane of the Help Browser. This command opens the browser if it is not already open. M-functions have two types of information that can be displayed by the user. The first is called the HJ fine, which contains the function name and a one-line description. The second is a block of explanation called the Help text block (these are discussed in detail in Section 2.10.1). Typing help at the prompt followed by a function name displays both the HI line and the Help text for that function in the Command Window. Occasionally, this information can be more up to date than the information in the Help browser because it is extracted directly from the documentation of the M-function in question. Typ- ing lookfor followed by a keyword displays all the H1 lines that contain that keyword. This function is useful when looking for a particular topic without knowing the names of applicable functions. For example, typing 1ookfor edge at the prompt displays all the H1 lines containing that keyword. Because the HI line contains the function name, it then becomes possible to look at specif- ic functions using the other help methods. Typing 1ookfor edge all at the prompt displays the H1 line of all functions that contain the word edge in ei- ther the H! line or the Help text block. Words that contain the characters edge also are detected. For example, the Hi line of a function containing the word polyedge in the HI líne or Help text would also be displayed. ILis common MATLAB terminology to use the term help page when refer- ring to the information about an M-function displayed by any of the preceding approaches, excluding 1lookfor. It is highly recommended that the reader be- come familiar with all these methods for obtaining information because in the following chapters we often give only representative syntax forms for MAT- LAB and IPT functions. This is necessary cilher because of space limitations or to avoid deviating from a particular discussion more than is absolutely nec- essary. In these cases we simply introduce the syntax required to execute the function in the form required at that point. By being comfortable with online search methods. the reader can then explore a function of interest in more de- tail with lite effort, Finally, the MathWorks' Web site mentioned in Section 1.3 contains a large database of help matcrial, contributed functions, and other resources that should be utilized when the online documentation contains insufficient infor- mation about a desired topic. :1.4 Saving and Retrieving a Work Session There are several ways to save and load an entire work session (the contents of the Workspace Browser) or selected workspace variables in MATLAB. The simplest is as follows. To save the entire workspace, simply right-click on any blank space in the Workspace Browser window and select Save Workspace As from the menu that appears. This opens a directory window that allows naming the file and se- tecting any foider in the system in which to save it. Then simply click Save. To save a selected variable from the Workspace, select the variable with a left click and then righr-click on the highlighted area. Then select Save Selection As ftom the ment that appears. This again opens a window from which a fold- er can be selected to save the variable. To select multiple variables, use shift- click or control-click in the familiar manner, and then use the procedure just described for a single variable. All files are saved in double-precision, binary format with the extension .mat. These saved files commonty are referred to as MATfites. For example, a session named, say, mywork. 2003 02.10, would ap- pear as the MAT-iile mywork 2003 02 10.mat when saved. Similarly, a saved image called final, image (which is a single variable in the workspace) will appear when saved as final image.mat. To load saved workspaces and/or variables, left-click on the foder icon on the toolbar of the Workspace Browser window. This causes a window to open from which à folder containing the MAT-files of interest can be selected. Double-clicking on a selected MAT-ile or selecting Open causes the contents of the file to be restored in the Workspace Browser window. Tt is possible to achieve the same results described in the preceding para- graphs by typing save and Load at the prompt, with the appropriate file names and path information. This approach is not as convenient, but it is used when formats other than those available in the menu method are required. As an exercise, the reader is encouraged to use the Help Browscr to learn more about these two functions. How References Are Organized in the Book Ali references in the book are listed in the Bibliography by author and date, as in Soille [2003]. Most of the background references for the theoretical content of the book are from Gonzalez and Woods [2002]. In cases where this is not true, the appropriate new references are identified at the point in the discus- sion where (hey are needed. References that are applicable to all chapters, such as MATLAB manuals and other general MATLAB references, are so identified in the Bibliography. Summary Tn addition to a brief introduction to notation and basic MATLAB tools. the material in this chapter emphasizes the importance of a comprehensive prototyping environ- ment in the solution of digital image processing problems. In the following chapter we begin to lay the foundation needed to understand IPT functions and introduce a set of fundamental programming concepts that are used throughout the book. The material in Chapters 3 through 12 spans a wide cross section of topics that are in the mainstream Of digital image processing applications. However, although the topics covered are var- ied, the discussion in those chapters follows the same basic theme of demonstrating how combining MATLAB and IPT functions with new code can be used to solve a broad spectrum of image-processing problems. a Summary u £ Chapter 2 44 Fundamentals “ATLAB and IPT cumentation use dh he terms matrix and areav, mostly in rchangeabiy, How- “em, keep in mind ua matrix is vo nensional, whereas um array can have ty finite dimension. IPT documentation refers to the coordinates in Fig. 2.1(b) as pixel coordi- nates. Less frequently, the toolbox also employs another coordinate conven- tion called spatial coordinates, which uses x to refer to columns and y to refers to rows, This is the opposite of our use of variables x and y. With very few ex- ceptions, we do not use IPT's spatial coordinate convention in this book, but the reader will definitely encounter the terminology in IPT documentation. 2.1.2 Images as Matrices The coordinate system in Fig. 2.1(2) and the preceding discussion lead to the following representation for a digitized image function: F(0,0) F(0,1) MON = 1) (1) = 10,9) fa) or =1) HM 1,0) HM 1,1) HM -,N-1) The right side of this equation is a digital image by definition. Each element of this array is called an image element, picture elemens, pixel, or pel. The terms image and pixel! are used throughout the rest of our discussions to denote a digital image and its elements. 'A digital image can be represented naturally as a MATLAB matrix: DD 10,2) f(2,1) f(2,2) TON) - T(2,N) FM, 1) t(M,2) TCM, N) where f(1, 1) = f(0,0) (note the tse of a monospace font to denote MAT- LAB quantities). Clearly the two representations are identical, except for the shift in origin. The notation f (p, q) denotes the element located in row p and column q. For example. f (6, 2) is the element in the sixth row and second col- umn of the matrix f. Typically we use the letters M and N, respectively, to de- note the number of rows and columns in a matrix. À 1 xN matrix is called a row vector, whereas an Mx 1 matrix is called a column vector. A 1x1 matrixis a scalar. Matrices in MATLAB are stored in variables with names such as A, a, RGB, real array, and so on. Variables must begin with a letter and contain only letters, numerals, and underscores. As noted in the previous paragraph, all MATLAB quantities in this book are written using monospace characters. We use conventional Roman, italic notation, such as f(x, y), for mathematical expressions, Reading Images Images are read into the MATLAB environment using function imread, whose syntax is imread('filename') 2.2 3 Reading lmages 15 Format Recognized Náme Description Extensions TIFF Tagged Image File Format «tifo tifr JPEG Joint Photographic Experis Group .jpg..jpeg GIF Graphics Interchange Format” .gif BMP Windows Bitmap .bmp PNG Portable Network Graphics .png XWD XWindow Dump «xd fGIF is supported by imread, but not by inurite. Here, filename is a string containing the complete namc of the image file (in- eluding any applicable extension). For example, the command line > f = imread('chestxray. jpg'); reads the JPEG (Table 2.1) image chestxray into image array f. Note the use of single quotes (') to delimit the string filename. The semicolon at the end of a command line is used by MATLAB for suppressing output. If a semicolon js not included, MATLAB displays the results of the operation(s) specified in that line, The prompt symbol (>>) designates the beginning of a command live, as it appears in the MATLAB Command Window (see Fig. 1.1). When, as in the preceding command line, no path information is included in filename, imread reads the file from the current directory (see Section 1,7.1) and, if that fails, it tries to find the file in the MATLAB search path (see Section 1.7.1). The simplest way to read an image from a specified directory is to include a full or relative path to that directory in filename. For example, > f = imread('D:imyimagesichestxray.jpg'); teads the image from a folder called my images on the D: drive, whereas >> f = imread('. myimagesichestxray. jpg'); Teads the image from the my images subdirectory of the current working di- fectory. The Current Directory Window on the MATLAB desktop toolbar displays MATLAB's current working directory and provides a simple, man- Val way to change it. Table 2.1 lists some of the most popular image/graphics formats supported by imread and imwrite (imyrite is discussed in Section 2.4). Function size gives the row and column dimensions of an image: >> size(f) ans = 1024 1024 TABLE 2.1 Some of the image/graphics formats supported by imreag and imwrite, starting with MATLAB 6.5, Earlier versions support a subset of these formais. Sec online help fora complete list or supported formats. In Windows directo- ries also are called folders. i6 Chopter2 % Fundamentals Ain size, tany HATLAB and IPT inctions com retura more than one out st argument, Mutei- le output angumenes rest be melosed within quare brackess, [ ) This function is particular!y useful in programming when used in the following form to determine automatically the size of an image: >> [M, Nj = size(f); “This syntax returns the number of rows (4) and columns (N) in the image. The uhos function displays additional information about an array. For in- stance, the statement >> whos f gives Name size Bytes class f 1024x1024 1048576 vint8 array Grand total is 1048576 elements using 1048576 bytes The uint8 entry shown refers to one of several MATLAB data classes dis- cussed in Scclion 2.5. A semicolon at the end of a whos line has no effect, so normally one is not used. » Displaying Images images are displayed on the MATLAB desktop using function inshow which has the basic syntax: inshow(f, 8) where f is an image array, and 6 is the number of intensity levels used to dis- play it. I£ G is omitted, it defaults to 256 levels. Using the syntax imshow(f, [low high]) displays as black all values less than or equal to low, and as white all values greater than or equal to high, The values in between are displayed as interme- diate intensity values using the default number of levels. Finally, the syntax imshow(f, [ 1) sets variable low to the minimum value of array f and high to its maximum value. This form of inshow is useful for displaying images that have a low dy- namic range or that have positive and negative values. Function pixval is used frequently to display the intensity values of indi- vidual pixels interactively. This function displays a cursor overlaid on an image, As the cursor is moved over the image with the mouse, the coordi- nates of the cursor position and the corresponding intensity values are 2.3 w Displaying lmages 17 shown on à display that appears below the figure window. When working with color images, the coordinates as well as the red, green, and blue compo- nents are displayed. If the left button on the mouse is clicked and then held pressed, pixval displays the Euclidean distance between the initial and cur- rent cursor locations. The syntax form of interest here is pixval which shows Lhe cursor on the last image displayed. Clicking the X button on the cursor window turns it off. 8 (a) The following statements read from disk an image called rose Si2.tif, EXAMPLE 21; extract basic information about the image, and display it using imshow: Image reading and displaying. >> f = imread('rose 512.tif'); >> whos f Name Size Bytes Class f 512x512 262144 uint8 array Grand total is 262144 elements using 262144 bytes >> imshow(f) A semicolon at the end of an imshow line has no effect, so normally one is not used. Figure 2.2 shows what the output looks like on lhe screen. The figure number appears on the top, left of the window. Note the various pull-down menus and utility buttons. They are used for processes such as scaling, saving, and exporting the contents of the display window. In particular, the Edit menu has functions for editing and formatting results before they are printed or saved to disk. FIGURE 2.2 Screen capture showing how an image appears on the MATLAB desktop. However, in most ofthe examples throughout this book, onty the imapes themselves are shown. Note the figure number on the top, left part of the window. 20 Chupter 2 4 Fundamentals ab ed ef FIGURE 2,4 (a) Original image. (b) through (£) Results of using jpg quality values q=50,25,15,5, and 0, respectively. False contouring begins to be barely noticeable for q=15 [image (d)] but is quite visible lorq=5and q=0. See Example 2.11 for a function that cremes alt re images in Fig. 2.4 using a simple for loop. where Filesize is in bytes. The number of bytes in the original image is com- puted simply by multiplying Width by Height by BitDepth and dividing the result by 8. The result is 486948. Dividing this by FileSize gives the compres- sion ratio: (486948/13849) = 35,16. This compression ratio was achieved while maintaining image quality consistent with the requirements of the appli- 2.4 4 Writing Images 21 cation. In addition to the obvious advantages in storage space, this reduction allows the transmission of approximately 35 times the amount of uncom- pressed data per unit time. The information fields displayed by imfinfo can be captured into a so- called structure variabte that can be used for subsequent computations. Using the preceding image as an example. and assigning the name K to the structure variable, we use the syntax >> K = imfinfo('bubbles25.jpg'); to store into variable K all the information generated by command imfinfo. The information generated by imfinfo is appended to the structure variable by means of fields, separated from K by a dot. For example, the image height and width are now stored in structure fields K. Height and K. Width. As an illustration, consider Lhe following usc of structure variable K to com- pute the compression ratio for bubbles25. jpg: > K = imfinfo('bubbles25.jpg'); >> image bytes = K.Width*K.Height*K.BitDepth/8; >> compressed bytes K.FilesSize; >> compression ratio = image bytes/compressed bytes compression ratio = 35.1612 Note that imfinfo was used in two different ways. The first was to type imfinfo bubbles25.jpg at the prompt, which resulted in the information being displayed on the screen. The second was to type K = imfinfo('bub- bles25.jpg'), which resulted in the information generated by imfinfo being stored in K. These two different ways of calling imf info are an example of command-function duality, an unportant concept that is explained in more detail in the MATLAB online documentation. s A more gencral imwrite syntax applicable only to tif images has the form imyrite(g, 'filename,tif', 'compression', 'parameter', . 'resolution', [colres rowres]) where 'parameter! can have one of the following principal values: 'none" indicates no compression: 'packbits! indicates packbils compression (the default for nonbinary images); and *coitt indicates ceitt compression (the default for binary images). The 1 X 2 array [colres rowres] contains two in- tegers that give the column resolution and row resolution in dots-per-unit (the default values are [7272]). For example, if the image dimensions are in inches, colres is the number oí dots (pixels) per inch (dpi) in the vertical direction, and similarly for rowres in the horizontal direction. Specifying the resolution by a single scalar, res, is equivalent to writing [res res]. Structures are dis- cussed in Sections 2.166 and 11.11. To fear more abom command function dltality, consuit che help page on this topic. See Section 1.73 regarding help pages. JF a stosement does ne fit on one line, use en ellipsis (rhree periods), followed by Return or Enter, o indicate thet the starememt continues on the next line, There are no spaces berween the periods. 2 Chapter 2 & Fundamentals XAMPLE 2,3: “sing imurite arameters. FURE 2.5 Effects of tanging the dpi solution while eping the «umber Of pixels -onstant VA 450 x 450 age at 200 dpi ze = 2.25 x 2.25 inches). ) The same 3x 450 image, 1at 300 dpi ze = 15X * Sinches) Yriginal image urtesy of Lixi, 2) 3 Figure 2.5(a) is an 8-bit X-ray image of a circuit board generated during quality inspection. It is in jpg format, at 200 dpi, The image is of size 450 x 450 pixels, so its dimensions are 2.25 X 2.25 inches. We want to store this image in tif format, with no compression, under the name sf.In addition, we want to reduce the size of Lhe image o 1.5 X 1.5 inches while keeping the pixel count at 450 x 450. The following statement yields the desired result: >> imwrite(f, 'sf.tit','compression', 'none', 'resolution', ... 1300 300]) The values of the vector [colres rowres] were determined by multiplying 200 dpi by the ratio 2.25/1.5, which gives 300 dpi. Rather than do lhe compu- tation manually we could write >> res = round(200*2.25/1.5); >> imurite(f, 'sf.tif', 'compression', "none! , 'resolution', res) where function round rounds its argument to the nearest integer. It is impor- tant to note that the number of pixels was not changed by these commands, Only the scale of the image changed. The original 450 X 450 image at 200 dpi is of size 2.25 X 2.25 inches. The new 300-dpi image is identical, except that its 450 x 450 pixeis are distributed over a 1.5 X 1.5-inch area. Processes such as this are useful for controlling the size of an image in a printed document with- out sacrificing resolution. ” Often, it is necessary to export images to disk the way they appear on the MATLAB desktop. This is especially true with plots, as shown in the next chapter. The conients of a figure window can be exported to disk in two ways. The first is to use the File pull-down menu in the figure window (see Fig. 2.2) and then choose Export. With this option, the user can select a location, file name, and formal. More control over export parameters is obtained by using the print command: print —fno —dfileformat -rresno filename where no refers to the figure number in the figure window of interest. fileformat refers to one of the file formats in Table 2.1, resna is the resolu- tion in dpi, and filename is the name we wish to assign the file, For example, to export the contents of the figure window in Fig. 2.2 as a tif file at 300 dpi, and under the name hi res rose, we would type > print —f1 -dtiff -r300 hi res rose This command sends the file hi res rose. tif to the current directory. IÉ we simply type print at the prompt, MATLAB prints (to the default printer) the contents of the last figure window displayed. It is possible also to specify other options with print, such as a specific printing device. Data Classes Although we work with integer coordinates, the valnes of pixels themselves are not restricted to be integers in MATLAB. Table 2.2 lists the various data classes” supported by MATLAB and IPT for representing pixel values. The first eight entries in the table are referred to as nsmeric data classes. The ninth entry is the char class and, as shown, the last entry is referred to as the logica! data class. All numerie computations in MATLAB are done using double quantities, 50 this is also a frequent data class encountered in image processing applica- tions, Class uint8 also is encountered frequently, especially when reading data from storage devices, as 8-bit images are the most common representa- tions found in practice, These two data classes, class logical, and, to a lesser degree, class uint18, constitute the primary data classes on which we focus in this book. Many IPT functions, however, support all the data classes listed in Table 2.2. Data class double requires 8 bytes to represent a number, uint8 and int8 require 1 byte each, uint16 and int 16 require 2 bytes, and uint3s, h MATLAB documentation often uses the terms «ata class and «ara tupe interchangeably tn this book, We reserve use of the term type for images, as discussed in Section 2.6. 2.5 44 Data Classes 23 26 Chapter 2 & Fundamentals ffunerion change- Jass, discusserl in Section 2.2.9, cam be sed for changing an pu image to a spee- ed class, ABLE 2,3 unetions in [PT tor converting etween image “asses and types. 2e Table 6.3 for conversions that pply specifically +color images. array, B. is generated by the command B = double (A). This conversion is used routinely throughout the book because MATLAB expects operands in nu- merical computations to be double-precision, floating-point numbers. If € is an array of class double in which all values are in the range [0,255] (but possibly containing fractional values), it can be converted to an uint8 array with the command D = uinte(C). Tfan array of class double has any values outside the range [0,255] and itis converted to class uint8 in the manner just described, MATLAB converts to O all values that are less than 0, and converts to 255 all values that are greater than 255. Numbers in between are converted to integers by discarding their fractional parts. Thus, proper scaling of a double array so that its elements are in the range [0,255] is necessary before converting it to uint8. As indicated in Section 2.6.2, converting any of the numeric data classes to logical results in an array with logical 1s in locations where the input array had nonzero values, and logical 0s in places where the input array contained Os. 2.7.2 Converting between Image Classes and Types “The toolbox provides specific functions (Table 2.3) that perform the scaling necessary to convert between image classes and types. Function im2uint8 de- tects the data class of the input and performs all the necessary scaling for the toolbox to recognize the data as valid image data. For example, consider the following 2 X 2 image f of class double, which could be the result of an inter- mediate computation: Performing the conversion >> 9 = imtuinte(f) yields the result g = o 128 191 255 Name Converts Input to: Valid Input fmage Data Classes imBuintê uinta logical, uínta, uintt6, and double imuintio uíntis logical.uint8, uint18, and double mat2gray double (in range [0,1]) double 1 imêdouble double logical, uintê, uint16. and double im2by logical Uintê, vint16. and double | / 27 & Converting between Data Classes and Image Types from which we see that function im2uint8 sets to O all values in the input that are less than O, sets to 255 all values in the input that are greater than 1, and multiplies ai! other values by 255. Rounding the results of the muttiplication to the nearest integer completes the conversion. Note that the rounding behavior of imBuint8 is different from the data-class conversion function uint& dis- cussed in the previous section, which simply discards [ractional parts. Converting an arbitrary array of class double to an array of class double scaled to the range (0, 1] can be accomplished by using function mategray whose basic syntax is g = matêgray(A, [Amin, Amax]) where image g has values in the range O (black) to 1 (white). The specified pa- rameters Amin and Amax are such that values Jess than Amin in A become 0 in g. and values greater than Amax in A correspond to 1 in g. Writing >> g = matêgray(A); sets the valucs of Amin and Amax to the actual minimum and maximum values in A. The input is assumed to be of class double. The output also is of class double. Function im2aouble converts an input to class double, If the input is of class uint8, uínt16, or logícal, function im2double converts it to class double with values in the range [0, 1). If the input is already of class double, im2double returns an array that is equal to the input. For example, if an array of class double results from computations that yield values outside the range [0, 1), inputting this array into im2double will have no effect. As mentioned in the preceding paragraph, a double array having arbitrary values can be con- verted to a double array with values in the range [0, 1] by using function matagray. As an illustration, consider the class uintB image! >> h = Uint8([25 50; 128 200]); Performing the conversion >> g = imPdouble(h); yields the result 9 = 0.0980 o.1961 0.4706 O.7843 from which we infer that the conversion when the input is of class uint8 is done simply by dividing each valve of the input array by 255. If the input is of class uint16 the division is by 65535. Section 2.8.2 explains the use ol square brackets and semicolons to specity a matrix. 28 f=[12;34] fa 1 2 3 4 to binary such that values 1 and 2 become O and the other two values become 1. First we convert it to the range [0,1]: >> q = mat2gray(f) g= o 0.,9333 0.6657 1.0000 Then we convert it to binary using a threshold, say, of value 0.6: >> gb = imBbw(g, 0.6) gb = o 0 1 1 27 & Converting between Data Classes and Image Types As mentioned in Section 2.5, we can generate a binary array directly using re- jational operators (Section 2.10.2). Thus we get the same result by writing »gb=-f>2 gb = We could store in a variable (say, gbv) the fact that gb is a logical array by using the islogical function, as follows: >> gbv = islogical(gb) gbv = 1 (b) Suppose now lhat we want to convert gb to a numerical array of Os and 1s of class double. This is done directly: >> gbd = imadouble(gb) gbd = If gb had been a numeric array of class uint8, applying imadouble to it would have resulted in an array with values [o] o 0.0039 0.0039 because imadouble would have divided ali the elements by 255. This did not happen in the preceding conversion because im2double detected that the input was a logical array, whose only possible values are O and 1. If the input in fact had been an vint8 numeric array and we wanted to convert it ta class double while keeping the O and 1 values, we would have converted the array by writing >> gbd = double(gb) gba = 29