当前位置:网站首页>Semantic segmentation learning notes (1)
Semantic segmentation learning notes (1)
2022-07-02 15:24:00 【Shallow thoughts 52】
List of articles
One 、 difference
Semantic segmentation : Each pixel is labeled ( This pixel is human , Trees , Background, etc ) Semantic segmentation only distinguishes categories , Do not distinguish specific units in the classification

Instance segmentation : Not only to distinguish categories , Also distinguish each individual in the category

Panoramic segmentation : It is equivalent to semantic segmentation plus instance segmentation

Two 、 The code demonstrates the original image and mask The fusion
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")

3、 ... and 、 Data processing
take labelme Marked json convert to mask Images
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:\ desktop \ Information \ Semantic segmentation '
img_file=r'E:\ desktop \ Information \ Semantic segmentation \ picture '
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)
# Get images wide , high
height = dict_['imageHeight']
width = dict_['imageWidth']
shapes = dict_["shapes"]
# Generate an all zero image
img = np.zeros((height, width), dtype=np.uint8)
label_color = {
"sheep": 1}
for shape in shapes:
# Analyze the coordinates of polygon contour points
points = shape['points']
# Parse polygon labels
label = shape['label']
points = np.array(points, dtype=np.int32)
# Draw the outline
cv2.polylines(img, [points], isClosed=True, color=(255), thickness=2)
# Fill polygon color
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)
边栏推荐
- 20_ Redis_ Sentinel mode
- 如何用 Sysbench 测试 TiDB
- 你不知道的Set集合
- yolo格式数据集处理(xml转txt)
- 数据库内容输出有问题怎么解决
- 10_ Redis_ geospatial_ command
- How to avoid 7 common problems in mobile and network availability testing
- Learn the method code example of converting timestamp to uppercase date using PHP
- 16_ Redis_ Redis persistence
- 牛客练习赛101
猜你喜欢
随机推荐
05_队列
學習使用php實現公曆農曆轉換的方法代碼
使用 TiUP 部署 TiDB 集群
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
06_ Stack and queue conversion
工程师评测 | RK3568开发板上手测试
你不知道的Set集合
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
TiDB 环境与系统配置检查
10_Redis_geospatial_命令
How does the computer set up speakers to play microphone sound
牛客练习赛101
02_线性表_顺序表
14_Redis_乐观锁
Map introduction
C thread transfer parameters
YOLOV5 代码复现以及搭载服务器运行
Map介绍
MFC timer usage







