Approximate and subdivide polygons
skimage.draw
import
from
skimage.measure
import
,
,
=
(
[
[
1.64516129
,
1.16145833
],
[
1.64516129
,
1.59375
],
[
1.35080645
,
1.921875
],
[
1.375
,
2.18229167
],
[
1.68548387
,
1.9375
],
[
1.60887097
,
2.55208333
],
[
1.68548387
,
2.69791667
],
[
1.76209677
,
2.56770833
],
[
1.83064516
,
1.97395833
],
[
1.89516129
,
2.75
],
[
1.9516129
,
2.84895833
],
[
2.01209677
,
2.76041667
],
[
1.99193548
,
1.99479167
],
[
2.11290323
,
2.63020833
],
[
2.2016129
,
2.734375
],
[
2.25403226
,
2.60416667
],
[
2.14919355
,
1.953125
],
[
2.30645161
,
2.36979167
],
[
2.39112903
,
2.36979167
],
[
2.41532258
,
2.1875
],
[
2.1733871
,
1.703125
],
[
2.07782258
,
1.16666667
],
]
)
=
.
copy
()
for
in
range
(
5
):
=
(
,
degree
=
2
,
preserve_ends
=
True
)
=
(
,
tolerance
=
0.02
)
print
(
"Number of coordinates:"
,
len
(
),
len
(
),
len
(
))
,
(
,
)
=
(
ncols
=
2
,
figsize
=
(
9
,
4
))
(
[:,
0
],
[:,
1
])
(
[:,
0
],
[:,
1
])
(
[:,
0
],
[:,
1
])
=
((
800
,
800
),
'int32'
)
,
=
(
250
,
250
,
180
,
230
,
)
[
,
]
=
1
,
=
(
600
,
600
,
150
,
90
,
)
[
,
]
=
1
plt
.
gray
()
(
)
for
in
(
,
0
):
=
(
,
tolerance
=
2.5
)
(
[:,
1
],
[:,
0
],
'-r'
,
linewidth
=
2
)
=
(
,
tolerance
=
39.5
)
(
[:,
1
],
[:,
0
],
'-g'
,
linewidth
=
2
)
print
(
"Number of coordinates:"
,
len
(
),
len
(
),
len
(
))
((
0
,
800
,
0
,
800
))
()
Total running time of the script: (0 minutes 0.295 seconds)