当前位置:网站首页>Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
Opencv basic operation 2 realizes label2rgb and converts gray-scale images into color images
2022-07-01 01:21:00 【Ten thousand miles and a bright future arrived in an instant】
All the images obtained by semantic segmentation are gray-scale images , It is not conducive to viewing the segmentation effect , Through to label The value changes linearly three times , You can get information about R、G、B Pseudo color of three channels , Then generate a pseudo color image .
The specific code is as follows : For different class_num Of label Data sets , Just adjust the code class_num that will do
cv::Mat set_color(cv::Mat label) {
int class_num = 8;// One has 8 Categories
int color_setp = int(255 / class_num);
cv::Mat tmp,bg;
label.copyTo(tmp);
// Set the background to white
// Put more than 0 All the parts of the are assigned to 0, Less than or equal to 0 The part of is assigned as 255
threshold(tmp, bg, 0, 255, THRESH_BINARY_INV);
cv::Mat G = (class_num - label) * color_setp;
cv::Mat R = label * color_setp;
cv::Mat B = (R + G) / 2;
B.convertTo(B, CV_8UC1);
// Let the background be white
vector<cv::Mat> mv;
mv.push_back(R + bg);
mv.push_back(G + bg);
mv.push_back(B + bg);
cv::Mat RGB;
cv::merge(mv, RGB);
return RGB;
}The effect of the generated pseudo color image is shown in the figure 1 Shown , The background is white .

边栏推荐
猜你喜欢

Exploring the road of steam education innovation in the Internet Era

Exercises on recursion in C language
![[go] go implements row column conversion of sets](/img/d9/6272e55b2d9c6b6fbdf2537773bb83.png)
[go] go implements row column conversion of sets

XJY-220/43AC220V静态信号继电器

人穷志不短,穷学生也能玩转树莓派

2021电赛F题openmv和K210调用openmv api巡线,完全开源。

DLS-20型双位置继电器 220VDC

双位置继电器ST2-2L/AC220V

Day31-t1380-2022-02-15-not answer by yourself

Left join displays the specified value when the left join matching data is null
随机推荐
关于VCTK数据集
探索互联网时代STEAM教育创新之路
ORB-SLAM2源码学习(二)地图初始化
Poor students can also play raspberry pie
uniapp官方组件点击item无效,解决方案
Hoo research | coinwave production - nym: building the next generation privacy infrastructure
ESP8266 RC522
Vnctf 2022 cm CM1 re reproduction
2021电赛F题openmv和K210调用openmv api巡线,完全开源。
Dls-20 double position relay 220VDC
【go】go 实现行专列 将集合进行转列
冲击继电器ZC-23/DC220V
Windows环境下安装MongoDB数据库
5. TPM module initialization
Kongyiji's first question: how much do you know about service communication?
Practical shell knowledge
[learning notes] structure
How to do the performance pressure test of "Health Code"
Problem solving: how to manage thread_local pointer variables
Metauniverse and virtual reality (II)