当前位置:网站首页>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 .

边栏推荐
- About the general input operation mode of unity
- Chromatic judgement bipartite graph
- fluttertoast
- 用Steam教育启发学生多元化思维
- How to do the performance pressure test of "Health Code"
- The real topic of the 11th provincial competition of Bluebridge cup 2020 - crop hybridization
- Double position relay dls-5/2 dc220v
- Inspire students' diversified thinking with steam Education
- A proper job is a good job
- The question of IBL precomputation is finally solved
猜你喜欢
随机推荐
ASCII、Unicode、GBK、UTF-8之间的关系
Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
Parity linked list [two general directions of linked list operation]
Windows环境下安装MongoDB数据库
Open3D 点云包围盒
关于Unity一般的输入操作方式
软件开发完整流程
ArrayList analysis 1-cycle, capacity expansion, version
酒旅板块复苏,亚朵继续上市梦,距离“新住宿经济第一股“还有多远?
pytorch编程知识(2)
Usage of C set
JS to convert numbers into Chinese characters for output
JS方法大全的一个小文档
2021电赛F题openmv和K210调用openmv api巡线,完全开源。
Training discipline principle of robot programming
Two-stage RO: part 1
[go] go implements row column conversion of sets
系统设置大页
Install redis database and download redis Desktop Manager in win11
Document service design