当前位置:网站首页>语义分割学习笔记(一)
语义分割学习笔记(一)
2022-07-02 12:01:00 【浅念念52】
一、区别
语义分割:每个像素都打上标签(这个像素是人,树,背景等)语义分割只区分类别,不区分类别中的具体单元

实例分割:不光要区分类别,还要区分类别中的每一个个体

全景分割:相当于语义分割加上实例分割

二、代码演示原图像与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)
边栏推荐
- 工程师评测 | RK3568开发板上手测试
- C语言实现N皇后问题
- GeoServer offline map service construction and layer Publishing
- 15_Redis_Redis.conf详解
- Solve the problem that El radio group cannot be edited after echo
- 传感器数据怎么写入电脑数据库
- SQL 后计算的利器 SPL
- Deploy tidb cluster with tiup
- MFC console printing, pop-up dialog box
- Data analysis thinking analysis methods and business knowledge - business indicators
猜你喜欢

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)

Leetcode - Search 2D matrix

面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?

CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E

LeetCode - 搜索二维矩阵

飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测

Kibana basic operation
![[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)](/img/7b/2c471c070a3faa981f70136603495a.jpg)
[development environment] install the visual studio community 2013 development environment (download the installation package of visual studio community 2013 with update 5 version)

MFC 定时器使用

07_哈希
随机推荐
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
【C语言】详解指针的初阶和进阶以及注意点(1)
17_Redis_Redis发布订阅
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
871. Minimum refueling times: simple priority queue (heap) greedy question
The past and present lives of visual page building tools
AtCoder Beginner Contest 254
05_ queue
Have you learned the wrong usage of foreach
List集合&UML图
15_Redis_Redis.conf详解
Arithmetic operations and related exercises in C language
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
10_Redis_geospatial_命令
工程师评测 | RK3568开发板上手测试
02_ Linear table_ Sequence table
LeetCode 2320. Count the number of ways to place the house
Base64 编码原来还可以这么理解
Application and practice of Jenkins pipeline