center for computational visualization department of

7
CHAPMAN & HALL/CRC MATHEMATlCAL AND COMPUTATlONAL lMAGlNG SCIENCES Series Editors Chandrajit Bajaj Center for Computational Visualization The University of Texas at Austin Guillermo Sapiro Department of Electrical and Computer Engineering Duke University Aims and Scope This series aims to capture new developments and summarize what is known over the whole spectrum of mathematical and computational imaging sciences. It seeks to encourage the integration of mathematical, statistical and computational methods in image acquisition and processing by publishing a broad range of textbooks, reference works and handbooks. The titles included in the series are meant to appeal to students, researchers and professionals in the mathematical, statistical and computational sciences, application areas, as well as interdisciplinary researchers involved in the field. The inclusion of concrete examples and applications, and programming code and examples, is highly encouraged. Published Titles Image Processing for Cinema by Marcelo Bertalmlo Image Processing and Acquisition using Python by Ravishankar Chityala and Sridevi Pudipeddi Statistical and Computational Methods in Brain Image Analysis by Moo K. Chung Rough Fuzzy Image Analysis: Foundations and Methodologies by Sankar K. Pal and James F. Peters Theoretical Foundations of Digital Imaging Using MATLAB ® by Leonid P. Yaroslavsky .• Proposals for the series should be submitted to the series editors above or directly to: CRC Press, Taylor & Francis Group 3 Park Square, Milton Park, Abingdon, OX14 4RN, UK CJ-IAI'MAN & 1-!ALL/CRC i'v\ATH EMATICAL AND CO tv\ PUTATIONAL I MAG INC SCI l NCES C( I I u 1 1 .L u \ r I D Image Processing and Acquisition using Python Ravishankar Chityala University of Minnesota at Minneapolis USA Sridevi Pudipeddi SriRav Scientific Solutions Minneapolis, Minnesota, USA 0 Boca Raton London New York CRC Press is an imprint of the Taylor & Francis Group an informa business A CHAPMAN & HALL BOOK

Upload: others

Post on 24-Jan-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Center for Computational Visualization Department of

CHAPMAN & HALL/CRC MATHEMATlCAL AND COMPUTATlONAL

lMAGlNG SCIENCES

Series Editors

Chandrajit Bajaj Center for Computational Visualization

The University of Texas at Austin

Guillermo Sapiro Department of Electrical

and Computer Engineering Duke University

Aims and Scope

This series aims to capture new developments and summarize what is known over the whole spectrum of mathematical and computational imaging sciences. It seeks to encourage the integration of mathematical, statistical and computational methods in image acquisition and processing by publishing a broad range of textbooks, reference works and handbooks. The titles included in the series are meant to appeal to students, researchers and professionals in the mathematical, statistical and computational sciences, application areas, as well as interdisciplinary researchers involved in the field. The inclusion of concrete examples and applications, and programming code and examples, is

highly encouraged.

Published Titles Image Processing for Cinema

by Marcelo Bertalmlo

Image Processing and Acquisition using Python by Ravishankar Chityala and Sridevi Pudipeddi

Statistical and Computational Methods in Brain Image Analysis by Moo K. Chung

Rough Fuzzy Image Analysis: Foundations and Methodologies by Sankar K. Pal and James F. Peters

Theoretical Foundations of Digital Imaging Using MATLAB® by Leonid P. Yaroslavsky

.•

Proposals for the series should be submitted to the series editors above or directly to: CRC Press, Taylor & Francis Group

3 Park Square, Milton Park, Abingdon, OX14 4RN, UK

CJ-IAI'MAN & 1-!ALL/CRC i'v\ATH EMATICAL AND CO tv\ PUTATIONAL I MAG INC SCI l NCES

C( I I .c~f' u 11

.L ~ u \ r I ~-I D

Image Processing and Acquisition using Python

Ravishankar Chityala University of Minnesota at Minneapolis

USA

Sridevi Pudipeddi SriRav Scientific Solutions

Minneapolis, Minnesota, USA

0 ~y~~F~~~~~"P Boca Raton London New York

CRC Press is an imprint of the Taylor & Francis Group an informa business

A CHAPMAN & HALL BOOK

Page 2: Center for Computational Visualization Department of

MATLAB' is a trademark of The MathWorks, Inc. and is used with permission. The Math Works does not warrant the accuracy of the text or exercises in this book. This book's use or discussion of MATLAB' software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MAT LAB" software.

CRC Press Toy! or & l'ranci< Group 6000 Broken Sound Parkway NW. Boca Raton, FL 33187-2742

f:l 2014 by Taylor & fra ncis Group, LL CRC Press is an imprint of Taylor & Francis Group, an Inform a business

No claim to original U.S. Government works

Printed on acid-free paper Version Date: 20131206

International Standard Book Number-13: 978-1-4665-8375-7 (Hardback)

This book contains informati on obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all material s or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apo logi ze to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint.

Except n permitted under U.S. Copyright Law, no part of this book may be reprinted. reproduced, t rnnsmlned, or tltfl l•.ed in an)• form by a ny electronic, mechanical, or o thet' menns, now know n or hereafter invented. includ­Ing photocopying, micro(i[ming, and recording, or In nny infot·mation storage or re.trl ·Vlll sy•tcm, without written permission from the publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://www.copyright. com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe.

Library of Congress Cataloging-in-Publication Data

Chityala, Ravishankar, author. Image processing and acquisition using Python I Ravishankar Chityala, Sridevi Pudipeddi.

pages em. -- (Chapman & Hali/CRC mathematical and computational imaging sciences series)

Summary: "If title belongs to a series, the exact series title that will appear in the book is: Series number, exactly as it will appear in the book: Will the first-named author listed in Author Information appear as the first-named author for all other volumes of the series?"-­Provided by publisher.

Includes bibliographical references and index . ISBN 978-1-4665-8375-7 (hardback) 1. Image processing. 2. Python (Computer program language) I. Pudipeddi, Sridevi, author.

ll. Title. •"

TA1637.C486 2014 006.6'63--dc23

Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com

and the CRC Press Web site at http://www.crcpress.com

2013047010

To our parents and siblings

Page 3: Center for Computational Visualization Department of

..

Contents

List of Figures xvii

List of Tables xxiii

Foreword XXV

Preface xxvii

Introduction xxxi

About the Authors xxxiii

List of Symbols and Abbreviations XXXV

I Introduction to Images and Computing using

Python 1

1 Introduction to Python 3

1.1 Introduction ... 3

1.2 What is Python? 4

1.3 Python Environments 5

1.3.1 Python Interpreter 6

1.3.2 Enthought Python Distribution (EPD) 6

1.3.3 PythonXY .. . . . . . .. . . . . . 7

1.4 Running a Python Program •• 0 0 •••• 8

1.5 Basic Python Statements and Data Types 8

1.5.1 Data Structures 11 1.6 Summary 19 ..... . .

vii

Page 4: Center for Computational Visualization Department of

viii Contents

1.7 Exercises

2 Computing using Python Modules

2.1 Introduction ...... .

2.2 Python Modules

2.2.1 Creating Modules

2.2.2 Loading Modules

2.3 Numpy ........ .

2.3.1 Numpy Array or Matrices? .

2.4 Scipy

2.5 Matplotlib

2.6 Python Imaging Library

2. 7 Scikits . . . . . . . . . .

2.8 Python OpenCV Module

2.9 Summary

2.10 Exercises

3 Image and its Properties

3.1 Introduction . . . . . .

3.2 Image and its Properties

3.2.1 Bit Depth ....

3.2.2 Pixel and Voxel

3.2.3 Image Histogram

3.2.4 Window and Level

3.2.5 Connectivity: 4 or 8 Pixels

3.3 Image Types

3.3.1 JPEG

3.3.2 TIFF .

3.3.3 DICOM

3.4 Data Structures for Image Analysis

3.4.1 Reading Images ..

3.4.2 Displaying Images .

3.4.3 Writing Images . .

20

23

23

23

24

24

26

30

31

32

33

33

34

34

35

37

37

38

38

39

41

42

43

44

44

44

45

49

49

50

50

Contents

3.5

3.6

Programming Paradigm

Summary

3. 7 Exercises

II Image Processing using Python

4 Spatial Filters

4.1 Introduction

4.2 Filtering ..

4.2.1 Mean Filter

4.2.2 Median Filter

4.2.3 Max Filter . .

4.2.4 Min Filter . .

4.3 Edge Detection using Derivatives

4.3.1 First Derivative Filters . .

4.3.2 Second Derivative Filters .

4.4 Summary

4.5 Exercises

5 Image Enhancement

5.1 Introduction ...

5.2 Pixel Transformation

5.3 Image Inverse ....

5.4 Power Law Transformation

5.5 Log Transformation

5.6 Histogram Equalization

5. 7 Contrast Stretching

5.8 Summary

5. 9 Exercises

6 Fourier Transform

6.1 Introduction .

6.2 Definition of Fourier Transform . . .

6.3 Two-Dimensional Fourier Transform

ix

51

53

53

55

57

57

58

60

64

66

68

69

71

79

85

86

89

89

89

91

92

97

99

103

106

107

109

109

110

113

Page 5: Center for Computational Visualization Department of

X

6.4

6.5

Contents

6.3.1 Fast Fourier Transform using Python

Convolution ............. .

6.4.1 Convolution in Fourier Space

Filtering in Frequency Domain

6.5.1 Ideal Lowpass Filter ..

6.5.2 Butterworth Lowpass Filter

6.5.3 Gaussian Lowpass Filter ..

6.5.4 Ideal Highpass Filter ....

6.5.5

6.5.6

6.5.7

Butterworth Highpass Filter

Gaussian Highpass Filter .

Bandpass Filter

6.6 Summary

6. 7 Exercises

115

118

119

120

120

123

125

127

130

132

134

137

138

7 Segmentation 139

139

139

141

144

149

151

153

7.1 Introduction

7.2 Histogram Based Segmentation

7.3

7.2.1 Otsu's Method ... .

7.2.2 Renyi Entropy .... .

7.2.3 Adaptive Thresholding

Region Based Segmentation

7.3.1 Watershed Segmentation

7.4 Segmentation Algorithm for Various Modalities 161

7.4.1 Segmentation of Computed Tomography Image 161

7.4.2 Segmentation of MRI Image . . . . . . . . . . . 161

7.4.3 Segmentation of Optical and Electron Micro-

scope Image

7.5 Summary

7. 6 Exercises

8 Morphological Operations

8.1 Introduction

8.2 History

162

162

163

165

165

165

Contents

8.3 Dilation . . . . ...... .

8.4

8.5

8.6

8.7

8.8

8.9

Erosion

Grayscale Dilation and Erosion

Opening and Closing . . .

Hit-or-Miss

Thickening and Thinning

8.8.1 Skeletonization

Summary

8. 10 Exercises

9 Image Measurements

9.1

9.2

9.3

Introduction .. .

Labeling .. .. .

Hough Transform

9.3.1 Hough Line

9.3.2 Hough Circle

9.4 Template Matching

9.5 Summary

9. 6 Exercises

III Image Acquisition

10 X-Ray and Computed Tomography

10.1 Introduction ....

10.2 History . . . . . .

10.3 X-Ray Generation

10.3.1 X-Ray Tube Construction

10.3.2 X-Ray Generation Process

10.4 Material Properties ....... .

10.4.1 Attenuation . .. ... . .

10.4.2 Lambert Beer Law for Multiple Materials

10.5 X-Ray Detection

10.5.1 Image Intensifier

10.5.2 Multiple-Field II

Xl

166

171

175

176

179

184

185

186

187

189

189

189

194

194

197

201

205

205

207

209

209

209

210

210

212

216

216

218

219

220

221

Page 6: Center for Computational Visualization Department of

xii Contents

10.5.3 Flat Panel Detector (FPD) .

10.6 X-Ray Imaging Modes

10.6.1 Fluoroscopy ..

10.6.2 Angiography . .

10.7 Computed Tomography (CT)

10.7 .1 Reconstruction . . . .

10.7.2 Parallel Beam CT ...

10. 7.3 Central Slice Theorem

10.7.4 Fan Beam CT .

10.7.5 Cone Beam CT

10.7.6 Micro-CT ..

10.8 Hounsfield Unit (HU)

10.9 Artifacts ... ... .

10.9.1 Geometric Misalignment Artifacts .

10.9.2 Scatter ........... .

10.9.3 Offset and Gain Correction .

10.9.4 Beam Hardening

10.9.5 Metal Artifacts

10.10 Summary

10.11 Exercises

11 Magnetic Resonance Imaging

11.1 Introduction . . . . . . . . .

11.2 Laws Governing NMR and MRI

11.2.1 Faraday's Law ...

11.2.2 Larmor Frequency.

11.2.3 Bloch Equation ..

11.3 Material Properties ....

11.3.1 Gyromagnetic Ratio

11.3.2 Proton Density ...

11.3.3 T1 and T2 Relaxation Times

11.4 NMR Signal Detection . . . . . . .

11.5 MRI Signal Detection or MRI Imaging

..

223

224

224

224

226

227

227

228

232

233

234

236

237

238

238

240

241

242

243

244

247

247

248

248

249

250

251

251

252

253

255

256

Contents

11.5.1 Slice Selection ... .

11.5.2 Phase Encoding .. .

11.5.3 Frequency Encoding

11.6 MRI Construction

11.6.1 Main Magnet ..

11.6.2 Gradient Magnet

11.6.3 RF Coils .... .

11.6.4 K-Space Imaging

11.7 T1, T2 and Proton Density Image

11.8 MRI Modes or Pulse Sequence

11.8.1 Spin Echo Imaging .. .

11.8.2 Inversion Recovery .. .

11.8.3 Gradient Echo Imaging .

11.9 MRI Artifacts . . . . .

11.9 .1 Motion Artifact

11.9.2 Metal Artifact .

11.9.3 Inhomogeneity Artifact

11.9.4 Partial Volume Artifact .

11.10 Summary

11.11 Exercises

12 Light Microscopes

12.1 Introduction .

12.2 Physical Principles . . .

12.2.1 Geometric Optics

12.2.2 Numerical Aperture .

12.2.3 Diffraction Limit ..

12.2.4 Objective Lens ...

12.2.5 Point Spread Function (PSF)

12.2.6 Wide-Field Microscopes ...

12.3 Construction of a Wide-Field Microscope 12.4 Epi-Illumination 12.5

Fluorescence Microscope .. ....... .

xiii

258

258

259

259

259

260

261

262

263

265

265

266

267

268

269

271

271

272

272

273

275

275

276

276

277

278

280

281

282

282

284

284

Page 7: Center for Computational Visualization Department of

XlV Contents

12.5.1 Theory ......... .

12.5.2 Properties of Fluorochromes

12.5.3 Filters . . . .

12.6 Confocal Microscopes

12.7 Nipkow Disk Microscopes

12.8 Confocal or Wide-Field?

12.9 Summary

12 .1 0 Exercises

13 Electron Microscopes

13.1 Introduction ....

13.2 Physical Principles

13.2.1 Electron Beam

13.3

13.2.2 Interaction of Electron with Matter

13.2.3 Interaction of Electrons in TEM .

13.2.4 Interaction of Electrons in SEM

Construction of EM

13.3.1 Electron Gun

13.3.2 Electromagnetic Lens

13.3.3 Detectors ....

13.4 Specimen Preparations

13.5 Construction of TEM

13.6 Construction of SEM

13.7 Summary

13.8 Exercises

A Installing Python Distributions

A.1 Windows .......... .

A.l.1 PythonXY . . . . . . .

A.l.2 Enthought Python Distribution .

A.l.3 Updating or Installing New Modules

A.2 Mac or Linux ............. .

A.2.1 Enthought Python Distribution ...

284

285

287

288

289

291

292

293

295

295

296

297

298

299

300

301

301

303

304

306

307

308

309

311

313

313

313

316

316

318

318

Contents

A.2.2 Installing New Modules .

B Parallel Programming Using MPI4Py

B.1 Introduction to MPI ......... B.2 Need for MPI in Python Image Processing B.3 Introduction to MPI4Py

B.4 Communicator ..... B.5 Communication .....

B.5.1 Point-to-Point Communication

B.5.2 Collective Communication

B.6 Calculating the Value of PI

C Introduction to ImageJ

C.1 Introduction ..

C.2 ImageJ Primer

D MATLAB® and Numpy Functions

D.1 Introduction ........... .

Bibliography

Index

XV

318

323

323

324

325

326

327

327

329

331

333

333

334

331

337

341

351