0% found this document useful (0 votes)
8 views45 pages

(Ebook PDF) Image Operators: Image Processing in Python

The document promotes ebookluna.com as a platform for seamless downloads of various ebooks across multiple genres, particularly focusing on image processing in Python and related topics. It includes links to specific ebooks, such as 'Image Operators: Image Processing in Python' and 'Digital Image Processing,' along with a detailed table of contents outlining various chapters and subjects covered. Users can explore and download ebooks in different formats like PDF, ePub, and MOBI.

Uploaded by

rutracrixx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views45 pages

(Ebook PDF) Image Operators: Image Processing in Python

The document promotes ebookluna.com as a platform for seamless downloads of various ebooks across multiple genres, particularly focusing on image processing in Python and related topics. It includes links to specific ebooks, such as 'Image Operators: Image Processing in Python' and 'Digital Image Processing,' along with a detailed table of contents outlining various chapters and subjects covered. Users can explore and download ebooks in different formats like PDF, ePub, and MOBI.

Uploaded by

rutracrixx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Experience Seamless Full Ebook Downloads for Every Genre at ebookluna.

com

(eBook PDF) Image Operators: Image Processing in


Python

https://ebookluna.com/product/ebook-pdf-image-operators-
image-processing-in-python/

OR CLICK BUTTON

DOWNLOAD NOW

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


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

(eBook PDF) Digital Image Processing, Global Edition 4th


Edition

https://ebookluna.com/product/ebook-pdf-digital-image-processing-
global-edition-4th-edition/

ebookluna.com

Digital Image Processing Using MATLAB 1st edition - eBook


PDF

https://ebookluna.com/download/digital-image-processing-using-matlab-
ebook-pdf/

ebookluna.com

(eBook PDF) Digital Image Processing 4th Edition by Rafael


C. Gonzalez

https://ebookluna.com/product/ebook-pdf-digital-image-processing-4th-
edition-by-rafael-c-gonzalez/

ebookluna.com

Feature extraction and image processing for computer


vision Fourth Edition Aguado - eBook PDF

https://ebookluna.com/download/feature-extraction-and-image-
processing-for-computer-vision-ebook-pdf/

ebookluna.com
(eBook PDF) Radiographic Image Analysis 5th Edition

https://ebookluna.com/product/ebook-pdf-radiographic-image-
analysis-5th-edition/

ebookluna.com

Riemannian geometric statistics in medical image analysis


Pennec X 1st edition - eBook PDF

https://ebookluna.com/download/riemannian-geometric-statistics-in-
medical-image-analysis-ebook-pdf/

ebookluna.com

Handbook of Robotic and Image-Guided Surgery 1st Edition -


eBook PDF

https://ebookluna.com/download/handbook-of-robotic-and-image-guided-
surgery-ebook-pdf/

ebookluna.com

(eBook PDF) Deep Learning for Medical Image Analysis by S.


Kevin Zhou

https://ebookluna.com/product/ebook-pdf-deep-learning-for-medical-
image-analysis-by-s-kevin-zhou/

ebookluna.com

Handbook of medical image computing and computer assisted


intervention 1st Edition- eBook PDF

https://ebookluna.com/download/handbook-of-medical-image-computing-
and-computer-assisted-intervention-ebook-pdf/

ebookluna.com
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
[email protected]

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
Random documents with unrelated
content Scribd suggests to you:
several weeks and singing the Marseilles hymn morning and evening,
with the English jack spread over her round house, got under way,
and arrived safe at Toulon, which had been evacuated by the fleet
and army; and all this because Tunis was a neutral port. Now
everybody knew that before the squadron sailed, and also that Tunis
was nothing less than a nest of thieves; besides, we were out of
gunshot of their forts and might have taken the whole with the
greatest ease imaginable.
We had a rugged-headed, squint-eyed boatswain’s mate, who
early one morning passed the word for all those who were quartered
on the main deck to come below and fight the lower-deck guns. He
was instantly obeyed, and the people of their own accord were
absolutely going to bring the French 74 to action, and the above
boatswain’s mate as the head of the party was in the act of setting the
example, when the second lieutenant snatched the match out of his
hand just as he was going to fire. Lord Nelson, who commanded the
Agamemnon, happened to come on board soon after, and when this
was told him he seemed quite pleased: ‘For then,’ says he, ‘we must
have taken them.’ If he had commanded, we certainly should have
taken them,[94] and not have stayed wasting our time for months in
the bay doing nothing.
Our squadron used to water near the Goletta, a small channel
leading to the ancient harbour of Carthage, fortified on each side and
a chain across. On the left of this channel they have a gun with
marble shot of immense size; the diameter of the bore twenty two
inches and a half. On the other side are a few wells dug in the sand,
from which the squadron got their water. On one occasion I went in
the launch to fill our casks, a messmate of mine (the present Captain
Valobra) taking a trip with me; having given directions about filling,
I proposed to cross the Goletta (which has a drawbridge over it) and
take a look at the large fort they have close by. On getting into the
interior, which is a square, we saw a door open and went into what
appeared a guard room, from the number of arms tastefully arranged
about the walls, and several Turks rolled up in blankets lying on the
floor. Having examined the place we were going away, when one of
the Turks, as I approached the door, caught hold of me by the collar
and pushed me back. I did not relish this and tried to make the
blackguard understand, but all to no purpose. However, I again
made a movement to get out, when a young Turk, with a short stick
that had something round like a ball fixed to the end of it, made a
blow at my head which would certainly have done for me had I not
stepped back in time. We had left our side arms in the launch and
had nothing to defend ourselves against this ruffian. One of the
Turks we heard say ‘Spagniolle!’ upon which Valobra called out
‘Angleise!’ Whether this had the effect to liberate us I know not; but
an old withered Turk came up, and after a deal of altercation with the
fellow who struck at me, he pointed to the door and showed us the
way out, and glad enough we were of it. Having filled our casks we
returned on board (the rascally Turks pelting us with stones as long
as we were in reach), and made a complaint to Sir John Collins, who
went on shore the next day to represent the business to the
commandant of the fort, and this vagabond had the impudence to
say we might think ourselves well off that we were not sent up the
country and made slaves. Went with Lieutenant Shirley to see the
ruins of Carthage.... Saw several remains of antiquity, broken
columns, underground passages, pieces of frieze, and the remarkable
arches supposed to be the stables of the elephants. I went into a
room like a cellar and got a piece of the flooring, of beautiful green
and white marble, which I brought home; but some thief in England
stole it from me—the devil do him good with it. The ground about the
ruins was covered with reptiles of almost every description, which
made it dangerous to explore. I carried a piece of frieze several miles
intending to bring it home also, but was obliged to leave it from
fatigue. As Lieutenant Shirley, who was very tired, sat on a broken
column, I observed it might have been the same that Caius Marius
rested on when in exile and from which he made this memorable
reply (to show the instability of human greatness) to him that was
sent by the governor to warn him off: ‘Go,’ says he, ‘and say that thou
hast seen Caius Marius sitting on the ruins of Carthage.’
A short time before we left Tunis the bey sent a present to the
squadron, of bullocks, butter, poultry, scented candles and some otto
of roses. We in the cockpit had some butter, poultry, and a scented
candle or two; as for the otto of roses we could smell it near the
wardroom, but not a drop could we see in the cockpit. However, we
were more regaled with the scent of a seapie, made in a pitch kettle
that contained, besides other delicacies, upwards of thirty fowls. We
sat round the cauldron in the cockpit, like the witches in ‘Macbeth,’
and would not have exchanged this glorious mess for all the otto of
roses belonging to the bey or his ministers. At the same time, the
devil thank some people for their kindness in not paying the
compliment; they might have sent us one small bottle to counteract
the bilge water; but never mind; they, poor souls, are all dead; and
most of us are alive notwithstanding. As for the butter, it was only fit
to grease the topmasts, and for that purpose we resigned it. We had a
few of the candles, made of beeswax and scented.
The bullocks were very small, and here I must relate a droll
circumstance. Our purser’s steward was one that dearly loved grog,
and it so happened that on the day the bullocks were slaughtered, he
got beastly drunk. Some of the midshipmen seeing him in that
situation in the first watch, lying near the steward room, agreed to
sew him up in one of the bullocks’ hides, which was accordingly
done. The horns being on, were fixed to a nicety on his head and
fastened under the chin, firm as a rock. A little before twelve he came
to himself and got up (for his legs and arms were free) and tried to
get into the steward room, but the key was secured. He then began to
bellow, just as the quartermaster came down to call the watch, and
was knocking his horns against the bulk head, his tail near the
cockpit ladder. The quartermaster, holding up his lantern, looked at
him for some time in amazement; at last, letting it fall, he took to his
heels, swearing that the devil was in the cockpit; while those who
slept abaft on the lower deck jumped out of their hammocks and
followed his example. ’Twas a most laughable sight; particularly so
when the officer of the watch came down to see what was the matter
and, evidently under the influence of fear, did not venture down the
cockpit ladder until one of the midshipmen came up and said it was
Colquhoun, the steward, transformed into a bullock. It had a good
effect on the steward, as he was afraid ever after to bouse his jib up;
and whenever he put his head up the cockpit ladder, those on the
lower deck would sing out, ‘What’s become of your horns?’
Left Tunis for Porto Farino to get a supply of water for the fleet.
The plague had made great ravages before our arrival, but had in
some measure abated. This place is a Turkish arsenal, and several of
their men of war were fitting out. A number of Neapolitan slaves
were at work in the different storehouses; some of them could speak
English, and gave us an interesting account of the conduct of their
masters. I saw an old Turk, upwards of seventy, with a long stick in
his hand thrashing several of the poor wretches. I could not refrain
from telling him he was a damned old scoundrel; whether he
understood or not, I cannot say, but he called out repeatedly, ‘Esau,
Esau’; and Lieutenant Shirley bawling in his ear, ‘Will you have Isaac
and Jacob also?’
Porto Farino is situated near the mouth of the Bagrada,[95] where
Attilius Regulus, the Roman consul, lay encamped in the first Punic
war, when the serpent attacked and destroyed several of his soldiers
who came to the river to obtain water.... The ancient city of Utica,
famous for the death of Cato in the civil war, was at no great distance
from this port.
A short time before we sailed the Turkish governor paid a visit to
the ship, with his retinue, among whom was the Turkish admiral—a
fine looking fellow near seven feet high. We saluted the governor
with eleven guns, and he minutely inspected every part of the ship
and seemed highly delighted with the bread room, and also with the
68-pounders we had on the forecastle. One of his attendants spoke
English, and said he was in England at the time the Foudroyant was
captured by the Monmouth,[96] and that he lived at Wapping. We
suspected he was an Englishman although he said his name was
Mustapha.
Sailed from this port to cruise off the Island of Pantalaria. You
that are fond of romance are aware that in this island the famous
captain of banditti met his death; all Italy speaks of him, from the
Apennines to the Straits of Messina, and the shepherds of the Sicilian
vales sing the praises of the valoroso Capitano Rinaldini. But they
did not (in this island) sing the praises of little Tommy Yates, our
purser, who went on shore to purchase some articles, and put the
whole island under quarantine when they found out we had just left
the Turkish port; and if Tommy had gone on shore the second time
he probably would have left his bones there.
We encountered off this island the heaviest gale I ever was in;
particularly a squall that lasted from seven bells in the middle watch
until two bells in the morning watch. The storm staysails were blown
from the bolt rope, and the ship during this prodigious gust lay with
her main deck guns in the water. The sea was one white sheet, and
during the whole course of my servitude I never witnessed anything
equal to it; and many who had been in the hurricane of 1780 in the
West Indies, declared that this squall was equally terrible. After the
cruise we put into Trapani, the ancient Drepanum. It was here
Aeneas landed, according to Virgil, when the fight with the gauntlet
took place between Dares and Entellus, and it was also famous for
that between Hercules and Eryx, in which the latter was killed. It was
a noted place in the first Punic war for military events, as that of the
defeat of the Roman fleet under the Consul Claudius Pulcher,
wherein (according to Valerius Maximus) the Romans lost 90
galleys, 8,000 men killed or drowned, and 20,000 taken prisoners
by the Carthaginians without the loss of a man or a single galley on
their side.[97]
I must here relate an anecdote which will show how careful
people ought to be when joking with those whom they think don’t
understand their language. The day after we arrived at Trapani, near
thirty Sicilian clergymen came on board to see the ship, and while on
the quarter deck making their observations, Palmer, our fourth
lieutenant, in a frolicsome mood, went up to one of them and, while
bowing and scraping, said, ‘Pray, sir, were you ever knocked down
with a fathom of ——?’ when, to Palmer’s horror and amazement, the
other answered in good English, ‘Never in my life, sir,’ and then
addressed his companions, who cast their eyes upon Palmer and
began to laugh at his expense. This he could not stand, and in going
down the quarter deck ladder declared he would sooner face the devil
than a Trapani parson.
The islands Maretimo, Levanzo, and Faviguano are near this
place; in the last-mentioned island the Turkish prisoners are sent as
slaves. We saw several of them at work in the moat, one of them a
man of prodigious stature. These islands were the ancient Ægades,
where Lutatius Catulus, the Roman consul, defeated the
Carthaginian fleet and put an end to the first Punic War.[97]
Before we left Trapani we went to see a church, or rather
cemetery, where several rows of dead bodies were placed in niches
one over the other. They were naked, some standing up and others
lying at full length, and presenting an appearance truly horrible; we
understood they belonged to a particular order. While lying here, a
mutiny took place among the ship’s company, in consequence of
some bullocks that were anything but fat being sent for the use of the
people. Now John Bull, having more regard for fat and lean, swore
he’d be damned if he’d have anything to do with skin and bone. A
survey was then held and the report stated that as no other meat
could be obtained, double allowance of this lean kine should be
served out to make up the deficiency; but all to no purpose; and John
Bull, forgetting his duty and only thinking of his maw, broke out into
open rebellion. Some of the scoundrels were put in irons, but were
immediately released by the others and the irons thrown overboard.
They then assembled on the lower deck, got the hammocks down,
and a breastwork made in the bay, with the two foremost guns
pointed aft. The officers at last prevailed on them to return to their
duty, and, Sir John Collins being an easy man, no examples were
made. Sailed for Leghorn, where we arrived in Carnival time. We
were not long at an anchor before the ship was surrounded by boats
with musicians playing fine Italian airs and women singing most
delightfully.
Several men of war were in the roads; among which was the
Aquilon, 32, with Prince Augustus Frederick (now Duke of Sussex)
on his travels. Got leave with some difficulty to go on shore with two
messmates, Graves and Valobra; saw the brazen men so much
spoken of, consisting of the father and three sons (Turks) in bronze
chained to the four corners of a pedestal, with a marble statue of a
Tuscan prince on the top. Visited the Jews’ synagogue, which was
well worth seeing, being a magnificent temple; also the churches,
opera house and many other places, with fine paintings and statuary,
and had glorious fun at the Carnival, where we met our little purser,
Tommy Yates, with a mask and a black domino on, cutting such
capers that Heraclitus would have wiped away his tears had he seen
him, and joined in the laugh. He was a wet little soul and generous to
a degree, and everyone respected him.
Early next morning, after a sumptuous breakfast, we set off for
Pisa, about fourteen or fifteen miles from Leghorn, in one of the gilt
coaches with horses that, had they seen the devil would not have
taken fright. We were three hours going the distance and had full
time to observe the beautiful prospect along the Vale of Arno. About
ten we entered Pisa, where they were celebrating the Carnival in a
magnificent style, and we were told that six hundred coaches were in
the procession. The prince was among the number and appeared
much gratified. Pelting with sugar plums is customary on this
occasion; and one of our midshipmen pelted Lord Hervey in his
coach; and when told it was the British ambassador, and that he
looked very angry, he immediately hove another volley at Lady
Hervey, observing that she looked better tempered than his
Excellency.
We spent a very pleasant evening at the theatre, and next
morning went to the cathedral—a gorgeous fabric, with gates of
bronze highly decorated with passages from scripture in
compartments in basso relievo. We also saw the baptistery with a
whispering gallery, and the campo santo, with the paintings on the
wall in fresco round the cloisters, the work of the oldest masters. One
painting I well recollect, representing the Last Judgment—the work I
believe of Buffalmaco, who in this painting drew all his friends going
to heaven, and his enemies going to the devil; the faces of all being
an exact resemblance of those of both parties. The tombs of some of
the masters are at the foot of their works.[98] The campo santo is an
oblong figure, and the earth in the centre was brought from the Holy
Land some centuries ago, and people of religious celebrity are here
interred.
We next visited the Observatory and Botanical Gardens, and
then to the top of the Leaning Tower, 187 feet high, and whose
summit overlooks the base fifteen feet. One of our party began
ringing the bells, which brought up a posse of friars; and Graves,
pointing to one of them, a very fat man, exclaimed, ‘I’ll be damned if
that fellow is not fitted for foreign service with six months’ provisions
in his guts.’ I suppose they did not understand him, as they behaved
with great civility. Some in this country, who I could mention, would
have behaved in a different manner. There’s an old saying
That Pisa looks ill
If you sit still.

This was not the case with us, as we were constantly on the move and
saw everything and enjoyed ourselves greatly, particularly among the
masks while parading the Lung’ Arno. The day before our departure
we took a long and delightful walk upon the banks of the Arno and
were within a few miles of the spot where Catiline and his whole
army were destroyed 63 B.C., in the consulship of Marcus Tullius
Cicero and Caius Antonius Nepos.
Pisa has a university and formerly contained 100,000
inhabitants, but has greatly fallen off and grass grows in the streets.
It contains many churches and other superb buildings, particularly
the Grand Duke’s palace in the Lung’ Arno, the Hospital, and
Exchange. There are three bridges over the Arno, one of them of
marble. Several Roman antiquities are to be seen. It was our
intention to have gone to Lucca and from thence to Florence; but all
sublunary things are vain, as we were ordered to sea sooner than was
expected, and returned to Leghorn after five days’ absence, where we
dined at an excellent ordinary at one of the best houses in the city.
We had a strong party of English officers at the dinner, some of
whom got rather merry before the cloth was off the table, and
catching hold of the waiter they rolled him in the cloth with plates
and dishes, the fellow roaring out all the while to no purpose. One
midshipman took a loaf and let if fall out of the window (we were on
the second floor) upon the jaw of an Italian in the street, which
floored him, while others pelted legs and wings of fowls at those
looking out of the opposite windows; but to their kind forbearance
everything was taken as a joke and only laughed at. Would this have
been the case in England?—where every hole and corner has a board
threatening prosecution, and if you pass two or three stopping in the
street, their conversation will be about law, hanging, or trade.
Sallied out in the evening and went to a house in Scratch Alley—
you that have been at Leghorn I daresay know the place well. In the
middle of this lane lived an old woman of enormous size, who was
named the Boatswain of Scratch Alley. Saw a figure there I never
shall forget—a fellow dressed as a lady, with a fine cap trimmed with
blue ribbon and a white frock on, a face like Vulcan with a long black
beard. When he came in the room we were sitting in, he danced a
fandango and cut such astonishing capers that my old messmate
Vosper said drily, ‘Gardner, if that fellow is not the devil he must be
his near relation.’ The next evening three of us took a cruise, and, it
being very late before we returned, our lodging was shut up and with
difficulty we got entrance to a house near the Mole. The
accommodations vile in the extreme; only one bed, with sheets as if a
sweep had slept in them. At this time it began to rain with drops as
big as pistol balls, which obliged us to stay where we were. However,
we sat on the chairs, but got very little sleep for the rats and people
passing and re-passing to a sewer at the end of the room. The
morning luckily turned out fine, and after clearing our uniforms of a
few bugs that thought fit to billet themselves on us without being
invited, we gladly started from this infernal hotel to breathe the fresh
air. Went to Montenero, where the learned Smelfungus has a
monument near his remains.[99]
Having received orders to sail immediately and join the
squadron under Vice-Admiral Hotham off Toulon, we first put into
St. Fiorenzo for a short time. Went to see the Mortella tower that
beat off the Fortitude, 74, and Juno frigate; the former ship had
upwards of sixty killed and wounded, and was on fire in several
places from the red-hot shot. This tower had but two guns; one of
them was dismounted during the attack and defended by twenty
Frenchmen, only one of whom was killed. The tower was taken by
mounting some guns on a spot that overlooked it.[100]
Sailed from St. Fiorenzo and joined the squadron. Our captain,
Sir John Collins, being ill, we had Captain William Shield acting. Sir
John soon after departed this life and was committed to the deep.
Sixteen minute guns were fired at the funeral to denote the number
of years he had been a post captain. Sir John was a well-meaning
man, but fractious from long illness. He died with the gout in his
head and stomach. The ship’s company paid respect to his memory;
they divided their black silk handkerchiefs,[101] and wore one part
round their hats and the other round their arms, and requested they
might see the corpse before the interment; which request was
granted, and they walked through the cabin in ranks and bowed to
the coffin while passing, and most of them in tears—a sight truly
impressive. Billy Shield remained with us about a month after Sir
John’s death, and then George Campbell, as good a fellow as ever
lived, took command.
I have already stated our reconnoitring the enemy’s fleet in the
roads. Out of many instances I shall mention one that had nearly
been of serious consequences. Having stood in with a fine breeze, the
enemy never fired a shot until we hove in stays. At this time it fell on
a sudden a dead calm, and we were within gunshot. They then began
to blaze away from all their forts, the red-hot shot flying in every
direction. I was looking out of the gunroom port when a shot came
right under our counter, which made the water hiss and had nearly
struck the rudder. At this time things looked queer, all the boats were
hoisted out and began to tow, but still we drifted in, the shot flying
full half a mile beyond us, when luckily a breeze came off the land
and saved the Berwick from being sunk or blown up, for she never
would have been taken. Fortunately we had none killed or wounded,
which was astonishing, as the shot flew like hail. Captain Campbell
soon after left the ship, being appointed to the Terrible, 74, and
Captain George Henry Towry succeeded him.
Our squadron under Admiral Hotham consisted of eight sail of
the line, two of them three-deckers (the Britannia, 100, and St.
George, 98) and two frigates; and, after several weeks’ cruise, the
French fleet put to sea from Toulon with seven sail of the line, one of
them a three-decker, and six or seven frigates or smaller vessels.
Now, mark me, several of those ships had been put down as burnt at
the evacuation of Toulon, but now had the impudence to rise from
their ashes like the Phœnix,[102] or like the snake that had slept the
winter, but on the return of spring appears renewed in youth and
with new fury burns:
Qualis ubi in lucem coluber, mala gramina pastus,
Frigida sub terra tumidum quem bruma tegebat,
Nunc positis novus exuviis, nitidusque juventa,
Lubrica convolvit sublato pectore terga,
Arduus ad solem, et linguis micat ore trisulcis.—Aeneid.

June 1794.—We were at dinner when the drum beat to quarters,


and on going upon deck saw the ‘Resurgam Squadron’ coming out,
under topsails and foresail, on the starboard tack, in line of battle,
the Sans Culotte,[103] 136 guns, their leading ship; the wind westerly;
our squadron standing in on the larboard tack, and to the best of my
recollection about three leagues from the enemy; and, had we stood
on and tacked, we should have got in their wake. But our admiral
made a signal—it being at this time evening—that a movement would
take place after dusk. Now, what do you think this movement was?
Why, to bear up and sail large! ‘Tell it not in Gath, nor publish it in
the streets of Askalon.’ The Meleager, 32, was left behind to watch
the enemy. All this appeared strange; but the admiral, we supposed,
knew
What was what and that as high
As metaphysic wit could fly.

Now we had an opinion also, and that opinion was that the
French might have been brought to action that evening; at any rate
we should have prevented them from getting back to the roads, and
could have attacked them in the morning if a night action was
considered hazardous. It was said the admiral was fearful they
should escape us and throw relief into Calvi, at that time besieged.
Whatever was the reason, off we set as if hell kicked us and joined
Lord Hood—I think the next day; and then, as brave as Hercules,
crowded sail with fourteen or fifteen sail of the line and got sight of
them the day after, in the morning, working in near Gourjean Bay,
[104]
where they anchored in the afternoon under the forts. Lord Hood
made every preparation to attack them, and a general chase with
some hopes of success took place. We were ordered to attack the fort
on the starboard hand until the fleet had passed, and then to follow;
and the Illustrious, 74, was ordered against the frigates in the other
quarter in shore, near the other line-of-battle ships. But all this
ended in disappointment, as towards night the wind blew strong off
the land and the attack was given up in the morning, and we were
detached with the sick to St. Fiorenzo, and then to Calvi to assist in
the siege. It was here that Lord Nelson lost his eye and Captain
Serocold his life. We remained but a short time at Calvi and then
returned to St. Fiorenzo. The Yankee historian (James) gives a very
incorrect account of this; in fact, he says little or nothing about our
squadron under Admiral Hotham when the French put to sea; which
appears strange, as this calumniator always felt happy in finding
fault with naval officers, and here he missed a good opportunity.
While cruising in the Gulf of Genoa we picked up parts of the
booms belonging to the Ardent, 64, who had been missing a long
time; and from the appearance of the spars it was evident she was
blown up with all hands,[105] as nothing has been heard of her since.
It was a sad business that we did not bring the French to action the
day they left Toulon; the disappointment was bitterly felt by those
who expected prize money and promotion, and here a glorious
opportunity was thrown away in the most unaccountable manner.
For personal bravery Admiral Hotham stood pre-eminent; but it has
been said he was not fit to command in chief, but very able as a
second. In the American war he greatly distinguished himself,
particularly when he was commodore on board the Preston, 50, he
engaged and would have taken a French 84,[106] one of D’Estaing’s
squadron, which a gale of wind coming suddenly on alone prevented;
and the public accounts respecting this action say, ‘Now for the glory
and honour of the British army.’
While speaking of the honour of the British navy, I must say a
word or two more about the seamen and marines. When Lord Hood
besieged Bastia he proposed to General Dundas, who commanded
the troops, to make a joint attack; but the general thought it too
hazardous. Now Lord Hood had a different opinion,
and while General Dundas
And his eighteen manœuvres sat still on the grass

he attacked the place with the seamen and marines who covered
themselves with glory and carried all the works, and Bastia was
obliged to surrender.
Having letters of recommendation to Lord Hood and to Admiral
Goodall, I went on board the Victory and was told by the secretary
(McArthur), that several were before me on the list for promotion;
but if I would take my chance his lordship would remove me to the
Victory immediately. This I thought would be of little service; and as
the Gorgon, 44, was under orders for England I requested to be sent
on board of her and try my interest at home. My request being
granted, Captain Towry in the kindest manner recommended me to
Captain Wallis of the Gorgon, which kindness I shall always
remember, and am sorry that the service has lost by his death so
good an officer. He served with his Majesty[107] in the Andromeda
and Valiant.
Before leaving the Berwick I must mention a few droll hands
that belonged to her; and first I shall bring forward old Bell, the mate
of the hold. We pressed him and several mates of merchantmen out
of a cartel from Marseilles to Gibraltar, and put them on the quarter
deck. He was a hard-drinking man and also a hard-working man. We
had a set on board full of fun; and when old Bell was half seas over,
they used to paint his face with red ochre, his eyebrows blacked,
large moustache, with a flaxen wig made from the fag ends of the
tiller rope; a cocked hat over all, tied under the chin; his shirt off and
his body painted like an ancient Briton. In this costume I have seen
him chasing the midshipmen through the tier with a drawn sword, a
fit subject for a pencil like Hogarth’s.
Next to him was old Collier, who drank like a fish, and when
drunk used to sing the Thirty-fourth Psalm and prognosticate that
the ship would founder with all hands. They used to make fast his
shirt sleeves at the wrist and then haul the shirt over his head, so that
he could not clear his hands. In this situation he would be powdered
and painted, with a red night cap on his head, and placed alongside
of old Bell, while the whole cockpit would be in a roar.
We had a little slovenly surgeon’s mate whose name was Vag.
The midshipmen annoyed him sadly by calling out Vag-Veg-Vig-Vog-
Vug, while others in a cockney cadence would sing out Wig-Wag-
Wog, which enraged him almost to madness. I happened to come
into the berth where he was sitting at a time they were calling out as
above, when he, without any provocation on my part, snatched up
the snuffers and with the sharp end stabbed me in the chest and then
run a-muck after the rest, who were glad enough to steer clear of
him.
Some of our lads had a custom of taking an afternoon’s nap,
particularly Graves, who went with me to Pisa. The others, always on
the watch for mischief, would clap a spritsail yard upon his nose.
This was done by cutting a notch on the outside of a piece of hoop
and bending it so as to form a forceps and then put it on the nose like
a spring. The first time it was fixed he started up and swore lustily
that a rat (for we had hundreds of them on board) had seized him by
the nose. On another occasion some wicked fellow made a curious
mark on his forehead with caustic that remained for several weeks.
Our chaplain was a learned gentleman and always going on
shore to make researches after antiquities. When we sailed from
Toulon he was left behind; and on making his escape (so we were
told) when the enemy entered, he got upon a wall where a rope
ladder was placed about ten feet high. When he got on the top the
ladder gave way and he had no means of alighting on the other side,
and was afraid to jump down. In this predicament a party of French
came up and one of them let fly a stone, which fortunately for him
first struck the wall and then hit him on the hip, and canted him the
right way; and by that means he luckily made his escape to the boats
with little hurt, but damnably frightened. In the gale of July 1793,
when we carried away our main topmast and half the main top, an
arm chest full of black pieces[108] fell out of the top with thundering
sound upon the quarter deck, and several of the muskets stuck with
their muzzles in the deck, which bent some of the barrels. Old Billy
Chantrell, our first lieutenant, taking up one of them, said with a
grin, ‘I shall take this home; it will do when I go a-shooting to kill
sparrows round a hayrick.’ When it fell it was within an inch of his
head, and he was knocked down with a piece of the chest which
broke through the netting. I passed a very happy life during the time
I belonged to the Berwick and parted with many valuable friends
with deep regret. Our first lieutenant (Chantrell), Mr. Chas. Duncan,
the master, and Tomlinson, the clerk, left the ship at the same time
and joined the Gorgon as supernumeraries for a passage to England;
and also two of my old shipmates, Yetts and Allardice, formerly of
the Edgar, invalided home, which made the Gorgon very agreeable to
me. The following are the names of the officers:—
Sir John Collins, Knt., Captain.
Dead. A good man but fractious from severe illness; he
commanded the Ruby, 64, detached from the grand fleet at the
relief of Gibraltar, 1782, being one of eight sail of the line sent
to reinforce the fleet in the West Indies. On the passage she
captured, after a smart action, the Solitaire, a French 64, for
which Captain Collins was knighted.
Wm. Shield, Esq., Captain.
A retired rear-admiral. [Died 1842.—Marshall, iii. 89.]
Geo. Campbell, Esq., Captain.
Dead. A vice-admiral; a better fellow never existed. [As a rear-
admiral, second in command under Nelson off Toulon 1803–4.
Died, admiral and G.C.B., in 1821.]
Geo. Henry Towry, Esq., Captain.
Dead [1808]. In him the service lost a most worthy officer.
William Chantrell, 1st Lieutenant.
Dead. See Barfleur.
William Bullock, 2nd Lieutenant.
Dead. A commander; well-meaning and droll.
Chas. Stewart [or Stuart], 3rd Lieutenant.
Dead [1814]. A post captain [1796]; gouty and proud.
Nisbet Palmer, 4th Lieutenant.
Dead [1811]. He commanded the Alacrity, an 18-gun brig, in
the Mediterranean, and was captured by a French brig of the
same force. In the action Captain Palmer was wounded and
died soon after. James in his Naval History [v. 248 seq.] gives
a sad account of this. He says, ‘Capt. Palmer was only wounded
in the finger, that he ordered the colours to be struck to an
enemy of equal force, and that his death was occasioned by a
locked jaw.’ In justice to the memory of Captain Palmer it must
be recollected that the Alacrity was weakly manned—a great
number of her crew being absent in prizes. The Yankee
historian must have known this, but he had not the generosity
to state it. [James does state it; but nevertheless comments
very severely on the conduct of Palmer; not unmindful,
perhaps, of the fact that by the death of the captain, he was
commanding officer of the Berwick when captured on March 7,
1795.]
Thomas Shirley, 5th Lieutenant.
Dead. Half mad, but good-natured.
Chas. Duncan, Master.
A superannuated master attendant; a very good man.
[John] Dodgson, Surgeon.
Dead. A worthy fellow.
Thos. L. Yates, Purser.
Dead. Generous and thoughtless.
[Alexander John] Scott, Chaplain.
A Doctor of Divinity; was with Lord Nelson on board the
Victory at Trafalgar. [Died 1840.—D.N.B.]
[Hector] Tause, Gunner.
Dead. Crabbed.
Philip Myers, Carpenter.
Dead. A droll fellow.
[Joseph] Kemble, Boatswain.
Uncertain. A snappish cur.
Edward Hutchinson, Mate.
A commander; a good officer; a good navigator; a good seaman
and a most worthy messmate. [Captain, retired, 1840; died
1851.—O’Byrne.]
Robt. Tucker, Mate.
A commander; a good seaman, but given to drinking. [Died,
retired captain, 1846.—O’Byrne.]
J. A. Gardner, Mate.
A commander.
Wm. Vosper, Signal midshipman.
Lieutenant of the Royal Asylum, Greenwich Hospital. We were
at three schools together at Gosport, and in two ships; a very
able officer and seaman.
James Valobra, Midshipman.
A commander; a very worthy fellow. [Died 1861.—O’Byrne.]
Augustus Collins, Midshipman; son of the captain.
Dead. I believe a commander.
John Graves, Midshipman.
Dead. A lieutenant. Poor Jack was a worthy fellow.
James Galloway, Midshipman.
A commander [1806], out-pension. [Died 1846.—Marshall, x.
345; O’Byrne.]
John Lawrence, Midshipman.
A post captain [1817]; C.B. [Died 1849.—Marshall, viii. 123;
O’Byrne.]
[Richard] Scovell, Midshipman.
Killed in battle.
[Nicholas] Le Bair, Midshipman.
Poor fellow! was taken in the Berwick, and died in French
prison. [DD. in the pay-book, April 19, 1795. Toulon.]
Alex. Mackenzie, Midshipman.
Dead [1825]. A post captain. This man, when he was a
midshipman, used to sneak after the lieutenants; when made a
lieutenant, sneaking after the captains, and when made a
captain, was at his old tricks, sneaking after the admirals. Had
he lived to be made a flag officer, he would have sneaked after
the devil.—[Marshall, vii. 75.]
John Rose, Midshipman.
A commander; a good fellow.
[William] Barber, Midshipman.
Dead. A lieutenant; a good fellow.
[Thomas] Pitt, Midshipman.
Uncertain. I believe a master.
[Thomas] Hewlett, Midshipman.
A master; I believe dead.
[John] Bell, Mate of the hold.
Uncertain. A droll fellow; drank hard.
[Walter] Dempster, Midshipman.
Uncertain. A quiet, good fellow.
[John] Collier, Midshipman.
Uncertain. Good natured; drank hard.
Lord Proby, Midshipman.
Dead [1804]. A post captain. [William Allen Proby, eldest son
of the first Earl of Carysfort.]
John Lambrick, Midshipman.
A commander.—[O’Byrne.]
Wm. McCulloch, Midshipman.
Dead [1825]. A post captain [1814]; a smart officer.—[Marshall,
vii. 398.]
John Briggs, 1st Assistant Surgeon.
A surgeon R.N.; a most worthy gentleman.
[Henry] Vagg, 3rd Assistant Surgeon.
Uncertain. A sloven; Vig-Vag-Vog-Vug.
GORGON, 44

UPON TWO DECKS

Adieu, ye vales, that smiling peace bestow


Where Eden’s blossoms ever vernal blow,
Ye fairy scenes where fancy loves to dwell,
And young delight, for ever, oh, farewell!—Falconer.

In July 1794 I joined the Gorgon, Captain James Wallis, at St.


Fiorenzo, and after considerable delay sailed for Gibraltar with the
convoy bound for England under Vice-Admiral P. Cosby, who had his
flag on board the Alcide, 74. The following men of war, to the best of
my recollection, in company:—

Alcide 74 Vice-Admiral Cosby


Commerce de Marseilles[109] 136
Gorgon 44
Pearl[109] 36
Topaze[109] 36
St. Fiorenzo 36
Modeste 32

We had a very pleasant passage to Gibraltar, where we remained


some time in the New Mole, and then started for Cadiz to take in
money and to join the convoy assembling there for England. On the
passage we got on shore a few leagues to the southward of Cadiz, and
had very near taken up our quarters on the shoals, and, what was
remarkable, a frigate had been sent before us for the same purpose,
but got on shore in this place, and was obliged to return, and we
(being clever) after laughing at the circumstance, were sent to repair
her errors and went bump on shore on the very spot. The America,
64, having arrived at Cadiz to take charge of the convoy, we were put
under her orders, and having got on board the money, sailed with the
convoy for Lisbon.
Farewell and adieu, ye fair Spanish Ladies,
Farewell and adieu, ye Ladies of Spain;
For we’ve received orders to sail for old England,
In hopes in short time for to see you again.—Old Song.

After a passage of near three weeks we arrived in the Tagus,


fortunately the day before a tremendous hurricane, which blew dead
upon the shore, came on and lasted a considerable time. We
remained several weeks at Lisbon collecting the convoy. At last when
everything was ready we got under way, I think the latter end of
September, the following men of war in company:—

America 64 Hon. John Rodney, Commodore, having charge of the


convoy
Gorgon 44 Captain Wallis
Pearl 36
Topaze 36
St. 36 Capt. Sir C. Hamilton (?)
Fiorenzo
Modeste 32 Captain [Byam Martin]
Alert 18

We had a most dreadful passage home, blowing a gale of wind


the whole time with seldom more sail set than a close-reefed main
topsail. The French squadron that captured the Alexander, 74, had
been on the look-out for us. We had several French emigrants on
board who were in the greatest tribulation for fear of being taken;
and fortunately for them and for us the Jacobin squadron got on the
wrong scent. I don’t know how it happened, but some people kept an
odd kind of reckoning, and we had some idea of making the banks of
Newfoundland instead of the British Channel. However, at last we
got to the northward and westward of Scilly, with the wind at SW;
but it must be understood, to give the devil his due, that we had not
an observation for a long time, and our dead reckoning was not to be
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!

ebookluna.com

You might also like