Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
7 views

(eBook PDF) Image Operators: Image Processing in Python download

The document is an eBook titled 'Image Operators: Image Processing in Python,' which provides a comprehensive guide to image processing techniques using Python. It includes chapters on scripting, operator nomenclature, digital images, color models, geometric transformations, frequency space manipulations, and texture recognition. Additionally, it offers links to download related eBooks on digital image processing and other relevant topics.

Uploaded by

maawiahil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
7 views

(eBook PDF) Image Operators: Image Processing in Python download

The document is an eBook titled 'Image Operators: Image Processing in Python,' which provides a comprehensive guide to image processing techniques using Python. It includes chapters on scripting, operator nomenclature, digital images, color models, geometric transformations, frequency space manipulations, and texture recognition. Additionally, it offers links to download related eBooks on digital image processing and other relevant topics.

Uploaded by

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

(eBook PDF) Image Operators: Image Processing in

Python pdf download

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

Download more ebook from https://ebooksecure.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebooksecure.com
to discover even more!

(eBook PDF) Digital Image Processing, Global Edition


4th Edition

http://ebooksecure.com/product/ebook-pdf-digital-image-
processing-global-edition-4th-edition/

Digital Image Processing Using MATLAB 1st edition -


eBook PDF

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

(eBook PDF) Digital Image Processing 4th Edition by


Rafael C. Gonzalez

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

Feature extraction and image processing for computer


vision Fourth Edition Aguado - eBook PDF

https://ebooksecure.com/download/feature-extraction-and-image-
processing-for-computer-vision-ebook-pdf/
(eBook PDF) Radiographic Image Analysis 5th Edition

http://ebooksecure.com/product/ebook-pdf-radiographic-image-
analysis-5th-edition/

Riemannian geometric statistics in medical image


analysis Pennec X 1st edition - eBook PDF

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

Handbook of Robotic and Image-Guided Surgery 1st


Edition - eBook PDF

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

(eBook PDF) Deep Learning for Medical Image Analysis by


S. Kevin Zhou

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

Handbook of medical image computing and computer


assisted intervention 1st Edition- eBook PDF

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

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


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

PART I Image Operators

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


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

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


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

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


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

vii
viii Contents

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


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

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


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

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

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


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

PART II Image Space Manipulations


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

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


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

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


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

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


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

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


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

PART III Frequency Space Manipulations

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


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

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


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

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


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

PART IV Texture and Shape

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


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

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


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

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


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

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


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

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


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

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


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

PART V Basis

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


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

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


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

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


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

xv
xvi Python Codes

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


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

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


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

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


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

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


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

Jason Kinser, D.Sc.


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

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

xxiii
Discovering Diverse Content Through
Random Scribd Documents
free to retrace his steps. Like Gillespie’s vengeance on the Vellore
mutineers was that taken by Kauffman on the foe. They were
smitten hip and thigh, thousands of prisoners were massacred in
cold blood, and the villainy of the Sart inhabitants was punished by
the surrender of the town for three days to pillage by the infuriated
army. The avenger was able to report to his master that tranquillity
reigned in Samarkand. The Amīr Muzaffar was at length convinced
that the Great White Tsar’s arm was too long to be withstood or
evaded. His proud spirit was crushed by repeated misfortunes, and
he implored permission to abdicate and end his days at Mekka. But
policy demanded that the ruler of Bokhārā should be one who had
learnt submission by bitter experience. Muzaffar ed-Dīn was
confirmed as Amīr, while his whilom province, Samarkand, was
incorporated with Turkestān, and placed under Lieutenant-General
Abramoff, who had given innumerable proofs of dauntless energy.
The general soon had his hands full, for the mullās were by no
means inclined to share their sovereign’s despondency. They worked
upon the ambitions of Katti Tūra, the heir-presumptive, a youth of
seventeen, whose reckless cruelties would have made him a meet
successor of his grandfather, the murderer of Stoddart and Conolly.
This prince raised the standard of revolt, and declared his father to
have forfeited the throne. He routed a detachment of Bokhāran
555
regulars sent against him, and took the stronghold of Karki, a
fortress commanding the upper reaches of the Amū Daryā. Abramoff
had little difficulty in quelling the insurrection. He took Karshī, the
cradle of the reigning dynasty, stormed Karki, and drove the prince
into the mountains which occupy the centre of Bokhārā. Here he
found no hiding-place. He was driven to the western border of
Samarkand, and finally captured through the treachery of a peasant.
The young rebel was dragged into the presence of his outraged
father, who ordered his head to be struck off and exposed at the
palace gate.
General Abramoff completed the pacification of Bokhārā by
subduing Shahrisabz, the last refuge of highland independence. He
then politely invited the Amīr to assume the sovereignty of the
pacified territory.

MAP SHOWING THE


ADVANCE OF RUSSIA
IN
CENTRAL ASIA.
Methuen & Co. London. G. Philip & Son, 32 Fleet St. London

So effectually was Muzaffar ed-Dīn’s proud spirit crushed by


adverse fortunes that he humbly received his province as a boon
from his Russian suzerain. He saw the once hated and despised
infidels in possession of Samarkand, the richest inheritance of his
fathers, and masters of the Zarafshān, the source of Bokhāran
prosperity. He knew that it was in their power to divert its life-giving
waters and render his capital a prey to the ever-advancing desert
sands. Thus the remainder of his days was spent in vain repentance,
in indulging “sorrow’s crown of sorrow”; and the Tsar had no more
obedient vassal than the man who had aspired to sit on the throne
of Tīmūr. His later policy has been adopted by his son, the present
Amīr `Abd ul-Ahad. With the conquest of Bokhārā and the
annexation of Samarkand the fourth great stride in the Russian
advance was completed. She was mistress of Central Asia, from the
confines of China to the Amū Daryā, that historic river which rises in
the Pamirs to empty its waters into the Sea of Aral.
These immense accessions to an empire which already rivalled
that of ancient Rome served but to open up a vista of future
possibilities.
“Since the reign of Peter the Great,” wrote a contemporary
556
Russian author, “we have advanced with diligence and at the price
of immense sacrifices across the steppes which barred our passage.
They are now left behind. Our dominion has reached the basin of
two great rivers whose waters lave thickly peopled and fertile
regions. We have a right to seek compensation for sacrifices and
labours endured for more than a century. We have a right to attain a
secure frontier by pushing our colonies up to the summit of the
Himalayan range, the natural barrier between the Russian and
English possessions. When this point has been reached, then only
can we look calmly on the development of Great Britain’s empire.”
The reduction of Khiva was a corollary of that of Bokhārā. The
Khānate stretched northwards as a wedge into the newly acquired
territory and dominated the lower reaches of the Amū Daryā. Its
ruler and its entire population were bitterly hostile to Russian
designs. A Khivan contingent had fought side by side with the hosts
of Samarkand during the recent campaigns, the result of which did
not intimidate them.
In the year which followed the conquest of Samarkand, Khivan
bands penetrated the steppes of the Orenburg government and
urged the Russian Kirghiz to revolt. Caravan trade between Western
Siberia was paralysed; and in 1870 the Khān had the presumption to
557
forbid the export of grain. General Kauffman, now in supreme
command in Turkestān, was compelled by his imperial master’s
explicit instructions to show a degree of forbearance which ill-suited
his temper. He was content to demand the release of the Russians
whom the Khān still held in slavery, and an explanation of the
offensive tone adopted by his ministers in their despatches. As is
invariably the case in dealing with Asiatics, the Russians found that
moderation was mistaken for weakness. The Khān claimed the river
Emba, on the north-eastern shore of the Caspian, as the boundary
of his dominions, and endeavoured to collect taxes from the tribes of
the Ust Urt Desert, which had long been regarded as within the
Russian sphere of influence. The Kirghiz steppes became unsafe for
caravans, and postal communication between Tashkent and
Orenburg was subject to continual interruptions. It was well known
that the mullās had incited the Khān to proclaim a religious war, and
that his forces were swollen by refugees from Bokhārā. The limits of
forbearance had been reached, and the most timid adviser of the
Tsar admitted that Khiva must be reduced to impotence. The story
of the fall of the rebellious Khānate has been told often, and so
558
graphically that it is needless to relate it in any detail. The
Russians had by this time amassed great experience in the physical
conditions to be encountered, and had profited by the lessons
taught by former disasters. Depôts for provisions were formed at
each halting-place, and columns started severally from the eastern
corner of the Caspian, Orenburg, Perovski on the Sir Daryā, and
Tashkent. So carefully had the minutest detail been worked out by
the Russian staff that the several divisions, after marching for nearly
900 miles through waterless deserts, reached Khiva almost
simultaneously. The Khān was unable to cope with a disciplined
army 14,000 strong. His capital was taken by storm, and on the 24th
of March 1873 he signed a treaty of peace, acknowledging himself to
be the humble vassal of Russia, and agreeing to pay an indemnity of
2,500,000 roubles, and to surrender all Russian and Persian slaves.
This pact has been loyally observed on both sides. The Khān still
retains a nominal sovereignty with even less independence than had
been accorded to Bokhārā, and Khiva is de facto as much a part and
parcel of Russia as the government of Moscow.
Kokand, the third Khānate of Central Asia, was doomed to lose
all semblance of freedom. Its ruler had accepted the inevitable on
the defeat of his powerful neighbours, had abolished slavery, and
had striven to maintain friendly relations with Russia. But his
territories were so placed that the annexation was essential to the
safety of the eastern borders. They intervened between Turkestān
and China, and were inhabited by a fanatical population with a
strong leaven of untamed Kirghiz and Kipchāk nomads. Had Kokand
possessed a firm and politic ruler, its absorption might have been
indefinitely postponed. The reverse was the case; for the Khān,
Khudā Yār, was detested by his subjects, and rebellions frequently
559
recurred which kept the whole of Central Asia in a ferment. A
climax was reached in 1875, when, after three years of almost
incessant civil war, the Russians found themselves compelled to
intervene. Kokand was invaded by a strong expeditionary force
under General Kauffman, among whose lieutenants was Skobeleff,
destined to win imperishable glory in subsequent campaigns. Short
work was made of the Kokandis, who had dethroned their Khān and
marched under his son’s banner. They were routed with prodigious
slaughter at Makhram, and the holy city of Marghilān was occupied
without resistance. Defeats were afterwards administered to the
native levies at Andijān and Nāmangān, and on 20th February the
capital was seized by a force under Skobeleff. On the 20th March
1876 the Tsar, Alexander II., formally authorised the annexation of
Kokand as a province of Turkestān under its ancient name,
Farghāna. Skobeleff, the ardent soldier who had so greatly
contributed to the reduction of the Khānate, became its first
governor. Farghāna has a temperate climate, and has bred a hardy
and warlike population. Owing to its remoteness from the centres
served by the Transcaspian Railway, the Russian officials were not till
lately subjected to the vigorous surveillance which is exercised over
their colleagues in other provinces, and the reins of administration
were slackly held. In the spring of 1898 the discontent inspired by
alien rule, which had been sedulously fanned by the priesthood,
burst into a flame. The ringleader of the movement was a
Mohammedan monk named Ishān Mohammad `Alī Khalīfa, who
claimed the hereditary dignity of Imām, or descendant of the
Prophet. He announced that on himself had devolved the task of
fulfilling a prophecy widely received, that during the last decade of
our century an Imām would proclaim a Holy War against the infidel.
As had been the case on the eve of the Indian Mutiny, a general
rising had been planned, and a simultaneous massacre of the
Russian troops throughout the province. History repeated itself in
the result of their deeply laid conspiracy. India was saved by the
premature outbreak at Mirat; and Farghāna by the impatience of the
Ishān, who on 29th May attacked a Russian camp near Andijān
before his sympathisers were ready for concerted action. The rising
was quelled with much bloodshed on either side; 18 of the leaders
were executed, and 350 were deported to North-Eastern Siberia.
The recent opening of railway lines connecting the cities of Farghāna
with Tashkent and Samarkand will render a recrudescence of the
spirit of revolt well-nigh impossible.
CHAPTER IV

Turkomania and the Turkomans

The reduction of Khiva marks a new era in the history of the Russian
advance. The last semblance of organised opposition to the
movement had disappeared, and the Tsar saw himself the
unquestioned suzerain of the great Khānates. Westwards, his base
was planted securely on the Caspian, where the port of
560
Krasnovodsk, founded in 1869 by General Stolietoff, was
connected with the Russian colonies in the Mangishlāk peninsula by
a chain of strong places. The Amū Daryā, that ancient boundary of
nations, marked the limits of the new empire in the west. But the
vast tract between sea and river was still unsubdued, and Russia’s
boundary marched with that of no organised state. Here lay the
habitat of the Turkomans, a race with whom no peace or truce was
possible, and the story of their subjection forms the final chapter in
the history of the heart of Asia. The haunt of these untamed tribes
may be described as a triangle, with Khiva as its apex; its sides the
Caspian and the Amū Daryā; and its base formed by a line drawn
from the city of Balkh in Afghanistān to the south-eastern corner of
the Caspian Sea. The area thus enclosed is not far short of 240,000
square miles, more than twice as great as that of the United
Kingdom. The north portion is a trackless waste; but it is by no
means a desert of the Sahara type, made familiar to us by so many
records of African travel. Variety is its most salient characteristic. In
some parts so firm is the surface that a horse’s hoof rings on it as on
a macadamised road. In others, again, the loose sand forms ridges
561
like petrified waves. After the spring rains the expanse of dull
white is carpeted, as if by miracle, with gorgeous lilies, tulips, and
other bulbous plants, long grass and tufts of reed. Water is, indeed,
required to clothe the arid sand with perennial verdure, and render it
a breeding-ground for countless flocks and herds. It is found at
depths rarely exceeding thirty feet below the surface, and wells are
562
of frequent recurrence. The only rivers of importance are the
Murghāb and the Tajand, which rise in the mountains of Afghanistān
and lose themselves in the sand; but streams innumerable descend
their flanks. In times beyond the range of history the western
portion of the Turkoman Desert was watered by the Amū Daryā,
which discharged itself into the Caspian at the head of the Bay of
Michaelovsk. Owing to some convulsion of nature, or to interference
with its course by an attempt to employ it for irrigation, the bed of
the mighty stream shifted and now discharges into the Sea of Aral.
Vegetation is scanty, except during the brief spring-time. The soil is
covered, in some parts, with the camel’s thorn, a forbidding plant
which can be masticated only by the “ship of the desert.” The
perennial flora are completed by the stunted tamarisk, a root like the
stem of a rose called takh, and a shrub termed saxaul (haloxylon
ammodendron). The latter is full of knots, and has a grain most
difficult to cut or split, but it is precious as fuel, and still more
valuable as a means of binding the billowy sands. These steppes
contain few traces of animal life. Herds of beautiful wild asses are
sometimes seen in the distance, and a species of antelope is oftener
563
met with. Wells are beset with a variety of birds, which fly down
to their depths in search of water. But the stillness of the waste is
intense, and the boundless horizon is seen through the clear pure air
shimmering with the heat or broken only by a mirage. The climate of
the Turkoman Desert is one of extremes. In December and January
the cold is intense. Moser, who traversed the Kārakūm in the depth
of winter, encountered a temperature of 15 degrees below freezing-
564
point, with squalls, snow, and glacial cold. In the summer months
the heat is equally trying, and it is sometimes accompanied by sand-
storms which render respiration almost impossible. But the
Turkomans are not confined to regions so inhospitable. They have
long been established in the south-east of the Caspian, a tract
watered by the rivers Gargan and Atrak, which is swampy towards
the embouchure, but farther inland is broken by valleys as rich and
565
full of charm as any on the flanks of the Pyrenees. The streams
descending from the Kopet Dāgh, a mountain range which separates
Persia from the Turkoman Desert, has produced a fertile belt of
fifteen to twenty-five miles wide, extending from Kizil Arvat to
Giaour, a distance of 187 miles. This is the Akkal oasis. Where the
Murghāb enters the desert it forms the great Merv oasis, a land
which, even in its decadence, is one of the most fertile in the world.
This ancient seat of empire, which fell into Turkoman hands after its
invasion in 1784 by the forces of the Amīr Murād of Bokhārā, has
other advantages precious to a predatory race. It is within striking
distance of Northern Persia, and is separated from Herāt by a low
566
range of rolling hills which offer no obstacle to an invading horde.
Such is the land which, from time immemorial, has been the haunt
of one of the most interesting races in the world. Like the Red
Indians, with whom they have many characteristics in common, they
have succumbed to the ruthless force of Western civilisation; and a
study of their traditions and usages possesses the greater interest
because both will soon disappear under the process of Russification
to which Central Asia is being subjected. In the opinion of a well-
567
known living authority, the Turkomans belong to a branch of the
Turkish race inhabiting the Altaī Mountains and the upper regions of
the Yenesei and Irtish in Mid-Siberia. Long before the Christian era
the pressure of population led them to migrate southwards and
eastwards, and, following in all probability the old course of the
Oxus, their hordes spread over the great steppes extending from the
Caspian to the Hindu Kush. The appellation by which the race has
for centuries been known is considered by Vambéry to be derived
from “Turk,” a proper name which the nomads always employ when
speaking of themselves, and “men,” a suffix equivalent to the English
“ship” or “dom.” That the Turkomans were identical with the
Parthians, who were so long a thorn in the side of the Roman
Empire, admits of little doubt, and the supposition derived from
identity of racial character finds corroboration in the fact that the
568
Dahæ, a famous Parthian tribe, dwelt in ancient days in the
region between the Balkans and the river Atrak, which is still called
Dehistān. But the strangers from the icy north were not long
contented to roam over steppes which were well-nigh as hospitable
as those of Siberia. They smelt booty in the richly watered slopes of
the Kopet Dāgh and the populous cities of Northern Persia. The era
of the Sāmānides (A.D. 218–639) was one of constant struggles
between these unwelcome immigrants and the settled Iranians of
Northern Persia, and history repeated itself in the ruin and
desolation which befell the latter. Towards the end of the Middle
Ages the northern portion of the old empire of Darius was given up
to Turkoman tribes bent on war and pillage. At this date we find
them divided into many tribes. The most famous were the Salors,
who possessed some at least of the traits of the noble savage of
fiction. They dwelt at the edge of the hills on the oasis formed by
the Murghāb and Tajand. In the twelfth century the Sultan Sanjar,
the greatest of the Seljūkides, was defeated by the Kara and Alieli
Turkomans at Andakhūy and Maymena, where both are still to be
found. The Balkan Mountains in the sixteenth century looked down
on Ersari encampments, and at an earlier date the peninsula of
Mangishlāk was roamed over by various tribes. For centuries
unnumbered the Turkomans were free from foreign influence, and
maintained the primitive ferocity and power for aggression
unleavened by intercourse with civilisation. They found their master
in rare exceptions to the long succession of debauchees who filled
the throne of Persia. In the seventeenth century Shāh `Abbās the
Great (1585–1626) drove them from the rich valleys of the Kopet
Dāgh and planted colonies of 15,000 Kurds along the crest, in the
not altogether vain hope that these scourges of Asia Minor would
hold their neighbours in check. Nādir Shāh, infamous for the
bloodshed attending his capture of Delhi, was himself a Turkoman,
and proved more than a match for his kinsmen. In 1796 Āghā
Mohammad, the first sovereign of the reigning dynasty, who was
also of Turkoman origin, took effectual measures to protect his
frontier, and, had his brief career not been brought to a close by the
assassin’s dagger, he would doubtless have tamed these fierce
children of the desert. His successor, Fath `Alī Shāh, attempted the
process, and in 1813 the Turkoman tribes appealed to the Tsar of
Russia for assistance against him. Alexander I., however, was then
engaged in rolling back the tide of Napoleon’s invasion, and was
powerless to help them, thus exciting an intense irritation. We obtain
a glimpse of the position occupied by the Turkoman tribes in 1831 in
569
the pages of Burnes. At that date the Tekkes were second to no
tribe in numbers, though they had not reached the commanding
position which they attained at the eve of the Russian conquest. This
section of the Turkoman race is found at the dawn of their history
occupying the Isthmus of Mangishlāk, on the north-eastern coast of
the Caspian. Driven thence in 1718 by the Kalmaks, they dislodged
the Yamuds from Kizil Arvat, and the Kurds and Alielis from the strip
of fertile land at the basis of the Kopet Dāgh, known as the Akkal
oasis. Their name, which in our tongue signifies “Mountain Goat,” is
said to be derived from the agility with which they urged their horses
over the ravines on the mountain side. The Tekkes proclaimed their
allegiance to the Khān of Khiva, and each village paid a tribute of a
camel, but they were forced to recognise the supremacy of Nādir
Shāh. Until the commencement of the present century they were
confined to the limits of the oasis; but population began to press too
heavily on the means of subsistence, which, in Central Asia, is
synonymous with water. The cultivation spread to such an extent
that the arīks, or small irrigation canals, proved unequal to its
necessities. Hence, about 1830, 10,000 families migrated eastwards
and established themselves on the banks of the Tajand. Here they
built a fort, called after their chief, Oraz Khān Kal`a. The total
570
number of Tekke tents or kibitkas is put by Burnes at 40,000.
THE SEA OF SAND IN THE KARA-KUM DESERT
THE SEA OF SAND IN THE KARA-KUM DESERT

At that epoch the Ersaris roamed over the Upper Oxus, and were
equally numerous with the Tekkes. The Merv oasis was inhabited by
the Sāriks, numbering 20,000 tents, who were engaged in a struggle
with the Khivans, then temporary masters of Merv. The Yamuds,
about as numerous as the Sāriks, wandered between Khiva and
Astrabad in Khorāsān, while the territory watered by the Atrak and
Gurgān was inhabited by the Gokhlans, who acknowledged the sway
of Persia. Finally the Salors, who made up by courage for the paucity
of their numbers, held the upper reaches of the Tajand near
Sarakhs. In 1832 their constant ravages led to reprisals on the
Persian side. They were attacked by an overwhelming force under
`Abbās Mīrzā, son of Shāh Fath `Alī, and after a desperate
resistance their stronghold, Sarakhs, was captured. The survivors
fled northwards and occupied the Yoletan oasis, south of Merv.
Meantime the Tekkes, who had settled in the upper reaches of the
Tajand, had been desolating the northern possessions of Persia, and
the cry of the harassed inhabitants reached the capital. Vigorous
measures were ordered by the Shāh, and in 1845 Āsaf ud-Dawlé,
the governor of Khorāsān, fell on their settlements and utterly
destroyed them. The Tekkes, ousted from their coign of vantage,
sought refuge in the Akkal oasis, but it was already over-peopled,
and their brethren there were constrained to refuse them ingress.
They finally obtained Āsaf ud-Dawlé’s leave to settle in Sarakhs,
which had been depopulated thirteen years earlier by the expulsion
of the Salors. At first they respected the Persian territory, for the
energetic governor of Khorāsān had shown that he knew how to
deal with them. Their relations with Khiva were very different, for
that Khānate was surrounded by nomad tribes, and had no outlet for
the prowess of their cavalry save in conflict with them. Mohammad
Amīn Khān, then sovereign of Khiva, stormed Sarakhs and left a
viceroy with a garrison there. Hardly was his back turned when the
Tekkes rose at the intruders and put them to the sword. This
outrage brought the Khān again into the field. He laid siege to
Sarakhs, but, while directing the operations upon a mound on the
right bank of the Harī Rūd, was surprised by a body of Turkomans
and decapitated. His head was sent to the Shāh and his body to
Khiva for burial. The Tekkes were encouraged by this brilliant
success to resume their raids into Persia, and again the governor of
Khorāsān was provoked to retaliate. He burnt Sarakhs and drove the
Tekkes northwards as far as Merv, which had, with one brief interval,
been held by the Sāriks since its devastation by the Amīr of Bokhārā
in 1784. The inhabitants resisted the Tekkes’ invasion with the fierce
jealousy which reigned between all Turkoman tribes. They implored
help of the Persians, and the governor of Khorāsān forthwith
marched on Merv with 18 battalions and 7000 cavalry. The Tekkes,
finding themselves between two fires, offered submission to Persia,
and rendered it acceptable by costly gifts. Then they turned on the
churlish Sāriks, and drove them from Merv to the oases of Yoletan
and Panjdih in the upper reaches of the Murghāb, dispossessing in
their turn the Salors, who, with the permission of the Persian
571
authorities, settled at Zarābād on the left bank of the Harī Rūd.
Thus the pressure of population in the Akkal oasis led to a dispersal
of the Tekkes who inhabited it. In little more than a quarter of a
century we find them masters of the wondrously fertile lands
irrigated by the Murghāb, after dislodging the former occupants and
destroying a force sent against them by the greatest of Khivan
rulers. On taking possession of their conquest the Tekkes began to
develop its resources according to their lights. They made a rude
dam twenty-five miles above Merv, and excavated twenty-four small
572
canals which irrigated lands sufficient to support 48,000 families.
But they were as far from being peaceful cultivators as ever. They
overran the whole of Khorāsān, and carried their raids 450 miles
south of its capital, Meshed. Stung to madness by the desolation
thus wrought, the Persians planned a systematic vengeance.
In 1860 they built a fort as a basis of their operations, which
they called New Sarakhs, opposite the old citadel of that name.
Then, in the following year, the commander-in-chief advanced
against Merv with a force of 12,000 infantry, 10,000 horsemen, and
33 guns. The Tekkes, in great alarm, offered submission and a
substantial tribute. But the Persian general, confident in his numbers
and armament, would hear of no compromise. The tribesmen,
compelled to fight for life and freedom, acquitted themselves with a
gallantry which inspired terror in the invaders. The Persian
artillerymen and infantry were slain or captured to a man, and the
guns served twenty years after to arm a citadel which the Tekkes
573
built as a defence against an anticipated Russian attack. The
cavalry alone, including the cowardly commander-in-chief, found
safety in flight, and so great was the glut of prisoners that the price
of a Persian slave in Khivan and Bokhāran markets fell to a sum
574
equal to a pound sterling. This was the last organised attempt
from the Persian side to subvert Tekke independence, and the tribe,
settled firmly in the great oases of Akkal and Merv, were free to
pursue their lawless impulses at the expense of their neighbours. For
Persia was not alone in serving as a quarry. The fierce children of
the steppes carried rapine and murder within a few miles of the
575
citadel of Herāt, and spread far and wide a terror as abject as
that inspired by the Danish pirates in the coast towns of Saxon
England. Such is the history of the rise of the Tekke division of the
Turkoman race to a position which rendered it the chief obstacle to
the Russian advance. It is a modern reproduction, in miniature, of
the great Mongol movement which, starting seven centuries ago,
has not yet spent its force. Like the other Turkoman tribes, the
Tekkes were ranged in divisions and clans—the Tokhtamish
inhabiting the eastern portion of the Merv oasis, while the Otamish
576
occupied the western. In the extreme east lived the Beks. These
great divisions were split up into minor ones, and the latter again
ramified into clans.
The organisation applied to Tekkes of the Akkal and Merv oases
alike, for members of the various sections were scattered over the
577
entire territory in their occupation. Government among the Tekkes
578
of every tribe was a pure democracy. Affairs of state were
discussed by an assembly consisting of the entire population. These
gatherings elected a Khān to represent the executive by
acclamation, and withdrew the dignity when the chosen one ceased
to please. The office was not an object of ambition, for the Khān’s
authority was little more than a matter of form. He had forty jigits,
or attendants, to enforce order; but he had not the power of the
purse. For special purposes a tribal representative, termed Ikhtiyār,
was chosen by the popular assembly. Thus, in 1881, O’Donovan
found one at Merv who had been sent to treat with the Shāh of
579
Persia at Teheran. In latter days the tribe exhibited a tendency to
follow the ordinary evolution of a state, which is from a democracy
to a hereditary monarchy acquired by the sword. The new departure
began with a famous chieftain named Nūr Verdi Khān, who had led
the Tekkes in the victories over the Khivans, the Persians, and the
Sāriks. He was intrepid, just, and hospitable, moulded in the stamp
of those who carve for themselves empire, and his influence was so
great that he was permitted to hand over the chiefship of the Akkal
580
Tekkes to his son Makhdūm Kulī Khān, when he assumed that of
the Merv oasis. The growth of the hereditary principle was doubtless
fostered by the sense of impending danger from the Russian
avalanche. In earlier times an attempt to introduce it would have
been fiercely resisted by the untamed nomads. Old age and
experience alone commanded weight, and the yoke of
Mohammedanism, elsewhere so heavy in the East, pressed but
lightly on these popular assemblies. Though nominally Sunnis or
orthodox followers of the Prophet, the Turkomans practised few of
the interminable observances prescribed by the Koran; and the
mullās, mostly steeped in ignorance, possessed no influence over
581
them. But the Tekkes felt instinctively the impossibility of
maintaining democratic methods in times of stress. Military
operations were confided to the tribesmen of known valour and
582
intelligence, termed Sardārs, who had a minute knowledge of the
country to be traversed, and were intrusted with the direction of the
raids, which were the main object of the Turkoman’s existence. Thus
did these banditti acquire prisoners who could be held to ransom,
and slaves who found a ready market in the neighbouring Khānates.
583
The things needed were a good horse, arms, and a contempt for
death. “He who puts his hand to his sword-hilt,” runs a Turkoman
proverb, “hath no need to ask for a good reason.” “On horseback,”
says another, “a Tekke knows neither father nor mother.” When one
of these natural leaders of men determined on a foray, he planted
his lance, surmounted by a flag, in the ground in front of his kibitka,
and invited all good Musulmans, in the name of the Prophet, to
range themselves under his banner.
The call to arms was rarely disregarded; and the Sardār soon
found his tent besieged by several hundreds, or even thousands, of
warriors prepared to yield him a blind obedience. He fixed the date
and place of gathering, but the object was not disclosed. On the day
prescribed his followers assembled, each on a well-trained stallion,
and leading spare horses with provisions. If the object of attack lay
in the plains of Khorāsān, the Kopet Dāgh Mountains were scaled by
one of the three passes practicable to Tekke horsemen. On reaching
the southern slopes, the provisions were left in some sure retreat,
known only to the Sardār, under the charge of a few horsemen,
584
while the day was spent in preparing for the raid. Far in the valley
below lay the village destined to destruction. The smoke curled
upwards from its white cottages embowered in forest trees. The old
men gossiped in the evening sun; the maidens were bringing home
the cattle from the pastures. This was the moment chosen for the
onslaught. In a few moments the village street was thronged with
fierce Turkomans bending low over the saddle-bow and hacking and
stabbing right and left. Then the survivors, with the cattle and
valuables, were gathered together and hurried off to the robbers’
lair. When pursuit was feared, 100 or even 130 miles were traversed
ere rein was drawn. The girls and child captives, being more
valuable than adults, were carried at some warrior’s saddle-bow, but
all able to run were dragged in chains behind the captors. When
they sank from fatigue their sufferings were ended by a thrust from
the long Turkoman dagger. If the quarry were a Kurd village, greater
precautions were needed, for every settlement had its tower into
which the population fled on an alarm being given. These fortresses
were sometimes stormed while the defenders slept, and the garrison
stabbed with fiendish ferocity. In dealing with caravans, the
585
Turkomans lay in wait for their prey in the vicinity of wells, and
swooped down on the travellers during their halt. At other times
they hung on the outskirts of the procession of camels and cut off
stragglers. Success depended on the suddenness of attack; and if it
failed it was seldom repeated, for bravery was not a characteristic of
the Turkoman, except when the safety and honour of his family were
at stake. Then, as the Russians found to their cost, they fought like
lions.
For the slaves a ready market was found in the Khānates of
Khiva and Bokhārā, whence dealers visited Tekke settlements at
frequent intervals. The traffic was of ancient date, and, until the
advent of the Russians, was recognised by law and custom. Florio
Beneveni, an Italian who passed some time at Bokhārā in the early
part of the eighteenth century, informed Peter the Great that 3000
Russians were held captive there, and, at the commencement of our
own, Mouravieff reported that a similar number languished in
586
bondage in Khiva. Wolff, writing in 1843, estimated the number of
Persian slaves in Bokhārā at 200,000, and those detained at Khiva
about the same period were stated by Major Abbott to exceed
700,000. The price paid varied with the age of the prisoner, children
and young girls being twice as valuable as adults.
But the Tekke considered his steed as even more indispensable
than a trusted leader to success in pursuing his inherited instinct.
The fame of the Turkoman horse is as old as Alexander’s days. Tīmūr
improved the breed by distributing 5000 Arab stallions among the
tribesmen, and in our own day Shāh Nāsir ud-Dīn, of Persia,
587
unwisely sent 600 to his ancient foes. But the Turkoman’s
innocent ally in his marauding expeditions showed hardly any traces
of Arab ancestry. He was big, leggy, and narrow-chested, with a high
588
crupper, large head, and sloping quarters. The neck and tail
showed none of the proud curves which characterise the courser of
Yemen. At short distances he was no match for the English
thoroughbred; but with careful training and special diet he was able
589
to amble for 60 or 70 miles a day for an almost unlimited period.
When hard pressed, a Tekke has been known to travel with two
steeds at the rate of 160 miles a day, and even more. The
endurance of the horseman was even more remarkable, for he could
keep his saddle for twenty hours out of the twenty-four during eight
590
consecutive days. The Tekke stallions—mares were rarely ridden—
were not indulged in stabling, but picketed outside their owner’s
591
tent, and preserved against cold by layers of felt, the number of
which increased with his age. They were never removed without the
greatest precaution, and served to maintain the coat in a lustrous
sheen, though a knife and a piece of felt were the only substitutes
for the currycomb, brush, and clippers of Western stables. On these
coverings was placed the wooden saddle with a high peak, which
was covered with a piece of coloured silk tied across the chest. The
Turkoman’s warmest affections were lavished on his steed, with
whom he would share the last drop of water, the last handful of
barley meal. The whip was carried merely for show, and spurs were
unknown. His attachment was repaid by his dumb friend, whose
fiercest encounter with another stallion could be stayed by his
master’s well-known accents.
The daily life of the Turkoman varied with the category to which
he belonged. Those who adopted a nomad existence were styled
592
Chomry, and dwellers in fixed habitations Charva; but they
passed from one stage to the other at their own inclination, wealth
593
being the prevailing factor. The nomads wandered on the banks
of the rivers and the limits of the desert where the mountain
streams had not been absorbed by the thirsty sands. Their herds
were their only wealth, and they rarely pitched their felt abodes for
more than three days at any spot. The Chomry, or sedentary
Turkomans, dwelt for a portion of the year in fastnesses termed
kal`a, open spaces crowded with their tents, and fortified with clay
walls flanked by towers. Around them spread the fields and gardens
of the aul, in which barley, juwārī (holcus sorghum), rice, and finely
flavoured melons were produced in abundance, thanks to the water
distributed by the arīks, or irrigation canals. In times of stress the
fortresses, which had but a single gate, formed places of refuge. At
594
the eve of the Russian conquest the whole Akkal oasis was
covered with these strongholds. They stretched in a single line,
afterwards in two or more lines, from Kizil Arvat to Askabad. The
great stronghold of Geok Teppe, destined to give the Russians so
much trouble, was situated in the broadest part of the oasis;
Askabad, now the headquarters of Transcaspia, was a congeries of
eight of these fortified villages.
The physiognomy of the Turkoman betrays the indelible
Mongolian type. He is above the middle height, of a dark olive
complexion, with prominent cheek-bones, and small almond eyes,
595
shifty, and glittering with intelligence. His nose is generally broad
and uplifted at the extremity, his lips thick, and moustaches scanty.
The ears are very large, and stand up from the head. The senses of
smell and hearing are as strongly developed as those of the Red
596
Indian. In the female the Mongolian strain is even more visible.
Their hair is short, but very thick and coarse. In youth they are tall
597
and well formed, with every movement full of grace. Their rosy
cheeks give a charm to features destined in early middle-life to
become a network of wrinkles. No characteristic of savage life is so
marked as the rapid decay of beauty. The Turkoman dress has
changed but little since he met the Roman legionaries in battle grip.
It consists of a long crimson tunic of coarse Bokhāran silk, with
598
slender black and yellow combined stripes. Over this is worn a
loose dressing-gown, termed jabba, descending below the knee, of
black or dark brown material, which in summer is of cotton and in
winter of camel’s hair or wool. The wealthier adopt the Uzbeg
costume of several jabbas of coarse Bokhārā silk, confined by
waistbands of silk over a shirt and pantaloons of the same material.
The legs are covered with thick socks of a checked pattern, and the
feet with high metal-heeled slippers just large enough to admit the
insertion of the toe. They are slow and ungraceful walkers, and show
to more advantage when on horseback. Then the jabba is tucked
into wide leather boots of a Hessian pattern, giving a most ungainly
appearance to the equestrian. But the distinguishing mark of the
Turkoman is his large cylindrical head-covering of black sheep-skin,
termed kalpak. It is worn over a skull-cap fitting tightly to the half-
shaved head, and is far less heavy than its appearance would imply.
The women’s dress consists in long floating skirts of red or blue
599
silk. The bosom is covered with a sort of cuirass of silver plaques,
coins and amulets, the trophies of her husband’s prowess in war or
raids. The wealthier add bracelets of thick silver, and collars with
plates suspended therefrom, like that worn by Jewish high priests.
Married women confine their stubborn locks in a small, round,
embroidered bonnet, while those of young girls cover their
shoulders. On occasions of ceremony a casque of open silver-work is
600
worn over a red cloth cap, giving a Minerva-like appearance. The
face is partly covered by the end of a silk mantila or burunjak.
The character of the Turkomans before the process of
Russification began was a compound of the virtues and the vices to
be found in half-tamed races of the higher type. He has been
branded as an irreclaimable savage because he wrought untold
misery on the helpless populations within striking distance of his
own den.
But no greater mistake can be made by the student of ethics
than to judge men of other nationalities by the standard of right and
601
wrong maintaining in our own. It would be as unjust to blame the
Turkomans for the bluntness of their moral sense in the matter of
raids as to condemn George Washington because he did not think fit
to emancipate his slaves. By dint of inherited instinct the inhabitant
of Merv and Akkal had come to regard depredations as a necessary
incident of his daily life. His barbarous insensibility while engaged in
an alaman was not inconsistent with the exercise of solid virtues. He
was hospitable to a fault, and is so at the present day, though the
advent of Russians has sorely curtailed his means. A stranger was
made welcome to the Tekke’s smoky kibitka, and was safe beneath
its shelter. He was invited to share the family meal, were it thick
602
cakes of unleavened bread pilaw, compressed curds, or rice boiled
with sour milk. For his delectation the tea-pot, the Persian watet-
603 604
pipe, the chess-board, and the clarionet were produced, and
he was forced to listen till dawn to tales of ancient prowess, to
legends of Iskandar and Tīmūr, those twin heroes of Central Asian
romance. And there was a strain of inbred nobility in the nomad
characters. They were robbers on occasion; but they scorned to
pilfer. Espionage was unknown amongst them. Rarely, indeed, was
the foul abuse so common in Mohammedan countries heard from
Tekke lips. His most scathing epithet was “coward.” His faults were
those of other races which have not come into contact with
605
civilisation. He was greedy, self-indulgent, and prone to take
every advantage possible of a wealthy stranger. His childish curiosity
and utter disregard of that which is conventionally termed good
manners were equally conspicuous. In one essential, indeed, which
is rightly considered to indicate an advanced culture, he shone by
contrast with the people of every other country governed by the
Koran. His women-folk were free from those restraints which dwarf
the intelligence and degrade the moral sense. They went unveiled,
and associated freely with the tribesmen and even with sojourners in
their tents. And yet the standard of chastity was comparatively high;
while in times of stress the Tekke girls fought desperately by their
husbands’ side. It must be admitted that misdeeds were punished
with a dagger-thrust, and that, in a Tekke’s affections, a wife ranks
far below a horse. She rose early to bake her husband’s bread,
cooked and fetched water for him, and presumed not to eat till he
606
had finished his meal. Her industry was extraordinary. Her
embroidery was once a marvel of good taste, and she still weaves
carpets which are unrivalled in Asia for beauty and durability. The
superintendent of the state domains at Bahrām `Alī, near Merv, has
specimens which are more than three centuries old and are yet as
607
brilliant as if they had just left the loom. The method of
manufacture can be watched in every Turkoman village.

You might also like