Contents

List of Figures and Tables xiii

Acknowledgment xix

Foreword xxi

Preface xxv

Why Should I Care About Java? xxv

Who Should Read This Book? xxv

Why Not Use the Advanced Imaging Package? xxvi

This Is Not Just a Textbook xxvii

What Chapters Do I Need to Read? xxvii

How Can I Use the Web to Teach and Learn More Image Processing? xxx

1. Introduction 1

1.1. What is This Book About? 1

1.1.1. What is Image Processing? 2

1.1.2. What is Java? 2

1.1.3. Why Do Image Processing in Java? 3

1.2. Who Should Read This Book? 3

1.3. What Will You Learn? 4

2. Event Processing and the AWT 5

2.1. The Frame Class 7

2.2. Interaction 11

2.2.1. The EventTester 11

2.2.1.1. Intercepting Menu Events 15

2.2.1.2. The ShortCutFrame 16

2.2.1.3. Petri Nets 19

2.2.2. BooLog 27

2.2.3. ExpandoLog 28

2.2.4. Class Summary 31

2.2.5. Class Usage 31

2.3. Summary 33

2.4. Suggested Projects 34

3. Displaying and Filtering Images 39

3.1. Image Representation 40

3.2. Scalar Numeric Data Types 42

3.3. Arrays in Java 43

3.4. Drawing in Java 47

3.5. The ImageFrame Class 48

3.5.1. Class Summary 49

3.5.2. Class Usage 49

3.6. The FilterFrame 53

3.6.1. Class Summary 53

3.6.2. Class Usage 53

3.6.3. Class Implementation 54

3.7. The GrabFrame Class 55

3.7.1. Class Summary 55

3.7.2. Class Usage 56

3.7.3. Class Implementation 57

3.8. SnellWlx Class and Test Patterns 58

3.8.1. Class Summary 59

3.8.2. Class Implementation 59

4. Homogeneous Point Processing 61

4.1. The Histogram Class 64

4.1.1. Class Summary 65

4.1.2. Class Usage 66

4.2. Homogeneous Point Processing Functions 68

4.2.1. Using the Pow Function 70

4.2.2. Using Linear Transforms 74

4.2.3. The Uniform Non-Adaptive Histogram Equalization 79

4.2.4. Maple and Exponential Non Adaptive Histogram Equalization 84

4.2.5. Adaptive Histogram Equalization 89

4.3. The TransformTable Class 92

4.3.1. Class Summary 93

4.3.2. Class Usage 93

4.4. The NegateFrame Class 93

4.4.1. Class Summary 95

4.4.2. Class Usage 96

4.5. Summary 102

5. Digital Image Processing Fundamentals 103

5.1. The Human Visual System 104

5.2. Overview of Image Processing 107

5.2.1. Digitizing a Signal 108

5.2.2. Image Digitization 116

5.2.3. Image Display 118

6. Input Streams 121

6.1. Getting a FileName 123

6.2. File Input Stream 126

6.3. The Ubyte Class 136

6.4. The StreamSniffer Class 137

6.4.1. Class Summary 138

6.4.2. Class Usage 139

7. Image File Readers and Writers 141

7.1. Getting a Filename and Writing a PPM File 142

7.2. Writing a Program That Writes a Program 144

7.3. Writing Lossless 24-Bit Color Image Files 148

7.4. Reading GZIP Compressed PPM Files 154

7.5. The SaveFrame Class 157

7.5.1. Class Summary 157

7.5.2. Class Usage 158

7.6. The OpenFrame Class 159

7.6.1. Class Summary 160

7.6.2. Class Usage 161

7.7. The Timer Class 162

7.7.1. Class Summary 162

7.7.2. Class Usage 162

7.7.3. Class Example: Loop Interchange 163

7.8. The ProgressFrame 169

7.8.1. Class Summary 169

7.8.2. Class Usage 169

7.9. The WriteGif 171

7.9.1. Class Summary 171

7.9.2. Class Usage 172

7.10. The WritePPM Class 172

7.10.1. The PPM 173

7.10.2. Class Summary 173

7.10.3. Class Example 173

7.11. Summary 174

7.12. Projects 174

8. Direct Convolution 175

8.1. The Mathematical Basis of Convolution 176

8.2. The Cyclic Convolution, Correctness and Speed 182

8.3. Generating Convolution Kernels - The Mat Class 184

8.3.1. Class Summary 185

8.3.2. Class Usage 185

8.4. Implementing Direct Convolution 189

8.4.1. Class Summary 189

8.4.2. Class Usage 189

8.5 Summary 191

9. Spatial Filters 193

9.1. Blurring 193

9.2. Median Filtering 201

9.3. High-Pass 214

9.4. The SpatialFilterFrame 218

9.4.1. Class Summary 218

9.4.2. Class Usage 219

9.5. Summary 228

9.6. Suggested Projects 229

10. Convolution-based Edge Detection 231

10.1. Laplace Filter 231

10.2. Roberts 243

10.3. Sobel and the Double Templates 245

10.4. Comparing Edge Detectors 252

10.5. Summary 262

10.6. Projects 263

10.7. EdgeFrame Class 265

10.7.1. Class Summary 265

10.7.2. Class Usage 266

11. Morphological Filtering 275

11.1. Set Theory 276

11.2. Erosion and Dilation 279

11.3. Opening and Closing 289

11.4. Outlining 292

11.5. Thinning and Skeletonization 296

11.6. Summary 306

11.7. Projects 307

11.8. The MorphFrame 308

11.8.1. Class Summary 308

11.8.2. Class Usage 310

12. Boundary Processing 313

12.1. Hough Transform 313

12.2. Simple Edge Tracing 323

12.3. Edge Detection 326

12.4. Summary 335

12.5. Projects 336

12.6. The BoundaryFrame 338

12.6.1. Class Summary 338

12.6.2. Class Usage 339

12.7. The MartelliFrame 342

12.7.1. Class Summary 342

12.7.2. Class Usage 343

13. Chromatic Light 347

13.1. Introduction to Color 347

13.2. Tristimulus 349

13.2.1. RGB and XYZ for Illuminant D65 352

13.2.2. Sub-Sampling 355

13.2.2. YIQ and NTSC Encoders 359

13.3. Linear Cut Color Reduction 361

13.4. The Median Cut Algorithm 362

13.4. Summary 368

13.5. Projects 368

13.6. The ColorHash Class 371

13.6.1. Class Summary 371

13.6.2. Class Usage 371

13.7. The ColorFrame 372

13.7.1. Class Summary 372

13.7.2. Class Usage 373

14. Warping 377

14.1. Translation 378

14.2. Scaling 379

14.3. Rotation 381

14.4. Shear 382

14.5. The AffineFrame 382

14.6. Applying the Transforms to an Image 386

14.7. Inferring a 3 Point Affine Mapping 389

14.8. Inferring a 4 Point Bilinear Map 392

14.9. Effects 398

14.10. Projects 401

15. Unitary Transforms 405

15.1. Introduction 405

15.2. The Discrete Fourier Transform 407

15.3. The Wavelet Transform 414

15.4. The Haar Basis 416

15.5. Implementing the Two-Dimensional Haar Lifting 425

15.6. Writing a Wavelet Encoded File 429

15.7. Summary 430

15.8. Projects 431

Appendix A. Book Resources On-line 435

Appendix B. The Kahindu Interface 437

B.1. Icon Design 438

B.2. Icon Design By Drawing 440

B.3. Icon Design By Typing 442

B.4. Saving the Icon as Java 443

Appendix C. The Structure of Kahindu 445

Appendix D. Index of Fields and Methods 469

Literature Cited 497

Index 513

Colophon 531