File tree Expand file tree Collapse file tree 3 files changed +24
-21
lines changed
Expand file tree Collapse file tree 3 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -29,8 +29,9 @@ figure10.py
2929 Just paste two images next to each others
3030figure13.py
3131 Demonstrate salt&pepper effect
32- edginess.py
33- Contains the ``edginess_sobel `` function from the book
32+ features.py
33+ Contains the ``edginess_sobel `` function from the book as well as a simple
34+ wrapper around ``mahotas.texture.haralick ``
3435simple_classification.py
3536 Classify SimpleImageDataset with texture features + sobel feature
3637figure18.py
Original file line number Diff line number Diff line change @@ -20,3 +20,20 @@ def edginess_sobel(image):
2020 edges = mh .sobel (image , just_filter = True )
2121 edges = edges .ravel ()
2222 return np .sqrt (np .dot (edges , edges ))
23+
24+ def texture (im ):
25+ '''Compute features for an image
26+
27+ Parameters
28+ ----------
29+ im : ndarray
30+
31+ Returns
32+ -------
33+ fs : ndarray
34+ 1-D array of features
35+ '''
36+ im = im .astype (np .uint8 )
37+ return mh .features .haralick (im ).mean (0 )
38+
39+
Original file line number Diff line number Diff line change 1010from sklearn .linear_model .logistic import LogisticRegression
1111import numpy as np
1212from glob import glob
13- from edginess import edginess_sobel
13+ from features import texture , edginess_sobel
1414
1515basedir = '../SimpleImageDataset/'
1616
1717
18- def features_for (im ):
19- '''Compute features for an image
20-
21- Parameters
22- ----------
23- im : str
24- filepath for image to process
25-
26- Returns
27- -------
28- fs : ndarray
29- 1-D array of features
30- '''
31- im = mh .imread (im , as_grey = True ).astype (np .uint8 )
32- return mh .features .haralick (im ).mean (0 )
33-
3418haralicks = []
3519sobels = []
3620labels = []
@@ -40,8 +24,9 @@ def features_for(im):
4024# Use glob to get all the images
4125images = glob ('{}/*.jpg' .format (basedir ))
4226for fname in images :
43- haralicks .append (features_for (fname ))
44- sobels .append (edginess_sobel (mh .imread (fname , as_grey = True )))
27+ im = mh .imread (fname , as_grey = True )
28+ haralicks .append (texture (im ))
29+ sobels .append (edginess_sobel (im ))
4530
4631 # Files are named like building00.jpg, scene23.jpg...
4732 labels .append (fname [:- len ('xx.jpg' )])
You can’t perform that action at this time.
0 commit comments