Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不会修仙的道士
labelme
提交
37fe44a9
L
labelme
项目概览
不会修仙的道士
/
labelme
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
labelme
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
37fe44a9
编写于
8月 15, 2018
作者:
K
Kentaro Wada
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add colormap arg to draw_label
上级
9a4c5a70
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
8 deletion
+32
-8
labelme/utils/draw.py
labelme/utils/draw.py
+32
-8
未找到文件。
labelme/utils/draw.py
浏览文件 @
37fe44a9
...
...
@@ -26,15 +26,28 @@ def label_colormap(N=256):
return
cmap
def
_validate_colormap
(
colormap
,
n_labels
):
if
colormap
is
None
:
colormap
=
label_colormap
(
n_labels
)
else
:
assert
colormap
.
shape
==
(
colormap
.
shape
[
0
],
3
),
\
'colormap must be sequence of RGB values'
assert
0
<=
colormap
.
min
()
and
colormap
.
max
()
<=
1
,
\
'colormap must ranges 0 to 1'
return
colormap
# similar function as skimage.color.label2rgb
def
label2rgb
(
lbl
,
img
=
None
,
n_labels
=
None
,
alpha
=
0.5
,
thresh_suppress
=
0
):
def
label2rgb
(
lbl
,
img
=
None
,
n_labels
=
None
,
alpha
=
0.5
,
thresh_suppress
=
0
,
colormap
=
None
,
):
if
n_labels
is
None
:
n_labels
=
len
(
np
.
unique
(
lbl
))
c
map
=
label_colormap
(
n_labels
)
c
map
=
(
c
map
*
255
).
astype
(
np
.
uint8
)
c
olormap
=
_validate_colormap
(
colormap
,
n_labels
)
c
olormap
=
(
color
map
*
255
).
astype
(
np
.
uint8
)
lbl_viz
=
cmap
[
lbl
]
lbl_viz
=
c
olor
map
[
lbl
]
lbl_viz
[
lbl
==
-
1
]
=
(
0
,
0
,
0
)
# unlabeled
if
img
is
not
None
:
...
...
@@ -48,8 +61,18 @@ def label2rgb(lbl, img=None, n_labels=None, alpha=0.5, thresh_suppress=0):
return
lbl_viz
def
draw_label
(
label
,
img
=
None
,
label_names
=
None
,
colormap
=
None
):
def
draw_label
(
label
,
img
=
None
,
label_names
=
None
,
colormap
=
None
,
**
kwargs
):
"""Draw pixel-wise label with colorization and label names.
label: ndarray, (H, W)
Pixel-wise labels to colorize.
img: ndarray, (H, W, 3), optional
Image on which the colorized label will be drawn.
label_names: iterable
List of label names.
"""
import
matplotlib.pyplot
as
plt
backend_org
=
plt
.
rcParams
[
'backend'
]
plt
.
switch_backend
(
'agg'
)
...
...
@@ -62,10 +85,11 @@ def draw_label(label, img=None, label_names=None, colormap=None):
if
label_names
is
None
:
label_names
=
[
str
(
l
)
for
l
in
range
(
label
.
max
()
+
1
)]
if
colormap
is
None
:
colormap
=
label_colormap
(
len
(
label_names
))
colormap
=
_validate_colormap
(
colormap
,
len
(
label_names
))
label_viz
=
label2rgb
(
label
,
img
,
n_labels
=
len
(
label_names
))
label_viz
=
label2rgb
(
label
,
img
,
n_labels
=
len
(
label_names
),
colormap
=
colormap
,
**
kwargs
)
plt
.
imshow
(
label_viz
)
plt
.
axis
(
'off'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录