技术专栏
语义分割学习笔记
文章目录
一、区别
- 语义分割:每个像素都打上标签(这个像素是人,树,背景等)语义分割只区分类别,不区分类别中的具体单元
实例分割:不光要区分类别,还要区分类别中的每一个个体
全景分割:相当于语义分割加上实例分割
二、代码演示原图像与mask融合
from PIL import Image
import imgviz
import numpy as np
image_file=r'D:\aaa\envs\labelme\Scripts\2_3_json\img.png'
mask_file=r'D:\aaa\envs\labelme\Scripts\2_3_json\label.png'
image=Image.open(image_file)
mask=Image.open(mask_file)
mask_img=Image.blend(image.convert("RGBA"),
mask.convert("RGBA"),0.5)
mask_img.save("vis2.png")
三、数据处理
将labelme标注好的json转换成mask图像
import json
import os
import imgviz
import numpy as np
from PIL import Image
import cv2
import glob
def save_colored_mask(mask,image_file):
lbl_image=Image.fromarray(mask.astype(np.uint8),mode='P')
colormap=imgviz.label_colormap()
lbl_image.putpalette(colormap.flatten())
lbl_image.save(image_file)
json_files=r'E:\桌面\资料\语义分割'
img_file=r'E:\桌面\资料\语义分割\图片'
json_l=glob.glob(os.path.join(json_files,'*.json'))
for json_ in json_l:
name=os.path.basename(json_)
img_name=name.replace('json','png')
fs=open(json_,encoding='utf-8')
dict_=json.load(fs)
# 获取图像 宽,高
height = dict_['imageHeight']
width = dict_['imageWidth']
shapes = dict_["shapes"]
# 生成一个全零图像
img = np.zeros((height, width), dtype=np.uint8)
label_color = {"sheep": 1}
for shape in shapes:
# 解析多边形轮廓点的坐标
points = shape['points']
# 解析多边形的标签
label = shape['label']
points = np.array(points, dtype=np.int32)
# 绘制轮廓
cv2.polylines(img, [points], isClosed=True, color=(255), thickness=2)
# 填充多边形颜色
cv2.fillPoly(img, [points], color=label_color[label])
img_path=os.path.join(img_file,img_name)
print(img_path)
save_colored_mask(img, img_path)
声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包
点赞
收藏
评论
打赏
- 分享
- 举报
评论
0个
手气红包
![易百纳技术社区](https://ebaina.oss-cn-hangzhou.aliyuncs.com/production/direct/resource/202306/14/empty.png)
相关专栏
-
浏览量:11047次2021-06-25 15:00:55
-
浏览量:1544次2023-02-14 14:48:11
-
浏览量:935次2023-06-03 15:59:06
-
浏览量:926次2023-12-28 13:59:27
-
浏览量:2023次2020-08-28 16:40:19
-
浏览量:13343次2021-07-08 09:43:47
-
浏览量:651次2023-07-05 10:16:37
-
浏览量:677次2023-06-03 15:58:59
-
浏览量:952次2023-03-02 14:50:04
-
浏览量:7478次2021-07-19 17:08:40
-
浏览量:5117次2021-06-09 14:02:36
-
浏览量:6754次2021-06-08 14:50:34
-
浏览量:568次2023-07-24 15:23:06
-
浏览量:671次2023-06-02 17:42:13
-
浏览量:552次2023-06-03 15:58:33
-
浏览量:3156次2020-08-18 11:46:20
-
浏览量:8772次2021-07-19 17:09:44
-
浏览量:13222次2021-07-05 09:47:30
-
浏览量:7344次2021-07-19 17:10:27
置顶时间设置
结束时间
删除原因
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖
打赏作者
![易百纳技术社区](https://ebaina.oss-cn-hangzhou.aliyuncs.com/direct/wechat/avatar/avatar_fake32.jpg)
mini菜
您的支持将鼓励我继续创作!
打赏金额:
¥1
![易百纳技术社区](/img/web/choose_active.png)
¥5
![易百纳技术社区](/img/web/choose_active.png)
¥10
![易百纳技术社区](/img/web/choose_active.png)
¥50
![易百纳技术社区](/img/web/choose_active.png)
¥100
![易百纳技术社区](/img/web/choose_active.png)
支付方式:
![易百纳技术社区](/img/web/paywx.png)
举报反馈
举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明
审核成功
发布时间设置
发布时间:
请选择发布时间设置
是否关联周任务-专栏模块
审核失败
失败原因
请选择失败原因
备注
请输入备注