File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 77
88import numpy as np
99import mahotas as mh
10+
11+ # Load our example image:
1012image = mh .imread ('../SimpleImageDataset/building05.jpg' )
13+
14+ # Convert to greyscale
1115image = mh .colors .rgb2gray (image , dtype = np .uint8 )
16+
17+ # Compute a threshold value:
1218thresh = mh .thresholding .otsu (image )
13- print (thresh )
19+ print ('Otsu threshold is {0}' .format (thresh ))
20+
21+ # Compute the thresholded image
1422otsubin = (image > thresh )
23+ print ('Saving thresholded image (with Otsu threshold) to otsu-threshold.jpeg' )
1524mh .imsave ('otsu-threshold.jpeg' , otsubin .astype (np .uint8 ) * 255 )
16- otsubin = ~ mh .close (~ otsubin , np .ones ((15 , 15 )))
25+
26+ # Execute morphological opening to smooth out the edges
27+ otsubin = mh .open (otsubin , np .ones ((15 , 15 )))
1728mh .imsave ('otsu-closed.jpeg' , otsubin .astype (np .uint8 ) * 255 )
1829
30+ # An alternative thresholding method:
1931thresh = mh .thresholding .rc (image )
20- print (thresh )
32+ print ('Ridley-Calvard threshold is {0}' .format (thresh ))
33+ print ('Saving thresholded image (with Ridley-Calvard threshold) to rc-threshold.jpeg' )
2134mh .imsave ('rc-threshold.jpeg' , (image > thresh ).astype (np .uint8 ) * 255 )
You can’t perform that action at this time.
0 commit comments