FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
BuildingMachineLearningSystemsWithPython/ch10/lena-ring.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
/
lena-ring.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (32 loc) · 983 Bytes
Breadcrumbs
BuildingMachineLearningSystemsWithPython
/
ch10
/
lena-ring.py
Copy path
File metadata and controls
41 lines (32 loc) · 983 Bytes
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
35
36
37
38
39
40
41
# 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
mahotas
as
mh
import
numpy
as
np
# Read in the image
im
=
mh
.
demos
.
load
(
'lena'
)
# This breaks up the image into RGB channels
r
,
g
,
b
=
im
.
transpose
(
2
,
0
,
1
)
h
,
w
=
r
.
shape
# smooth the image per channel:
r12
=
mh
.
gaussian_filter
(
r
,
12.
)
g12
=
mh
.
gaussian_filter
(
g
,
12.
)
b12
=
mh
.
gaussian_filter
(
b
,
12.
)
# build back the RGB image
im12
=
mh
.
as_rgb
(
r12
,
g12
,
b12
)
X
,
Y
=
np
.
mgrid
[:
h
, :
w
]
X
=
X
-
h
/
2.
Y
=
Y
-
w
/
2.
X
/=
X
.
max
()
Y
/=
Y
.
max
()
# Array C will have the highest values in the center, fading out to the edges:
C
=
np
.
exp
(
-
2.
*
(
X
**
2
+
Y
**
2
))
C
-=
C
.
min
()
C
/=
C
.
ptp
()
C
=
C
[:, :,
None
]
# The final result is sharp in the centre and smooths out to the borders:
ring
=
mh
.
stretch
(
im
*
C
+
(
1
-
C
)
*
im12
)
mh
.
imsave
(
'lena-ring.jpg'
,
ring
)
Back
|
FazBrowse Home
|
New Git URL