100% found this document useful (4 votes)
16 views

Complete Download Image operators image processing in Python First Edition Kinser PDF All Chapters

Image

Uploaded by

capayhusek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
16 views

Complete Download Image operators image processing in Python First Edition Kinser PDF All Chapters

Image

Uploaded by

capayhusek
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Image operators image processing in Python First


Edition Kinser

https://textbookfull.com/product/image-operators-image-
processing-in-python-first-edition-kinser/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Image Operators: Image Processing in Python 1st Edition


Jason M. Kinser

https://textbookfull.com/product/image-operators-image-processing-in-
python-1st-edition-jason-m-kinser/

textboxfull.com

Mathematical Image Processing Kristian Bredies

https://textbookfull.com/product/mathematical-image-processing-
kristian-bredies/

textboxfull.com

Computing Colour Image Processing Alan Parkin

https://textbookfull.com/product/computing-colour-image-processing-
alan-parkin/

textboxfull.com

Image Processing and Computer Vision in iOS Oge Marques

https://textbookfull.com/product/image-processing-and-computer-vision-
in-ios-oge-marques/

textboxfull.com
Digital Image Processing Practical Approach Borko Furht

https://textbookfull.com/product/digital-image-processing-practical-
approach-borko-furht/

textboxfull.com

Computer Vision and Image Analysis Digital Image


Processing and Analysis 4th Edition Scott E Umbaugh

https://textbookfull.com/product/computer-vision-and-image-analysis-
digital-image-processing-and-analysis-4th-edition-scott-e-umbaugh/

textboxfull.com

Image Processing and Pattern Recognition Based on Parallel


Shift Technology First Edition Bilan

https://textbookfull.com/product/image-processing-and-pattern-
recognition-based-on-parallel-shift-technology-first-edition-bilan/

textboxfull.com

Nonlinear Eigenproblems in Image Processing and Computer


Vision Guy Gilboa

https://textbookfull.com/product/nonlinear-eigenproblems-in-image-
processing-and-computer-vision-guy-gilboa/

textboxfull.com

Digital image interpolation in MATLAB First Edition Kok

https://textbookfull.com/product/digital-image-interpolation-in-
matlab-first-edition-kok/

textboxfull.com
Image Operators
Image Operators
Image Processing in Python

Jason M. Kinser
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2019 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
No claim to original U.S. Government works

Printed on acid-free paper


International Standard Book Number-13: 978-1-4987-9618-7 (Hardback)
This book contains information 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
materials 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 apologize 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 as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in
any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, micro-
filming, and recording, or in any information storage or retrieval system, 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 identifi-
cation and explanation without intent to infringe.

Library of Congress Cataloging-in-Publication Data

Names: Kinser, Jason M., 1962- author.


Title: Image operators: image processing in Python/Jason M. Kinser.
Description: First edition. | Boca Raton, FL: CRC Press/Taylor & Francis Group, [2019] |
“A CRC title, part of the Taylor & Francis imprint, a member of the Taylor & Francis Group,
the academic division of T&F Informa plc.” | Includes bibliographical references and index.
Identifiers: LCCN 2018017140 (print) | LCCN 2018017764 (ebook) | ISBN 9780429451188 (eBook) |
ISBN 9780429835940 (Adobe PDF) | ISBN 9780429835933 (ePUB) |
ISBN 9780429835926 (Mobipocket) | ISBN 9781498796187 (hardback: acid-free paper)
Subjects: LCSH: Image processing—Digital techniques. | Python (Computer program language)
Classification: LCC TA1637 (ebook) | LCC TA1637 .K48 2019 (print) | DDC 006.6—dc23
LC record available at https://lccn.loc.gov/2018017140

Visit the Taylor & Francis Web site at


http://www.taylorandfrancis.com

and the CRC Press Web site at


http://www.crcpress.com
This book is dedicated to my beautiful wife – Sue Ellen.
Contents

Python Codes ................................................................................................................................... xv


Preface.............................................................................................................................................xxi
Software and Data.........................................................................................................................xxiii
Author ............................................................................................................................................ xxv

PART I Image Operators

Chapter 1 Introduction ............................................................................................................. 3


1.1 Scripting in Python ......................................................................................... 3
1.2 Installation ...................................................................................................... 4
1.2.1 Example Codes .................................................................................. 4
1.2.2 Establishing a Work Space................................................................. 4
1.2.3 The Spyder Interface.......................................................................... 5
1.2.4 Intent of the Text ................................................................................ 5

Chapter 2 Operator Nomenclature ........................................................................................... 7


2.1 Image Notation ............................................................................................... 7
2.2 Operators......................................................................................................... 8
2.2.1 Creation Operators ............................................................................. 8
2.2.2 Channel Operators ............................................................................. 9
2.2.3 Informational Operators................................................................... 12
2.2.4 Intensity Operators........................................................................... 14
2.2.5 Geometric Operators........................................................................ 16
2.2.6 Transformation Operators ................................................................ 16
2.2.7 Expansion Operators........................................................................ 17
2.3 Combinations and Reduced Notation ........................................................... 18
2.4 Summary....................................................................................................... 19

Chapter 3 Scripting in Python ................................................................................................ 21


3.1 Basic Python Skills ....................................................................................... 21
3.1.1 Variables........................................................................................... 21
3.1.2 Strings .............................................................................................. 22
3.1.3 Type Conversions with Strings ........................................................ 23
3.2 Tuples, List, Dictionaries, and Sets .............................................................. 23
3.2.1 Tuple ................................................................................................ 23
3.2.2 Slicing .............................................................................................. 23
3.2.3 Lists.................................................................................................. 25
3.2.4 Dictionaries ...................................................................................... 25
3.2.5 Sets................................................................................................... 26
3.3 Flow Control ................................................................................................. 26
3.3.1 The if Command .............................................................................. 27
3.3.2 The while Command........................................................................ 28

vii
viii Contents

3.3.3 Break and Continue.......................................................................... 29


3.3.4 The For Loop ................................................................................... 29
3.3.5 The map and lambda Functions ....................................................... 31
3.3.6 Image Operators and Control........................................................... 31
3.4 Input and Output ........................................................................................... 32
3.4.1 Reading and Writing Text Files ....................................................... 32
3.4.2 Pickling Files ................................................................................... 32
3.5 Defining Functions........................................................................................ 33
3.5.1 Function Components ...................................................................... 33
3.5.2 Returns ............................................................................................. 34
3.5.3 Default Arguments........................................................................... 35
3.5.4 Function Help................................................................................... 35
3.6 Modules ........................................................................................................ 36
3.7 Errors ............................................................................................................ 38
3.8 NumPy .......................................................................................................... 39
3.8.1 Creating Arrays................................................................................ 39
3.8.1.1 Zeros and Ones ................................................................ 39
3.8.1.2 Random............................................................................ 40
3.8.1.3 Geometric Shapes............................................................ 41
3.8.1.4 Conversion of Numerical Data ........................................ 41
3.8.2 Manipulating Arrays ........................................................................ 42
3.8.2.1 Display Option................................................................. 42
3.8.2.2 Converting Arrays ........................................................... 42
3.8.2.3 Simple Math .................................................................... 42
3.8.2.4 Multiplying Vectors ......................................................... 43
3.8.2.5 Multiplying Matrices ....................................................... 44
3.8.2.6 Array Functions ............................................................... 44
3.8.2.7 Decisions ......................................................................... 47
3.8.2.8 Advanced Slicing............................................................. 48
3.8.2.9 Universal Functions ......................................................... 48
3.8.2.10 Sorting ............................................................................. 49
3.8.3 Indices .............................................................................................. 51
3.9 SciPy ............................................................................................................. 52
3.9.1 Loading and Saving Images............................................................. 53
3.9.2 Examples from ndimage .................................................................. 54
3.9.2.1 Rotation and Shift............................................................ 54
3.9.2.2 Center of Mass................................................................. 55
3.10 Summary....................................................................................................... 56

Chapter 4 Digital Images ....................................................................................................... 59


4.1 Images in Python .......................................................................................... 59
4.2 Resolution ..................................................................................................... 59
4.2.1 Intensity Resolution ......................................................................... 59
4.2.2 Spatial Resolution ............................................................................ 61
4.3 Digital Formats ............................................................................................. 63
4.3.1 Bitmaps ............................................................................................ 63
4.3.2 JPEG ................................................................................................ 63
4.3.3 GIF ................................................................................................... 63
4.3.4 TIFF ................................................................................................. 64
Contents ix

4.3.5 PNG.................................................................................................. 65
4.3.6 Other Compressions......................................................................... 65
4.4 Summary....................................................................................................... 65

Chapter 5 Color ...................................................................................................................... 67


5.1 The RGB Color Model ................................................................................. 67
5.2 The HSV Color Model.................................................................................. 69
5.3 The YUV Family .......................................................................................... 72
5.4 CIE L*a*b*................................................................................................... 73
5.5 Improvements in Recognition....................................................................... 74
5.6 Summary....................................................................................................... 77

PART II Image Space Manipulations


Chapter 6 Geometric Transformations ................................................................................... 81
6.1 Selections...................................................................................................... 81
6.2 Linear Translation......................................................................................... 83
6.2.1 Simple Shifting ................................................................................ 83
6.2.2 NonInteger Shifts ............................................................................. 84
6.3 Scaling .......................................................................................................... 85
6.4 Rotation......................................................................................................... 87
6.5 Dilation and Erosion ..................................................................................... 88
6.6 Coordinate Mapping ..................................................................................... 90
6.7 Polar Transformations................................................................................... 90
6.7.1 Theory .............................................................................................. 91
6.7.2 Python Implementation.................................................................... 92
6.7.3 Example ........................................................................................... 94
6.8 Pincushion and Barrel Transformations ...................................................... 95
6.9 Other Transformations.................................................................................. 96
6.9.1 Generic Transformations.................................................................. 97
6.9.2 Affine Transformation...................................................................... 98
6.10 Summary....................................................................................................... 99

Chapter 7 Image Morphing .................................................................................................. 101


7.1 Warp............................................................................................................ 101
7.1.1 Marking Fiducial Points................................................................. 101
7.1.2 Image Dancer ................................................................................. 101
7.1.3 Delaunay Tessellation .................................................................... 103
7.1.4 Applying the Warp ......................................................................... 104
7.2 Average Face............................................................................................... 106
7.3 Image Morphing ......................................................................................... 107

Chapter 8 Principle Component Analysis ............................................................................ 111


8.1 The Purpose of PCA ................................................................................... 111
8.2 Covariance Matrix ...................................................................................... 111
8.3 Eigenvectors................................................................................................ 112
8.4 PCA............................................................................................................. 113
x Contents

8.4.1 Distance Tests ................................................................................ 116


8.4.2 Organization Example ................................................................... 116
8.4.3 RGB Example ................................................................................ 121
8.5 First Order Nature of PCA.......................................................................... 124
8.6 Summary..................................................................................................... 124

Chapter 9 Eigenimages ........................................................................................................ 127


9.1 Eigenimages................................................................................................ 127
9.1.1 Large Covariance Matrix ............................................................... 128
9.1.2 Python Implementation.................................................................. 128
9.1.3 Face Recognition Example ............................................................ 130
9.1.4 Natural Eigenimages...................................................................... 131

PART III Frequency Space Manipulations

Chapter 10 Image Frequencies............................................................................................... 137


10.1 Complex Numbers ...................................................................................... 137
10.2 Theory......................................................................................................... 138
10.3 Digital Fourier Transform........................................................................... 138
10.3.1 FFT in Python ................................................................................ 139
10.3.2 Signal Reconstruction .................................................................... 139
10.4 Properties of a Fourier Transform............................................................... 140
10.4.1 DC Term......................................................................................... 140
10.4.2 Conservation of Energy ................................................................. 141
10.4.3 Replication ..................................................................................... 142
10.4.4 Addition ......................................................................................... 142
10.4.5 Shift................................................................................................ 143
10.4.6 Scale............................................................................................... 143
10.4.7 Power Spectrum ............................................................................. 144
10.5 Displaying the Transform ........................................................................... 144
10.6 Simple Shapes............................................................................................. 145
10.6.1 Rectangle........................................................................................ 145
10.6.2 Circle.............................................................................................. 146
10.7 Frequency Bands ........................................................................................ 147
10.8 Windowing.................................................................................................. 149
10.9 Summary..................................................................................................... 152

Chapter 11 Filtering in Frequency Space............................................................................... 153


11.1 Frequency Filtering..................................................................................... 153
11.1.1 Low-pass Filter .............................................................................. 153
11.1.2 High-pass Filter.............................................................................. 154
11.1.3 Band-pass Filter ............................................................................. 155
11.2 Directional Filtering.................................................................................... 156
11.3 Fingerprint Example ................................................................................... 158
11.4 Artifact Removal......................................................................................... 160
11.5 Summary..................................................................................................... 163
11.6 Problems ..................................................................................................... 163
Contents xi

Chapter 12 Correlations ......................................................................................................... 165


12.1 Justification and Theory.............................................................................. 165
12.2 Theory......................................................................................................... 165
12.2.1 Computations in Fourier Space...................................................... 166
12.3 Implementation in Python........................................................................... 167
12.3.1 Brute Force..................................................................................... 167
12.3.2 Method Based on Fourier Transforms ........................................... 168
12.3.3 Example – Geometric Shapes ........................................................ 169
12.3.4 Example – Boat Isolation............................................................... 170
12.4 Composite Filtering .................................................................................... 174
12.5 SDF and MACE.......................................................................................... 175
12.5.1 Fractional Power Filter (FPF) ........................................................ 176
12.5.1.1 Theory............................................................................ 176
12.5.1.2 Manipulating α .............................................................. 177
12.5.1.3 Example......................................................................... 178
12.5.1.4 The Constraints.............................................................. 180
12.5.1.5 Dual FPFs ...................................................................... 182
12.6 Restrictions of Correlations ........................................................................ 184
12.7 Summary..................................................................................................... 184

PART IV Texture and Shape

Chapter 13 Edge Detection .................................................................................................... 189


13.1 Edges........................................................................................................... 189
13.2 The Sobel Filters......................................................................................... 190
13.3 Difference of Gaussians.............................................................................. 191
13.4 Corners........................................................................................................ 193

Chapter 14 Hough Transforms ............................................................................................... 199


14.1 Detection of a Line ..................................................................................... 199
14.2 Detection of a Circle................................................................................... 202
14.3 Application ................................................................................................. 204
14.4 Summary..................................................................................................... 205

Chapter 15 Noise.................................................................................................................... 209


15.1 Random Noise ............................................................................................ 209
15.2 Salt and Pepper Noise................................................................................. 209
15.3 Camera Noise.............................................................................................. 212
15.4 Colored Noise ............................................................................................. 212
15.5 Comparison of Noise Removal Systems .................................................... 212
15.5.1 Smoothing ...................................................................................... 213
15.5.2 Low-Pass Filtering ......................................................................... 214
15.5.3 Erosion and Dilation ...................................................................... 214
15.5.4 Median Filter.................................................................................. 215
15.5.5 Wiener Filter .................................................................................. 216
15.6 Other Types of Noise .................................................................................. 217
15.7 Summary..................................................................................................... 217
xii Contents

Chapter 16 Texture Recognition ............................................................................................ 221


16.1 Data............................................................................................................. 221
16.2 Edge Density............................................................................................... 221
16.2.1 Statistical Method .......................................................................... 221
16.2.2 The Method of Rosenfeld and Thurston ........................................ 223
16.2.3 Wavelet Decomposition and Texture ............................................. 227
16.2.4 Gray-Level Co-Occurrence Matrix ................................................ 230
16.2.4.1 Angular Second Moment............................................... 232
16.2.4.2 Contrast.......................................................................... 232
16.2.4.3 Correlation..................................................................... 233
16.2.4.4 Variance ......................................................................... 234
16.2.4.5 Entropy .......................................................................... 234
16.2.4.6 The Remaining Haralick Metrics .................................. 235
16.3 Filter-Based Methods.................................................................................. 238
16.3.1 Law’s Filters................................................................................... 238
16.4 Summary..................................................................................................... 240

Chapter 17 Gabor Filtering .................................................................................................... 243


17.1 Gabor Filtering............................................................................................ 243
17.2 Edge Response............................................................................................ 245
17.3 Texture Extraction with Gabor Filters ........................................................ 246
17.4 Gabor Filters in Fourier Space.................................................................... 249
17.5 Summary..................................................................................................... 249

Chapter 18 Describing Shape................................................................................................. 251


18.1 Contour Methods ........................................................................................ 251
18.1.1 Chain Code..................................................................................... 251
18.1.2 The Polygon Method...................................................................... 252
18.1.3 Metrics Used to Describe Shape .................................................... 252
18.1.4 Fourier Descriptors ........................................................................ 255
18.1.5 Wavelets ......................................................................................... 258
18.1.6 Elastic Matching ............................................................................ 258
18.2 Region Methods.......................................................................................... 262
18.2.1 Eigenvectors and Eigenvalues........................................................ 262
18.2.2 Shape Metrics................................................................................. 265
18.3 Describing Structure ................................................................................... 267
18.3.1 Curvature Flow .............................................................................. 267
18.3.2 Medial Axis.................................................................................... 269
18.4 Problems ..................................................................................................... 271

PART V Basis

Chapter 19 Basis Sets............................................................................................................. 275


19.1 Discrete Cosine Transform ......................................................................... 276
19.2 Zernike Polynomials................................................................................... 279
19.3 Empirical Mode Decomposition................................................................. 282
19.4 Image Analysis with Basis Sets.................................................................. 285
Contents xiii

Chapter 20 Pulse Images and Autowaves .............................................................................. 293


20.1 Pulse-Coupled Neural Network .................................................................. 293
20.1.1 Mammalian Visual Cortex ............................................................. 293
20.1.2 PCNN............................................................................................. 293
20.1.2.1 Theory............................................................................ 294
20.1.2.2 Pulse Streams................................................................. 294
20.1.2.3 Applications................................................................... 295
20.1.2.4 Operator Notation.......................................................... 296
20.2 Intersecting Cortical Model ........................................................................ 296
20.2.1 Centripetal Autowaves ................................................................... 297
20.2.2 ICM ................................................................................................ 297
20.3 Texture Classification with the ICM........................................................... 298
20.4 Summary..................................................................................................... 300

Appendix A Operators ............................................................................................................. 303


Appendix B Operators in Symbolic Order............................................................................... 325
Appendix C Lengthy Codes..................................................................................................... 327
Bibliography ................................................................................................................................. 333
Index.............................................................................................................................................. 335
Python Codes
1.1 Positioning Python to the user’s directory ............................................................................. 4
1.2 Positioning Python to the user’s directory ............................................................................. 5
2.1 Corresponding Python outline ............................................................................................... 7
2.2 Swapping the color channels ............................................................................................... 11
2.3 Converting an RGB image to a grayscale image ................................................................. 12
2.4 A few informational operations ........................................................................................... 13
2.5 Computing the average of selected pixels............................................................................ 13
2.6 Determining which channel has the most energy ................................................................ 14
2.7 Isolating the man’s cane....................................................................................................... 16
3.1 Creating an integer............................................................................................................... 21
3.2 Simple math functions ......................................................................................................... 22
3.3 Type casting ......................................................................................................................... 22
3.4 Creating strings .................................................................................................................... 22
3.5 Type conversions.................................................................................................................. 23
3.6 Building a name ................................................................................................................... 23
3.7 Tuple .................................................................................................................................... 24
3.8 Extraction............................................................................................................................. 24
3.9 Slicing selected elements ..................................................................................................... 24
3.10 Using a list ........................................................................................................................... 25
3.11 Using a dictionary ................................................................................................................ 26
3.12 Some dictionary functions ................................................................................................... 26
3.13 Some set functions ............................................................................................................... 27
3.14 A simple if statement ......................................................................................................... 27
3.15 A multiple line if statement................................................................................................ 27
3.16 The if-else statement ....................................................................................................... 28
3.17 The elif statement.............................................................................................................. 28
3.18 A compound if statement ................................................................................................... 28
3.19 A while statement............................................................................................................... 29
3.20 Usgin break command........................................................................................................ 29
3.21 Using the continue command ........................................................................................... 30
3.22 The for loop........................................................................................................................ 30
3.23 Using the range command.................................................................................................. 30
3.24 Using the range command in a for loop ........................................................................... 31
3.25 Using the map and lambda functions ................................................................................. 31
3.26 Choosing parameters in a function ...................................................................................... 31
3.27 Choosing parameters in a function ...................................................................................... 32
3.28 Writing to a file .................................................................................................................... 32
3.29 Reading to a file ................................................................................................................... 32
3.30 Pickling a file ....................................................................................................................... 33
3.31 Reading a pickle file............................................................................................................. 33
3.32 Reading a pickle file............................................................................................................. 33
3.33 Defining a function .............................................................................................................. 34
3.34 Return a value from a function ............................................................................................ 34
3.35 Return a tuple from a function ............................................................................................. 34
3.36 Default arguments ................................................................................................................ 35

xv
xvi Python Codes

3.37 Function help ....................................................................................................................... 35


3.38 Showing help ....................................................................................................................... 36
3.39 Initial commands.................................................................................................................. 36
3.40 Reading a module ................................................................................................................ 37
3.41 Shortcut name ...................................................................................................................... 37
3.42 From import ......................................................................................................................... 37
3.43 Executing commands in either version of Python ............................................................... 38
3.44 Divide by 0 error .................................................................................................................. 38
3.45 Traceback through a module................................................................................................ 38
3.46 Try-except ............................................................................................................................ 39
3.47 Creation of vectors............................................................................................................... 40
3.48 Creating tensors ................................................................................................................... 40
3.49 Accessing data in a matrix ................................................................................................... 40
3.50 Creating random arrays........................................................................................................ 41
3.51 Using a random seed............................................................................................................ 41
3.52 Creating a solid rectangle..................................................................................................... 41
3.53 Creating arrays from data..................................................................................................... 42
3.54 Setting the number of decimal places that are printed to the console.................................. 42
3.55 Converting between vectors and matrices............................................................................ 43
3.56 Math operations for vectors ................................................................................................. 43
3.57 Multiplication with vectors .................................................................................................. 44
3.58 The inner product of two matrices ....................................................................................... 44
3.59 Maximum values in an image .............................................................................................. 45
3.60 Application of several functions .......................................................................................... 46
3.61 Locating the maximum ........................................................................................................ 46
3.62 Using the nonzero function ................................................................................................ 47
3.63 Advanced slicing for arrays ................................................................................................. 48
3.64 Advanced slicing for arrays with multiple dimensions........................................................ 49
3.65 Mathematical functions for an array .................................................................................... 49
3.66 Sorting data in an array ........................................................................................................ 50
3.67 Sorting images according to a user-defined criteria............................................................. 50
3.68 Example of the indices function .......................................................................................... 51
3.69 Creating a solid circle .......................................................................................................... 52
3.70 The Circle function.............................................................................................................. 52
3.71 Loading an image................................................................................................................. 53
3.72 Rearranging the color channels............................................................................................ 53
3.73 Saving an image ................................................................................................................... 54
3.74 An example of melding the operators and functions from ndimage.................................... 54
3.75 Finding the center of mass ................................................................................................... 55
4.1 Loading the image using Python Image Library.................................................................. 59
4.2 Loading the image using commands from imageio ............................................................. 59
4.3 Reducing the intensity resolution......................................................................................... 61
5.1 Creating an image that suppresses the background ............................................................. 69
5.2 Converting between HSV and RGB values ......................................................................... 70
5.3 The vectorize function applies the operation to all pixels................................................... 70
5.4 Modifying the hue channel .................................................................................................. 71
5.5 The RGB to YIQ conversion................................................................................................ 72
5.6 Getting the Cb and Cr channels from the rocket image....................................................... 73
6.1 Using the Window and Plop operators................................................................................. 82
6.2 Demonstrating the Downsample and Concatenate operators .............................................. 83
Python Codes xvii

6.3 Shifting an image ................................................................................................................. 84


6.4 Noninteger shifts.................................................................................................................. 86
6.5 Scaling the image................................................................................................................. 86
6.6 Rotation using scipy.ndimage .............................................................................................. 87
6.7 Multiple rotations................................................................................................................. 88
6.8 Dilation operations............................................................................................................... 89
6.9 The perimeters are created by computing the difference between two dilations................. 90
6.10 Creation of the image in Figure 6.10 ................................................................................... 91
6.11 The RPolar function............................................................................................................. 93
6.12 The IRPolar function............................................................................................................ 93
6.13 The LogPolar function ......................................................................................................... 93
6.14 Finding the perimeter of the cell.......................................................................................... 96
6.15 The Barrel function ............................................................................................................. 97
6.16 An example using scipy.ndimage.geometric–transform .................................................. 98
6.17 An example using scipy.ndimage.affine_transform ................................................ 98
7.1 Starting Dancer .................................................................................................................. 102
7.2 The DelaunayWarp function ............................................................................................ 103
7.3 Reading a CSV file............................................................................................................. 103
7.4 Extracting information from the tessellation ..................................................................... 104
7.5 Finding a simplex............................................................................................................... 104
7.6 Commands to warp an image............................................................................................. 106
7.7 Morphing two images ........................................................................................................ 108
8.1 Testing the eigenvector engine in NumPy ......................................................................... 113
8.2 Proving that the eigenvectors are orthonormal .................................................................. 113
8.3 Projection of data into a new space.................................................................................... 115
8.4 Projection of data into a new space.................................................................................... 116
8.5 The first two dimensions in PCA space ............................................................................. 117
8.6 The ScrambleImage function ........................................................................................... 118
8.7 The Unscramble function ................................................................................................. 119
8.8 Various calls to the Unscramble function ......................................................................... 120
8.9 The LoadImage and IsoBlue functions ............................................................................ 122
9.1 The EigenImages function ................................................................................................ 129
9.2 The ProjectEigen function................................................................................................ 129
10.1 The Rect2Polar and Polar2Rect functions....................................................................... 137
10.2 Forward and inverse FFT ................................................................................................... 139
10.3 The DC term ...................................................................................................................... 142
10.4 Conservation of energy ...................................................................................................... 142
10.5 Computing the original image ........................................................................................... 142
10.6 The shifting property.......................................................................................................... 143
10.7 The script for Equation (10.28).......................................................................................... 148
10.8 Creating the mask .............................................................................................................. 151
10.9 Using the KaiserMask function........................................................................................ 152
11.1 An example of a low-pass filter ......................................................................................... 154
11.2 An example of a high-pass filter ........................................................................................ 155
11.3 An example of a band-pass filter ....................................................................................... 155
11.4 An example of a band-pass filter with soft edges .............................................................. 156
11.5 The Wedge function .......................................................................................................... 157
11.6 An example of line filtering ............................................................................................... 158
11.7 The MaskinF function....................................................................................................... 159
11.8 The MultiWedges function ............................................................................................... 160
xviii Python Codes

11.9 The ColorCode1 function ................................................................................................. 160


11.10 Removal of the screen from the baseball image ................................................................ 162
12.1 Smoothing through a correlation with a small solid block ................................................ 167
12.2 The Correlate1D function................................................................................................. 169
12.3 The Correlate2DF function .............................................................................................. 169
12.4 Correlating shapes.............................................................................................................. 169
12.5 Loading and creating the necessary images....................................................................... 171
12.6 The LocateDock function.................................................................................................. 172
12.7 The Overlay function ........................................................................................................ 173
12.8 The SubtractDock function .............................................................................................. 174
12.9 The IDboats function ........................................................................................................ 174
12.10 The FPF function............................................................................................................... 176
12.11 Testing the FPF function ................................................................................................... 177
12.12 Computing an FPF ............................................................................................................. 178
12.13 The LoadTach function..................................................................................................... 179
12.14 The MakeTachFPF function............................................................................................. 180
12.15 Running the functions in the tachometer problem............................................................. 180
13.1 Shifting a simple array ....................................................................................................... 189
13.2 Extracting the vertical edges .............................................................................................. 190
13.3 Using the Sobel function to create an edge enhancement ................................................. 191
13.4 Application of the DoG filter ............................................................................................. 193
13.5 The Harris function........................................................................................................... 194
13.6 Applying the Harris detector to simple geometric shapes ................................................. 195
14.1 The LineHough function................................................................................................... 200
14.2 Creating Figure 14.1 .......................................................................................................... 201
14.3 Creating Figure 14.2 .......................................................................................................... 201
14.4 Running the Hough transform on an image with a line ..................................................... 201
14.5 The Hough transform applied to a different image............................................................ 202
14.6 Creating a line that is at a different orientation.................................................................. 202
14.7 Circle Hough transform applied to multiple rings ............................................................. 204
14.8 The detection of the cane ................................................................................................... 206
15.1 Adding random noise......................................................................................................... 210
15.2 Smoothing in Python ......................................................................................................... 210
15.3 Salt noise............................................................................................................................ 211
15.4 Applying colored noise ...................................................................................................... 212
15.5 The AddNoise function ..................................................................................................... 213
15.6 The Lopass function .......................................................................................................... 214
15.7 The ErosionDilation function ........................................................................................... 215
15.8 Applying a median filter .................................................................................................... 216
15.9 Applying a Wiener filter .................................................................................................... 217
16.1 Simple texture measure through the ratio of the mean and standard deviation ................. 223
16.2 Compute the edge density.................................................................................................. 223
16.3 Measuring the four moments ............................................................................................. 225
16.4 The FourMoments function.............................................................................................. 225
16.5 Beginning the comparison of textures ............................................................................... 226
16.6 The WvlIteration function................................................................................................ 228
16.7 Creating an output after a single iteration in wavelet decompostion ................................. 228
16.8 The WaveletDecomp function .......................................................................................... 229
16.9 The GetParts function....................................................................................................... 230
16.10 The WaveletEnergies function.......................................................................................... 230
Python Codes xix

16.11 The Cooccurrence function .............................................................................................. 231


16.12 The HHomogeneity function ............................................................................................ 232
16.13 The HContrast function.................................................................................................... 233
16.14 The HCorrelation function ............................................................................................... 234
16.15 The HVariance function.................................................................................................... 234
16.16 The HEntropy function..................................................................................................... 235
16.17 The Haralick function....................................................................................................... 236
16.18 Using the Haralick function.............................................................................................. 237
16.19 The five Law’s vectors ....................................................................................................... 239
16.20 The BuildLawsFilters function ........................................................................................ 239
16.21 The LawsJets function ...................................................................................................... 240
17.1 The GaborCos function .................................................................................................... 244
17.2 The Filts function .............................................................................................................. 244
17.3 The ManyCorrelations function ...................................................................................... 245
17.4 Complete steps to create an image, Gabor filters, and the correlations ............................. 246
17.5 The RandomJets function................................................................................................. 247
17.6 The entire process of gathering correlations, extracting jets, and mapping in
PCA space ......................................................................................................................... 248
18.1 The PerimeterPoints function .......................................................................................... 254
18.2 The ShowPerimPoints function........................................................................................ 254
18.3 The ChainLength function ............................................................................................... 255
18.4 The Curvature function .................................................................................................... 255
18.5 The FourierDescriptors function ..................................................................................... 257
18.6 The ReadFiducial function ............................................................................................... 259
18.7 The RemoveCenterBias function ..................................................................................... 260
18.8 The RemoveRotateBias function...................................................................................... 261
18.9 The RemoveScaleBias function ........................................................................................ 261
18.10 The GridDifference function ............................................................................................ 262
18.11 The Shape1 function.......................................................................................................... 263
18.12 The ExtractStats function................................................................................................. 263
18.13 Computing four geometric values...................................................................................... 266
18.14 The metrics for the six shapes............................................................................................ 267
18.15 The CurveFlow function ................................................................................................... 268
18.16 Running iterations of curvature flow ................................................................................. 269
18.17 Computing the medial axis ................................................................................................ 270
19.1 Using the 1D discrete cosine transform ............................................................................. 276
19.2 An example of a 1D DCT .................................................................................................. 277
19.3 The dct2d function ............................................................................................................ 278
19.4 The idct2d function ........................................................................................................... 278
19.5 Modified 2D EMD ............................................................................................................. 284
19.6 Reconstruction ................................................................................................................... 285
20.1 The original PCNN Python class ....................................................................................... 295
20.2 Typical execution of the PCNN ......................................................................................... 295
C.1 Programs to convert RGB to XYZ and then to CIE L*a*b* ............................................. 327
C.2 The Zernike function ........................................................................................................ 328
C.3 The Plop function .............................................................................................................. 329
C.4 The Warp function ............................................................................................................ 330
C.5 The KaiserMask function ................................................................................................. 331
Preface
Image processing and analysis is a burgeoning field that is gaining renewed interest in recent years.
The need for image analysis tools is ever increasing. Along with this is also the need to be able to
efficiently and explicitly describe processes used in analyzing images. Unfortunately, the current
state of publications is that each author has their own way of describing processes. Two different
authors describing the same process will often provide vastly different ways of communicating their
proposed process.
The recent development of high-powered scripting languages such as Python compounds the
issue. Publications can consume more real estate in explaining the process than it takes to write
the Python script to execute the process. Furthermore, the descriptions can be imprecise, because
some authors prefer to describe their processes through textual descriptions. Readers attempting to
replicate their results may find it a difficult process as not all of the steps are clearly explained.
The purpose of this text is to provide a unified mathematical language that coincides with Python
scripting. Image operators represent processes in a image analysis sequence, and these are associated
with Python scripts. Thus, a concise mathematical description of a process is easily translated into
Python scripts through this correlation. The conversion of Python scripts to image operators is nearly
as easy. Thus, this text introduces the initial set of image operators, complete with associated Python
scripts and examples.

Jason Kinser, D.Sc.


George Mason University
Fairfax, VA, USA
jkinser@gmu.edu

xxi
Software and Data
Software and data used in this text are available at:
https://jmkinser49.wixsite.com/imageoperators
Software and images copyright (c) Jason M. Kinser 2018. Software and images provided on this
site may be used for educational purposes. All other rights are reserved by the author.

xxiii
Author
Jason M Kinser, DSc, has been an associate professor at George Mason University for more than
18 years teaching courses in physics, computational science, bioinformatics and forensic science.
Recently, he converted the traditional university physics course into an active learning technology
environment at GMU. His research interests include modern teaching techniques, more effective
methods in text-based education, image operators and analysis, pulse image processing and multi-
domain data analysis. This book was born from a desire to engage students in physics education
and to find ways of reducing the external costs that both students and institutions incur within the
traditional education framework.

xxv
Part I

Image Operators
Exploring the Variety of Random
Documents with Different Content
coriander seed. The breakfast before us was a most substantial one, there
being no lack either of welcome, which is the best of cheer, or of mutton, fish,
beer, coffee, milk, and stale black rye-bread. Be it remembered that this
breakfast was neither Icelandic, Danish, nor Scotch; but, exhibiting some of
the characteristics of all three, seemed marvellously adapted to our present
requirements in this distant habitat.
We stepped into the store, and saw exposed for sale hardware and soft goods
of all kinds. In a corner were standing lots of quart-bottles gaudily labelled
“essence of punch,” whatever that may be. Mr. Henderson showed me some
specimens of double refracting calc, or Iceland spar, which is obtained in the
neighbourhood. It only occurs in one place of the island, filling a fissure of
greenstone from two to three feet wide and twenty to twenty-five feet long, on
the north bank of the Reydarfiord, about a thousand feet above the sea level.
There, a cascade rushes over the rock, bringing down fragments of the spar
from time to time. The mass itself gets loosened, bit by bit, through the action
of frost on the moisture which enters edgeways between the laminae, wedging
them apart in the direction of the cleavage of the crystals. Transparent
specimens more than a few inches in size are rare and valuable. Mr. Henderson
presented me with a beautiful large semi-transparent chalcedony weighing 1 ℔
7 oz., and some pebbles.
His partner, Mr. Jacobson, an Icelander, also gave me a young raven to make a
pet of. It was this year’s bird and quite tame. I called it Odin; and, having got
hold of an old box, improvised a door from a few spars, that it might have a
sheltered place to roost in at night till it got to the end of its voyage.
I now wandered up the valley, for an hour or two, alone, and sat down on a
slope, on the right side of it, to look around me and rest. The river, near where
I sit, flashes down over a steep rock and forms a fine waterfall, the roaring of
which is echoed from the chimney-capped amphitheatre of hills opposite.
Beneath the fall, it flows peacefully along, runnelling and rippling on, to the
blue fiord, through the quiet green valley. White streamlets of water trickle
down the trap hill-sides, every forty or fifty yards; the whole producing a
continuous quiet murmur or undertone, not unlike that from the wings of an
innumerable swarm of gnats playing in the sunshine on a warm summer’s day,
but ever broken in upon by the clear liquid tinkle of the streamlets nearest us,
heard drip, dripping, with a clear metallic sound which might be compared to
the chirp of the grasshopper. This solitary glen, now lying bathed in light, is
fanned by the gentle breeze, fragrant with the smell of tedded hay, and richly
variegated with wild flowers—harebells, butter-cups, wild thyme, cotton-grass,
and forget-me-nots—a gathered bunch of which is now lying beside me on a
moss-cushioned rock. Quietly musing here on all, of strange or new, I have
seen since leaving home, and dwelling more particularly on the great kindness
I have received at all hands, I feel grateful to God, who has hitherto opened up
a way for me and given me friends amongst strangers wherever I chanced to
wander.
We saw specimens of surturbrand, which crops out on the top of a steep
mountain, at the mouth of the fiord, on the north side, and obtained a few
more geological specimens and plants.
After dinner, I strolled for a quarter of a mile up the valley with Mr.
Henderson and Dr. Mackinlay, to visit the farm behind the store. It consists of
a group of hovels, the walls are stone and turf, the gables wood, and the roofs
covered with green sod. The entrance is a dark muddy passage leading into a
ground-floor apartment as dark and muddy, where, in winter, cattle are kept.
The kitchen is a dirty, smoky, sooty hole, with fish hanging in it to smoke and
dry; a pot of seal-blubber stands steaming in a corner. The fire is raised on a
few stones above the floor, like a smithy-forge; while there is a hole in the roof
for the smoke. Picking our way through another long passage, dark and dirty,
we found a trap-ladder and ascended to a little garret, where I could only walk
erect in the very centre. The apartment was floored and fitted up with bunks
all round the sides and ends. In these box-beds, at least seven people—men,
women and children—sleep at night, and sometimes a few more have to be
accommodated. The little windows in the roof are not made to open, and no
regard whatever is paid to ventilation. Dr. Mackinlay prescribed for an old man
we found lying ill in this abominable fetid atmosphere, where his chances of
recovery were very slight. He was an old farm servant about whom nobody
seemed to care anything.
FARM HOUSE, SEYDISFIORD.

In a little apartment shut off from this one, and in the gable portion of the
building which in this case constitutes the front of the house, an old woman at
the window sits spinning with the ancient distaff,[39] precisely as in the days of
Homer.
To amuse the farmer’s daughters I showed them my sketches, with which they
seemed much interested.
SEYDISFIORD, LOOKING EAST TOWARDS THE SEA.

I understood part of their remarks, and could in some degree make myself
understood by them, with the few Danish and Icelandic words I kept picking
up. On receiving a little money and a few knick-knacks, they, all round, held
out their hands and shook mine very heartily. This, the Icelanders always do,
on receiving a present of anything however trifling.
After sketching the farm-house, I took two views of Mr. Henderson’s store;
one of them from a height behind, looking down towards the fiord, and the
other from the brink of it, looking up the valley. In the latter, a part of the
same farm-house appears, and thus indicates its exact position.[40] With the
assistance of these three sketches taken together, the reader will be enabled to
form some idea, of the appearance presented by this arm of the North Sea.
SEYDISFIORD, BY FARÖE TO LEITH
We sailed from Seydisfiord at half-past six P.M. on Saturday night, direct for the
Faröe islands.
There is a singular cone-shaped mountain called Brimnæs Fjall at the mouth of
the fiord, showing masses of clay-rock alternating with and pushing up trap,
which is deposited in thin layers of perpendicular structure. Several pillars or
shafts are left standing singly on the very summit, and present a very curious
appearance, distinctly relieved against the amber light of the sky. At Dr.
Mackinlay’s request I made a sketch of it.

BRIMNÆS FJALL.

A vessel of Mr. Henderson’s, which had been given up as lost, now


unexpectedly came in sight, which necessitated Mr. Jacobson and a young
Iceland lad, who were en route to Copenhagen, to get on board her and return
to Seydisfiord to look after her cargo, evidently much to their disappointment.
The wild scenery of the coast, especially at Reydarfiord, was strikingly
picturesque.[41]
Mr. Murray, Professor Chadbourne, Mr. Henderson and I walked the deck till
a late or rather an early hour, and watched the fast receding mountain-ranges
of Iceland—pale lilac, mauve, or deep purple—and the distant horns, shading
through similar tints from rose to indigo, all distinctly seen athwart the golden
light of the horizon which for hours has been ebbing slowly and softly away,
but is now on the turn, and about to flow again.

Sabbath, August 7. The weather is fine; no land or sail in sight all day; whales
playing about the ship. Had many pleasant deck-walks and talks, and several
quiet hours, sitting perched on the stem, reading, or watching the prow, below,
cutting and cleaving through the clear green water like a knife.

Monday morning, August 8. We are sailing between two of the Faröe islands,
bright sunshine lighting up all the regularly terraced trap-rocks, caves, and
crevices of this singular group.
I have now got a pet to look after, and, without Shakspere’s authority for it, we
know that
“Young ravens must have food.”

The last thing I did last night was to shut Odin in his box, and the first thing
this morning to let him out again and give him the freedom of the ship. The
bird knows me, is pleased when I scratch his head, and confidingly runs
hopping to me for protection when the boys about the ship teaze him more
than he likes. His fellow traveller, a young Icelandic fox brought on board at
Reykjavik to be sent to the Marquis of Stafford, also runs about the ship
during the day. At first we had some misgivings on the subject; for
“Treason is but trusted like the fox—
Who ne’er so tame, so cherished, and locked up,
Will have a wild trick of his ancestors.”

However, these fears were soon dissipated; for Odin can hold his own, and
when the fox, approaching furtively, uses any liberty with his tail feathers, he
suddenly gets a peck from the bird’s great formidable beak, which he does not
seem much to relish. The salutary fear continues for a short time, is forgotten,
and again the dab comes as a reminder. We were often greatly amused,
watching their individual habits and droll ways, when the one intruded upon
the other. It was half play, half earnest, a sort of armed neutrality with a basis
of mutual respect.
On the west coast of Stromoe is the roofless ruin of the church of Kirkuboe.
It was begun in the twelfth century, but never finished. It is built of stone, has
five large windows and several small ones below; a little farm house or hut,
with red tiles on the roof, stands near it. What a strange lonely place for a
church! Thorshavn lies on the other—the east—side of the island. It is only
five miles distant as the crow flies, but as we have to sail round the south
point, and Stromoe is twenty-seven miles long, we do not reach it till near
noon.
On landing, Mr. Haycock accompanied me to call for Miss Löbner, who has
been poorly ever since her sea voyage. Her mother presented wine, cake,
coffee &c., and was most hospitable. None of us being able to speak Faröese,
at first we felt a little awkward; but a brother of the old lady’s who speaks
English soon came to the rescue and acted as interpreter. With justifiable
pride, they again showed us their flower and kitchen garden. I got the whale-
knives, caps, shoes, gloves &c., which had been made or procured for me
during my absence in Iceland. Ere leaving, Miss Löbner appeared to say adieu!
and insisted on my accepting several other specimens of Faröese workmanship
as remembrances of Thorshavn. No people could have been kinder.
Again, wandering about, we explored the town, looked at the church, stepped
into the stores, passed the governor’s garden, and wandered a mile or two in
that direction in order to obtain a view, and get quit of the fishy smells which
superabound in Thorshavn.
On our return we called for Mr. Müller, who presented me with a copy of the
gospel of St. Matthew in Danish and Faröese, arranged in parallel columns. I
understood him to say that this was the only book ever printed in the Faröese
dialect, and that it is now out of print and very rare. It bears the date of 1823.
Here we saw an old man 76 years of age, an Icelander who has been in Faröe
for the last 40 years. He had spent several years in England, and told me that,
in 1815, he saw our regiments land at Liverpool after the battle of Waterloo.
He speaks English fluently.
A Thames fishing smack, and a sloop from Lerwick, are lying in the bay.
Piping and dancing goes merrily on, on board the latter, relieved by intervals
of music alone. In one of these, we heard “The Yellow Hair’d Laddie,”
rendered with considerable taste, although, doubtless, several “improvements
and additions” were made on the original score.
We took some Faröese boatmen into the saloon of the steamer, and I shall not
soon forget the look of wonder and utter astonishment pourtrayed on their
countenances, as they gazed on the mirrors and everything around, or were
shown things with which they were not familiar and heard their uses explained.
They were greatly pleased with my life-belt. Dr. Mackinlay showed them a
multiplying-glass, and, as it was handed from one to another—each man first
making the discovery of what had so inexplicably excited the wonder of the
last looker—the queer exclamations of amazement accompanied by inimitable
pantomimic gestures reached their culminating point, and were irresistibly
droll.

NAALSÖE—FARÖE.

The weather is all we could desire. The sailors are singing some curious Danish
songs, with the time well marked, as they heave the anchor; and at 20 minutes
past 6 o’clock P.M. we are steaming out of the bay. The evening is lovely, and
the Thermometer, on the deck, stands at 68°. Thorshavn soon disappears, and
we leave the Faröe islands astern, relieved against an amber sky, Dimon being
the most striking and conspicuous of the group. A few stars shone overhead,
and I walked the deck till midnight.
ENTRANCE TO THE SOUND LEADING TO THORSHAVN.

Tuesday, August 9. At breakfast, tasted a whale-steak which Miss Löbner had


yesterday sent on board for me, with particular instructions to the stewardess
to have it properly cooked. The flesh looked and tasted like dry tough beef,
with a slight flavour of venison. The blubber, however was too strong for any
of us to do more than merely satisfy—not gratify—our curiosity.
The day was lovely. Professor Chadbourne invited me to visit and spend a
month with him during his holiday. Indeed, cordial, pressing invitations, all
round, were the order of the day. As fellow-travellers we had been happy
together, and felt sorry at the near prospect of our little party being broken up
and scattered; for several valued friendships had been formed.
Between three and four o’clock in the afternoon, the thermometer indicated
98° in the sun and 75° in the shade. Dr. Mackinlay showed me an old Danish
dollar he had got, in change, at Reykjavik; it bore the date of A.D. 1619, the year
of the landing of the Pilgrim Fathers from the May Flower. Part of the day was
spent in writing out these pages from my diary. In the evening we saw, far to
our left, faint and dim on the horizon line, the north-west islands of Shetland;
and by a quarter to 8 o’clock P.M. were sailing twenty miles to the west of Fair
Isle, which lies between Orkney and Shetland. Both groups are in sight. We
have not seen a sail since we left Faröe, and now, what we at first fancied to be
one, off the north end of the Orkneys, turns out to be a light-house, rising
apparently from the sea, but in reality from low lying land which is yet below
the horizon.
The sunset to-night is gorgeous; cavernous recesses opening through a dense
purple cloud-bank into glowing regions of fire; while broad flashing gleams ray
out on every side athwart the sky, as if from furnace-mouths. Then we have
moonlight on a sea smooth as glass, and not even a ripple to be seen. The
Orkney light-house, now gleaming like a setting star, is left far astern. The
phosphoresence along the vessel’s side and in her wake is most brilliant; while,
seething, electric-like, from the screw, it rivals the “churned fire-froth” of the
demon steed. The moon, half-hid, is at times deep crimson and again bright
yellow. Many falling stars are shooting “madly from their spheres;” not that
our music lured them, although, “on such a night” of nights, when all is
harmonious, we cannot but sing. Mr. Murray gives us “Home, sweet home”
and “The last rose of summer,” and ere retiring at midnight, all of us join
together in singing the “Spanish Chant.”

Wednesday morning, August 10. We are off Inverness; wind a-head and rising.
Professor Chadbourne to-day gave me an oak-leaf which he plucked from the
tree, at Upsala, planted by Linnæus with his own hands. Wrote as long as the
heaving of the ship would admit of it, then arranged botanical specimens and
read Wordsworth. The wind is blowing so fresh, off Peterhead, that, with full
steam, we are not making above one and a half knots; and at times can scarcely
keep any way on. Passed the Bell-Rock; the sea still rising. Went to bed at 11
o’clock P.M.; vessel pitching a good deal.

Thursday morning, August 11. Rose at four o’clock and was on deck ere the
Arcturus dropt anchor in Leith Roads. But as we cannot get our traps on shore
till the custom-house officer comes at nine o’clock to overhaul them, we
remain and breakfast on board. The examination made, at half-past ten o’clock
A.M., we landed by a tug steamer, and made for our respective railway stations,
each, on parting, bidding the other “a bright adieu!” in the hope that it might
only be for “a brief absence!” “Odin” was in good feather: his owner sun-
bronzed and strong.
At length, comfortably ensconsed in the fast express, I lay back in the corner
of a compartment, closed my eyes and resigned myself to see pleasant pictures
and dream waking dreams—of snow jökuls, volcanoes, glaciers, and ice-fields;
of geysers, mud-cauldrons, and sulphur-pits; of lava plains, black, wierd and
blasted, or dreary wastes of ice; of deep rapid rivers, flashing waterfalls, leaping
torrents; of frightful chasms, rugged cliffs, and precipitous mountains
mirrored in deep blue fiords; of pathless stony deserts, enlivened at times with
oasis-like spots of tender green herbage and bright coloured flowers; of wild
break-neck rides, over bare rocks, among slabs and lava-blocks of all shapes
and sizes and lying in every conceivable direction; through volcanic sands and
scoriæ; by red and black vetrified craters, or across dangerous fords; of
multifarious scamperings too, and mud-plashings over hill and dale; or wild
rides down rocky steeps, not on a phantom steed, but on a sure-footed Iceland
pony; of pleasant companionship by the way; of cordial welcome and great
kindness received, in quiet homesteads, and at all hands from the people,
wherever we went; then again of Frost contending with Fire, and of all the
varied and marvellous phenomena of Iceland, that singularly interesting island
in the lone North Sea.

STROMOE—FARÖE.
APPENDIX.
I.

ICELANDIC STORIES AND FAIRY TALES


TRANSLATED INTO ENGLISH BY THE REV. OLAF PÁLSSON, DEAN
AND RECTOR OF REYKJAVIK CATHEDRAL. REVISED AND
EDITED BY DAVID MACKINLAY AND ANDREW JAMES
SYMINGTON.

STORIES OF SÆMUNDUR FRODI, CALLED THE


LEARNED.[42]

I. THE DARK SCHOOL.

Long, long ago, when Trolls and Giants lived among men, there was a famous
school where curious youths were taught the mysteries of witchcraft. France
and Germany both claim the honour of it, but no one knows where it really
was.
It was kept in a dismal cavern, deep underground, into which no ray of
sunlight ever entered. Here, the scholars had to stay no less than seven winters;
for it took them all that time to complete their studies. They never saw their
teacher from one year’s end to another. Every morning a grey grizzly hand, all
covered with hair, pushed itself through the cavern wall and gave to each one
his lesson book. These books were written all over with letters of fire, and
could be read with ease, even in the dark. The lessons over, the same grizzly
hand again appeared to take away the books and bring in the scholars’ dinner.
At the close of winter, the scholars who had then got through their seven years
apprenticeship were dismissed. The great iron door was opened, and the
master stood watching those who went out; for he had stipulated that the
scholar who walked hindmost, in passing through, was to be seized by him and
kept as a thrall. But who was this strange school-master? Why, Old Nick
himself. No wonder, then, that each of the scholars struggled hard to be first
in passing the fatal threshold.
Once on a time, there were three Icelanders at the dark school; Sæmund Frodi,
afterwards parish priest at Oddi, Kalfur Arnason, and Halfdan Eldjarnsson,
afterwards parish priest at Fell, in Slettuhlid. They were all dismissed at the
same time. Sæmund, to the great delight of his companions, offered to walk
hindmost in going out of school, so he dressed himself in a long loose cloak,
which he took care to leave unbuttoned, and bidding good bye to school-
fellows left behind, prepared to follow his countrymen. Just as he was putting
his feet on the first step of the stair which led up from the school door, Old
Nick, who was watching hard by, made a clutch at the cloak and called out,
“Sæmund Frodi, pass not the door,
Thou art my thrall for evermore.”

And now the great iron door began to turn on its hinges; but, before Old Nick
had time to slam it too, Sæmund slipt his arms out of the sleeves of his cloak,
and sprung forward out of the grasp of his enemy.
In doing so, the door struck him a heavy blow on the heel, which gave him a
good deal of pain, when he said,
“The door hath swung too near the heel,
But better sore foot than serve the Deil.”

And so Sæmund outwitted Old Nick, and got away from the dark school along
with his two friends. Since then, it has become a common saying in Iceland,
when a person has had a narrow escape from danger, that “the door swung
too near his heels.”[43]

II. SÆMUND GETS THE LIVING OF ODDI.

At the time Sæmund, Kalfur, and Halfdan came out of the dark school, there
was no priest at Oddi, for the old priest had just died. All three of them would
fain have the living, and so each went to the king to ask it for himself. The
king knew his men; and so he sent them all away with the same answer, that
whoever reached Oddi first, should be made priest of that place.
Thereupon Sæmund summoned Old Nick and said to him, “Now, I’ll make a
bargain with you, if you swim with me on your back across to Iceland, and
land me there without wetting my coat-tail, I’ll be your servant as long as I
live.” Old Nick was highly pleased with the offer and agreed at once. So, in less
than no time, he changed himself into a seal, and left Norway with Sæmund on
his back.
Sæmund took care to have his prayer book with him, and read bits out of it
every now and then while on the way. As soon as they got close to the shores
of Iceland, which they did in less time than you would think, he closed the
book and suddenly struck the seal such a heavy blow on the neck with it that
the animal went down all at once into deep water. Sæmund, now left to
himself, struck out for the shore and got easily to land. In this way Old Nick
lost his bargain, and Sæmund got the living of Oddi.

III. THE GOBLIN AND THE COWHERD.

When Sæmund was priest of Oddi, he once had a cowherd—a good servant
withal, but greatly addicted to swearing. Sæmund often reproved him for this,
but all his reproofs were of no avail. At last he told him, he really ought to
leave off his bad habits, for Old Nick and his servants lived upon people’s
curses and wicked words. “Say you so?” said the cowherd, “if I knew for
certain that Old Nick would lose his meals by it, I would never say a bad word
more.” So he made up his mind to mend his ways.
“I’ll soon see whether you are in earnest or not,” said Sæmund, and so, he
forthwith lodged a goblin in the cowhouse. The cowherd did not like his
guest, and no wonder: for he was up to every kind of mischief, and almost
worried the life out of him with his wicked pranks. The poor cowherd bore up
bravely for a time, and never let slip an oath or angry word. The goblin got
leaner day by day, to the intense delight of the cowherd, who hoped, bye and
bye, to see an end of him.
One morning, on opening the byre door, the poor cowherd found every thing
turned topsy-turvy. The milk pails and stools were broken in pieces and
scattered about the floor; and the whole of the cows—and there were many of
them—tied tail to tail, were straggling about without halters, and goring each
other. It needed but half an eye to see who had done the mischief. So the
cowherd in a rage turned round to the goblin who, shrunk and haggard, lay
crouched up in a corner of a stall, the very picture of wretchedness, and
poured forth such a volley of furious curses as would have overwhelmed any
human being in the same plight. The goblin all at once began to revive; his
skin no longer shrivelled looked smooth and plump; his eye brightened up, and
the stream of life again flowed joyously through his veins.
“O, oh!” said the cowherd, as he suddenly checked himself, when he saw the
wonderful effect his swearing had on the goblin, “Now I know for certain that
Sæmund was right.” And from that day forward he was never known to utter
an oath. As for the goblin, he soon pined away again and has long since been
beyond troubling anybody. May you and I, and all who hear this story, strive to
follow the good example of Sæmund’s cowherd!

IV. OLD NICK MADE HIMSELF AS LITTLE AS HE WAS ABLE.

Sæmund one day asked Old Nick how little he could make himself. “Why,”
replied he, “as for that I could make myself as small as the smallest midge.”
Thereupon Sæmund bored a tiny hole in the door post, and asked him to
make good his boast by walking into it. This he at once did; but no sooner was
he in, than Sæmund stopped the hole with a little plug of wood, and made all
fast.
Old Nick cursed his folly, cried, and begged for mercy; but Sæmund would not
take out the stopper till he promised to become his servant and do all that he
was told. This was the reason why Sæmund always had it in his power to
employ Old Nick in whatever business he liked.

V. THE FLY.

As might be expected, Old Nick always harboured a great ill will against
Sæmund: for he could not help feeling how much he was in Sæmund’s power.
He therefore tried to revenge himself on various occasions; but all his tricks
failed, for Sæmund was too sharp for him.
Once, he put on the shape of a little fly, and hid himself—so he thought, at
least—under the film that had gathered on the priest’s milk jug, hoping that
Sæmund would swallow him unawares, and so lose his life. But Sæmund had
all his eyes about him; so instead of swallowing the fly he wrapped it up in the
film, covered the whole with a bladder, and laid the package on the altar.
There, the fly was obliged to remain till after the service, when Sæmund
opened the package and gave Old Nick his liberty. It is told, as a truth, that old
Nick never found himself in a worse case than when lying on the altar before
Sæmund.
VI. THE GOBLIN’S WHISTLE.

Sæmund had a whistle of such wonderful power, that, as often as he blew it,
one or more goblins appeared before him, ready to do his bidding.[44] One day,
on getting up, he happened to leave the whistle under his pillow, and forgot all
about it till the afternoon when the housemaid was going to make his bed. He
charged her, if she found anything unusual about the bed, she was on no
account to touch it, or move it from its place. But he might have saved himself
the trouble of speaking; for, as soon as the girl saw the whistle, she took it up
in her hand, and looked at it on every side. Not satisfied with much handling
it, she put it to her mouth and blew it lustily. The sound of the blast had not
died away before a goblin stood before her, saying, “what will you have me to
do?” The girl was not a little startled, but had the presence of mind to conceal
her surprise.
It so happened that the hides of ten sheep, that had been killed that day, were
lying on the ground in front of the parsonage. Recollecting this, the girl replied
to the goblin, “Go and count all the hairs that are on the ten hides outside,
and, if you finish your task before I get this bed made, I’ll consent to marry
you.” The goblin thought that a task worth undertaking for such a prize; and
hurrying out, fell to counting the hairs with all his might. The girl who did not
like the idea of being the wife of a goblin, lost no time, you may be sure, in
getting through with her work; and it was well she bestirred herself; for, by the
time the bed was made, the goblin had almost finished his task. Only a few
hairs of the last hide remained uncounted, but they were enough to make him
lose his bargain. When Sæmund afterwards learned how prudently the girl had
got out of her scrape, he was very well pleased.

ICELANDIC FAIRY TALES.

BIARNI SVEINSSON AND HIS SISTER SALVÖR.[45]

Once on a time, a worthy couple, Sveinn and his wife, occupied a farm, on the
shores of the beautiful Skagafiord, in the north country. They were in easy
circumstances and were blessed with two fine children, a son and daughter,
who were the joy of their hearts. Biarni and his sister Salvör—for these were
the names of their children—were twins and greatly attached to each other.
In the spring of the year,[46] about St. John’s day, when these two had reached
the age of twenty, the people of Skagafiord were arranging a party to make a
journey to the mountains of the interior, to gather Iceland-moss for making
porridge. Sveinn promised to let his son go with the party. As soon as Salvör
knew that, she felt a great desire to go too; and so she went to her parents to
ask their consent. This was not so easily got, as they did not wish to part with
both their children at once; and besides, they knew she was ill fitted to bear the
hardships and fatigues of mountain travelling. But she fretted so much at the
thought of being left behind, that, at last, they consented to let her go.
The night before the moss-gatherers were to leave, Sveinn the farmer dreamed
that he had two beautiful white birds, of which he was very fond, and that all
at once, to his great grief, the hen-bird disappeared and could nowhere be
found. On awaking in the morning, he could not help thinking that his dream
betokened no good to his darling Salvör, so he called her to him, and after
telling her his dream, he said to her, “Salvör dear! I cannot bear to part with
you, you must stay at home with your mother and me, for I would never
forgive myself if any ill befel you by the way.” Salvör who had been in great
glee at the prospect of riding, day after day, up the romantic valleys to the
south of Skagafiord, and there tenting out amidst the mountains, was neither
to hold nor to bind, when she found that, after all, she would have to stay at
home; she wept with vexation and distressed herself so much that her father
could not bear it, and again gave an unwilling consent to let her go. So she
accompanied her brother and the rest of the party to the mountains.
The first day after getting there, she gathered Iceland-moss with the others,
but during the night she fell suddenly ill and was unable to leave her tent on
the following day. Biarni stayed with her, and did all that a brother could do to
help and comfort her. For three whole days he was her companion, but, on the
fourth day, he left her for a time in charge of a friend, while he himself joined
the moss-gatherers. After partly filling his bag, he sat himself down by a large
stone, and, resting his head on his hand, brooded over his sister’s unhappy
fate; he feared she was going to die among the mountains.
By and by he heard a great tramping of horses, and, on looking about, he saw
two men riding towards him at a quick pace. One of them wore red coloured
clothes, and had a red horse; the other who was younger, was dressed in black,
and was mounted on a black horse. On reaching the place where Biarni was
sitting, they dismounted and saluted him by name.
“What ails you Biarni,” said the elder of the two strangers. For a time Biarni
answered not a word, but on being pressed to do so, he opened up his heart to
them and told all about his sister’s illness.
“My companions are going to return home, but I must stay to watch over
Salvör; and who knows how soon she may die in my arms.”
“You are in a hard case Biarni,” said the other, “and I am sorry for you, but
won’t you leave your sister with me, and I will take good care of her.”
“No, no,” said Biarni, “that I dare not do, for I know neither who you are, nor
where you come from. But will you tell me where your home is?”
“That’s no business of yours,” said the other, rather gruffly, and then, taking
from his pocket a silver-gilt box set with precious stones, added, “Won’t you
sell me your sister for this box.”
“No,” said Biarni, “nor for a thousand like it. I would not give her to you for
any money.”
“Well! well! there is no help for it, you will at all events accept this box, as a
token that you have met with men among the mountains.”
Biarni took the offered gift with pleasure, and thanked the giver. The two men
then bade him farewell and rode away, while he returned to the tent. Next
morning his companions went away home, leaving him alone with his sister.
Though she was now a little better, he dared not sleep, for he was afraid lest
the strangers should come and steal her away. But, after watching a whole day
and night, he felt overcome with fatigue; so he lay down, and folding his arms
round her waist to protect her, fell into a sound sleep. But, when he awoke, his
sister was gone, and was nowhere to be found. He spent a whole day
sorrowfully wandering from spot to spot, looking and calling for her, but it
was all in vain. He then turned his back on the mountains, and with a heavy
heart went home, and told his parents what had happened.
“Woe is me,” said Sveinn, “what I feared most has come to pass, but God’s
will be done!”
There was great grief in Skagafiord when the news spread from farm to farm;
for Salvör, with all her way-wardness, was a promising girl, and was every
body’s favourite. A party of young men returned to the mountains to look for
her, but nowhere was the least trace of her to be found.
And now ten years had passed away. By this time Biarni was married and
settled on a farm, not far from his father’s. During autumn all his sheep went
amissing, and his shepherd could not discover what had become of them
though he searched diligently for them three whole days. On learning this,
Biarni bid his wife provide him with a week’s supply of food, and an extra pair
of shoes; “for,” said he, “I shall go to the mountains myself to look for the
sheep.” His parents, who were still alive, urged him to stay at home; for they
feared that, if he went to the mountains, they might never see his face again.
“I must go,” said he to them, “I cannot afford to lose the sheep. But be of
good heart, and do not begin to weary for me till the week is over.”
He then went away on foot, and did not leave off walking for three days. At
the end of that time he came to a cavern, where he turned in and lay down to
sleep. On waking, he could not see a yard before him; for a thick fog which
rested on the ground. He continued his journey, but soon lost his way.
Towards evening the fog cleared off, and he found himself in a spacious valley,
not far from a large well built farm house. It was the hay season, so that all the
people of the farm were busy in the meadow. On getting near the house, he
noticed, in particular, two women and a girl who were tedding the hay. “God’s
peace be with you,” said he, on reaching the spot; and then, telling them of his
mishaps, he asked permission to stay all night under their roof. They gave him
a hearty welcome, and the girl went with him to the house. She was of more
genteel appearance than the rest—young and handsome—and, as Biarni
thought, bore some resemblance to his long lost but well remembered sister.
This unexpected circumstance renewed his old griefs, but he did what he could
to seem cheerful before his young hostess. She led him through several
apartments to a large well furnished room, where everything was neat and tidy.
Here, she drew in a chair, and kindly asked him to sit down and rest, while she
brought in supper. He had not long to wait; for she soon placed upon the table
a plentiful supply of meat and wine.
After supper, she showed him to the little room where he was to sleep for the
night; she then took away his wet clothes, wished him a kind good night, and
left the room.
As Biarni lay in bed, he fell a-wondering where he was, and how the sight of
the girl should have so waked up the sad memories of the past. He fell asleep
thinking of these things, but was soon awakened by the sound of singing in a
room over his head. It was the family at evening worship, as is the custom of
the country. He heard both men and women singing, but one voice sounded
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like