当前位置:网站首页>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)
边栏推荐
- Tidb data migration scenario overview
- Set set you don't know
- Application and practice of Jenkins pipeline
- MFC timer usage
- 原则、语言、编译、解释
- 06_ Stack and queue conversion
- Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
- Implementation of n queen in C language
- Sharp tool SPL for post SQL calculation
- How to write sensor data into computer database
猜你喜欢
随机推荐
List集合&UML图
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
AtCoder Beginner Contest 254
HUSTPC2022
Let your HMI have more advantages. Fet-g2ld-c core board is a good choice
AtCoder Beginner Contest 254
Printf function and scanf function in C language
学习使用php将时间戳转换为大写日期的方法代码示例
【C语言】详解指针的初阶和进阶以及注意点(1)
CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
传感器数据怎么写入电脑数据库
21_Redis_浅析Redis缓存穿透和雪崩
02_线性表_顺序表
12_ Redis_ Bitmap_ command
Application of CDN in game field
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
03_线性表_链表
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
The traversal methods of binary tree mainly include: first order traversal, middle order traversal, second order traversal, and hierarchical traversal. First order, middle order, and second order actu
20_Redis_哨兵模式