FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BuildingMachineLearningSystemsWithPython/ch10/threshold.py at master · luispedro/BuildingMachineLearningSystemsWithPython · GitHub
luispedro
/
BuildingMachineLearningSystemsWithPython
Public
Notifications
You must be signed in to change notification settings
Fork
1.4k
Star
2.1k
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
BuildingMachineLearningSystemsWithPython
/
ch10
/
threshold.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (27 loc) · 1.16 KB
Breadcrumbs
BuildingMachineLearningSystemsWithPython
/
ch10
/
threshold.py
Copy path
File metadata and controls
34 lines (27 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# This code is supporting material for the book
# Building Machine Learning Systems with Python
# by Willi Richert and Luis Pedro Coelho
# published by PACKT Publishing
#
# It is made available under the MIT License
import
numpy
as
np
import
mahotas
as
mh
# Load our example image:
image
=
mh
.
imread
(
'../SimpleImageDataset/building05.jpg'
)
# Convert to greyscale
image
=
mh
.
colors
.
rgb2gray
(
image
,
dtype
=
np
.
uint8
)
# Compute a threshold value:
thresh
=
mh
.
thresholding
.
otsu
(
image
)
print
(
'Otsu threshold is {0}'
.
format
(
thresh
))
# Compute the thresholded image
otsubin
=
(
image
>
thresh
)
print
(
'Saving thresholded image (with Otsu threshold) to otsu-threshold.jpeg'
)
mh
.
imsave
(
'otsu-threshold.jpeg'
,
otsubin
.
astype
(
np
.
uint8
)
*
255
)
# Execute morphological opening to smooth out the edges
otsubin
=
mh
.
open
(
otsubin
,
np
.
ones
((
15
,
15
)))
mh
.
imsave
(
'otsu-closed.jpeg'
,
otsubin
.
astype
(
np
.
uint8
)
*
255
)
# An alternative thresholding method:
thresh
=
mh
.
thresholding
.
rc
(
image
)
print
(
'Ridley-Calvard threshold is {0}'
.
format
(
thresh
))
print
(
'Saving thresholded image (with Ridley-Calvard threshold) to rc-threshold.jpeg'
)
mh
.
imsave
(
'rc-threshold.jpeg'
, (
image
>
thresh
).
astype
(
np
.
uint8
)
*
255
)
Back
|
FazBrowse Home
|
New Git URL