File tree Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Original file line number Diff line number Diff line change 1+ ==========
2+ Chapter 10
3+ ==========
4+
5+ Support code for *Chapter 10: Pattern Recognition & Computer Vision *
6+
7+ Data
8+ ----
9+
10+ This chapter relies on a publicly available dataset (which can be downloaded
11+ using the ``download.sh `` script inside the ``data/ `` directory) as well the
12+ dataset that is packaged with the repository at ``../SimpleImageDataset/ ``.
13+
14+ Running ``download.sh `` will retrieve the other dataset into a directory
15+ ``AnimTransDistr/ ``.
16+
17+ Scripts
18+ -------
19+
20+ threshold.py
21+ Threshold building image with both Otsu and Ridley-Calvard threshold
22+ lena-ring.py
23+ Show Lena in a sharp ring around a soft focus image
24+ figure5_6.py
25+ Computes figures 5 and 6 in the book
26+ figure9.py
27+ Compute Sobel images
28+ figure10.py
29+ Just paste two images next to each others
30+ figure13.py
31+ Demonstrate salt&pepper effect
32+ edginess.py
33+ Contains the ``edginess_sobel `` function from the book
34+ simple_classification.py
35+ Classify SimpleImageDataset with texture features + sobel feature
36+ figure18.py
37+ Classify ``AnimTransDistr `` with both texture and SURF features.
38+
Original file line number Diff line number Diff line change 99import mahotas as mh
1010image = mh .imread ('../SimpleImageDataset/building05.jpg' )
1111image = mh .colors .rgb2gray (image )
12- im8 = mh .gaussian_filter (image , 8 )
12+
13+ # Compute Gaussian filtered versions with increasing kernel widths
14+ im8 = mh .gaussian_filter (image , 8 )
1315im16 = mh .gaussian_filter (image , 16 )
1416im32 = mh .gaussian_filter (image , 32 )
17+
18+ # We now build a composite image with three panels:
19+ #
20+ # [ IM8 | | IM16 | | IM32 ]
21+
1522h , w = im8 .shape
1623canvas = np .ones ((h , 3 * w + 256 ), np .uint8 )
1724canvas *= 255
2027canvas [:, - w :] = im32
2128mh .imsave ('../1400OS_10_05+.jpg' , canvas [:, ::2 ])
2229
30+ # Threshold the image
31+ # We need to first stretch it to convert to an integer image
2332im32 = mh .stretch (im32 )
2433ot32 = mh .otsu (im32 )
25- mh .imsave ('../1400OS_10_06+.jpg' , (im32 > ot32 ).astype (np .uint8 ) * 255 )
34+
35+ # Convert to 255 np.uint8 to match the other images
36+ im255 = 255 * (im32 > ot32 ).astype (np .uint8 )
37+ mh .imsave ('../1400OS_10_06+.jpg' , im255 )
Original file line number Diff line number Diff line change 99import mahotas as mh
1010image = mh .imread ('../SimpleImageDataset/building05.jpg' )
1111image = mh .colors .rgb2gray (image , dtype = np .uint8 )
12+
13+ # We need to downsample ``image`` so that the details are visibly pixelated.
14+ # This exaggerates the effect so that the result is clear
1215image = image [::4 , ::4 ]
1316thresh = mh .sobel (image )
1417filtered = mh .sobel (image , just_filter = True )
1518
1619thresh = mh .dilate (thresh , np .ones ((7 , 7 )))
1720filtered = mh .dilate (mh .stretch (filtered ), np .ones ((7 , 7 )))
1821
19-
22+ # Paste the thresholded and non-thresholded versions of the image side-by-side
2023h , w = thresh .shape
2124canvas = 255 * np .ones ((h , w * 2 + 64 ), np .uint8 )
2225canvas [:, :w ] = thresh * 255
You can’t perform that action at this time.
0 commit comments