cityscape分割3类别数据处理
cpp:
#include "cv.h"
#include "highgui.h"
#include <iostream>
#include <fstream>
#include <string.h> using namespace std;
using namespace cv; int main()
{
ifstream infile;
infile.open("/media/hdc/xing/DeepLabV2/dataset/cityspace/gtFine/gtFine_color.txt");
string tmp;
while(getline(infile,tmp)){ string name = tmp.substr();
// cout << name << endl;
string gt_dir = "/media/hdc/xing/DeepLabV2/dataset/cityspace/gtFine/" + name;
string dis_dir = "/home/bnrc/cityscape_123label/" + name;
// cout << gt_dir << endl;
// cout << dis_dir << endl; Mat img;
img = imread(gt_dir);
int col = img.cols;
int row = img.rows;
// cout << col << endl;
// cout << row << endl;
//Mat result(1024, 2048, CV_8UC1, Scalar(255));
Mat result(, , CV_8UC1, Scalar());
for(int i = ;i < col;i++){
int index = ;
int blue = img.at<Vec3b>(index-,i)[];
int green = img.at<Vec3b>(index-,i)[];
int red = img.at<Vec3b>(index-,i)[];
while(index && (blue != || green != || red != )){
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
while(index && blue == && green == && red == ){
// result.at<uchar>(index-1,i) = 0;
result.at<uchar>(index-,i) = ;
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
int blue1 = blue;
int green1 = green;
int red1 = red;
while(index && blue == blue1 && green == green1 && red == red1){
// result.at<uchar>(index-1,i) = 150;
result.at<uchar>(index-,i) = ;
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
while(index && (blue != || green != || red != )){
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
while(index && blue == && green == && red == ){
// result.at<uchar>(index-1,i) = 0;
result.at<uchar>(index-,i) = ;
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
int blue2 = blue;
int green2 = green;
int red2 = red;
while(index && blue == blue2 && green == green2 && red == red2){
// result.at<uchar>(index-1,i) = 150;
result.at<uchar>(index-,i) = ;
index--;
blue = img.at<Vec3b>(index-,i)[];
green = img.at<Vec3b>(index-,i)[];
red = img.at<Vec3b>(index-,i)[];
}
}
// delete car flag
for(int i = ;i < col;i++){
for(int j = ;j < row;j++){
int blue = img.at<Vec3b>(j,i)[];
int green = img.at<Vec3b>(j,i)[];
int red = img.at<Vec3b>(j,i)[];
// cout << blue << " " << green << " " << red << ":" << i << " " << j << endl;
if(blue == && green == && red == ){
// result.at<uchar>(j,i) = 255;
result.at<uchar>(j,i) = ;
}
}
}
imwrite(dis_dir,result);
} //method 2 /*string gt_dir = "/media/hdc/xing/DeepLabV2/dataset/cityspace/gtFine/aachen/aachen_000001_000019_gtFine_color.png";
// size_t pos = tmp.find("/");
// string str = tmp.substr(0,pos);
// cout << str << endl;
string dis_dir = "/home/bnrc/aachen_000007_000019_gtFine_color.png";
// cout << gt_dir << endl;
// cout << dis_dir << endl;
Mat img;
img = imread(gt_dir);
int col = img.cols;
int row = img.rows;
// cout << col << endl;
// cout << row << endl;
Mat result(1024, 2048, CV_8UC1, Scalar(255));
for(int i = 0;i < col;i++){
int index = 1024;
int blue = img.at<Vec3b>(index-1,i)[0];
int green = img.at<Vec3b>(index-1,i)[1];
int red = img.at<Vec3b>(index-1,i)[2];
while(index && (blue != 128 || green != 64 || red != 128 )){
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
while(index && blue == 128 && green == 64 && red == 128){
result.at<uchar>(index-1,i) = 0;
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
int blue1 = blue;
int green1 = green;
int red1 = red;
while(index && blue == blue1 && green == green1 && red == red1){
result.at<uchar>(index-1,i) = 150;
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
while(index && (blue != 128 || green != 64 || red != 128 )){
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
while(index && blue == 128 && green == 64 && red == 128){
result.at<uchar>(index-1,i) = 0;
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
int blue2 = blue;
int green2 = green;
int red2 = red;
while(index && blue == blue2 && green == green2 && red == red2){
result.at<uchar>(index-1,i) = 150;
index--;
blue = img.at<Vec3b>(index-1,i)[0];
green = img.at<Vec3b>(index-1,i)[1];
red = img.at<Vec3b>(index-1,i)[2];
}
}
imwrite(dis_dir,result);
*/ //method 1 /*ifstream infile;
string gt_dir = "/media/hdc/xing/DeepLabV2/dataset/cityspace/gtFine/aachen/aachen_000007_000019_gtFine_labelIds.png";
string dis_dir = "/home/bnrc/aachen_000001_000019_gtFine_labelIds.png";
Mat img;
img = imread(gt_dir);
int col = img.cols;
int row = img.rows;
cout << col << endl;
cout << row << endl;
Mat result(1024, 2048, CV_8UC1, Scalar(255));
for(int i = 0;i < col;i++){
int index = 1024;
int label = img.at<uchar>(index-1,i);
// cout << label << endl;
while(index && label != 7){
index--;
label = img.at<uchar>(index-1,i);
// cout << label << endl;
}
// cout << label << endl;
while(index && label == 7){
result.at<uchar>(index-1,i) = 0;
index--;
label = img.at<uchar>(index-1,i);
// cout << index << ' ' <<label << endl;
}
// int value = label;
// while(index && label == value){
// result.at<uchar>(index-1,i) = 150;
// index--;
// label = img.at<uchar>(index-1,i);
// // cout << label << endl;
// }
}
imwrite(dis_dir,result);*/
return ;
}
python:
import cv2
import numpy as np with open('/media/hdc/xing/data_semantics/training/semantic_rgb/a.txt','r') as file:
# num = 0
for line in file:
# if num == 1:
# break
# num += 1
gt_image = '/media/hdc/xing/data_semantics/training/semantic_rgb/' + line.strip().split('./')[1]
# print gt_image
save_dir = '/media/hdc/xing/data_semantics/training/label012/' + line.strip().split('./')[1]
img_gt = cv2.imread(gt_image)
# print type(img_gt)
height = img_gt.shape[0]
width = img_gt.shape[1]
# print width,height
result = np.zeros((height,width))
for i in range(width):
index = height-1
red,green,blue = img_gt[index,i]
# print i,red,green,blue
while index >= 1 and (red != 128 or green != 64 or blue != 128):
index -= 1
red,green,blue = img_gt[index,i]
while index >= 1 and red == 128 and green == 64 and blue == 128:
index -= 1
result[index][i] = 1
# result[index][i] = 255
red,green,blue = img_gt[index,i]
while (index >= 1 and red == 232 and green == 35 and blue == 244) or (index >= 1 and red == 152 and green == 251 and blue == 152) or (index >= 1 and red == 160 and green == 170 and blue == 250) or (index >= 1 and red == 81 and green == 0 and blue == 81):
index -= 1
red,green,blue = img_gt[index,i]
while index >= 1 and red == 128 and green == 64 and blue == 128:
index -= 1
result[index][i] = 1
# result[index][i] = 255
red,green,blue = img_gt[index,i]
blue1 = blue
green1 = green
red1 = red
# print blue1,green1,red1
while index >= 1 and blue == blue1 and green == green1 and red == red1:
result[index][i] = 2
# result[index][i] = 150
index -= 1
red,green,blue = img_gt[index,i]
while index >= 1 and red == 128 and green == 64 and blue == 128:
index -= 1
result[index][i] = 1
# result[index][i] = 255
red,green,blue = img_gt[index,i]
while index >= 1 and blue == blue1 and green == green1 and red == red1:
result[index][i] = 2
# result[index][i] = 150
index -= 1
red,green,blue = img_gt[index,i]
# while index >= 1 and (red != 128 or green != 64 or blue != 128):
# index -= 1
# red,green,blue = img_gt[index,i]
# while index >= 1 and red == 128 and green == 64 and blue == 128:
# index -= 1
# # result[index][i] = 1
# result[index][i] = 255
# red,green,blue = img_gt[index,i]
# while index >= 1 and red == 250 and green == 170 and blue == 160:
# index -= 1
# red,green,blue = img_gt[index,i]
# while index >= 1 and red == 244 and green == 35 and blue == 232:
# index -= 1
# red,green,blue = img_gt[index,i]
# while index >= 1 and red == 152 and green == 251 and blue == 152:
# index -= 1
# red,green,blue = img_gt[index,i]
# blue2 = blue
# green2 = green
# red2 = red
# while index >= 1 and blue == blue2 and green == green2 and red == red2:
# index -= 1
# # result[index][i] = 2
# result[index][i] = 150
# red,green,blue = img_gt[index,i]
# print index
for i in range(width):
for j in range(height):
red,green,blue = img_gt[j,i]
if blue == 0 and green == 0 and red == 0:
result[j][i] = 0
cv2.imwrite(save_dir,result)
print save_dir
cityscape分割3类别数据处理的更多相关文章
- 笔记:基于DCNN的图像语义分割综述
写在前面:一篇魏云超博士的综述论文,完整题目为<基于DCNN的图像语义分割综述>,在这里选择性摘抄和理解,以加深自己印象,同时达到对近年来图像语义分割历史学习和了解的目的,博古才能通今!感 ...
- Google的分布式计算模型Map Reduce map函数将输入分割成key/value对
http://www.nowamagic.net/librarys/veda/detail/1768 上一篇 大规模分布式数据处理平台Hadoop的介绍 中提到了Google的分布式计算模型Map R ...
- [论文][半监督语义分割]Adversarial Learning for Semi-Supervised Semantic Segmentation
Adversarial Learning for Semi-Supervised Semantic Segmentation 论文原文 摘要 创新点:我们提出了一种使用对抗网络进行半监督语义分割的方法 ...
- Atitit 研发体系建立 数据存储与数据知识点体系知识图谱attilax 总结
Atitit 研发体系建立 数据存储与数据知识点体系知识图谱attilax 总结 分类具体知识点原理规范具体实现(oracle,mysql,mssql是否可以自己实现说明 数据库理论数据库的类型 数据 ...
- 查看 table,view,sp的定义
1, 查看用户创建的Proc,View, UDF,trigger 的定义 sys.sql_modules Returns a row for each object that is an SQL la ...
- R语法学习 第十二篇:因子
因子(factor)是R语言中比较特殊的一个类型, 它是一个用于存储类别的类型,因子的行为有时像字符串,有时像整数.因子也是一个向量,每个元素都是字符类型.因子具有因子水平(Levels),用于限制因 ...
- 论文笔记:Mask R-CNN
之前在一次组会上,师弟诉苦说他用 UNet 处理一个病灶分割的任务,但效果极差,我看了他的数据后发现,那些病灶区域比起整张图而言非常的小,而 UNet 采用的损失函数通常是逐像素的分类损失,如此一来, ...
- 从Learning to Segment Every Thing说起
原文地址:https://arxiv.org/pdf/1711.10370.pdf 这是何恺明老师发表于CVPR2018的一篇优秀paper. 先简单回顾一下语义分割领域之前的工作 那么什么是语义分割 ...
- 数据分析-kaggle泰坦尼克号生存率分析
概述 1912年4月15日,泰坦尼克号在首次航行期间撞上冰山后沉没,2224名乘客和机组人员中有1502人遇难.沉船导致大量伤亡的原因之一是没有足够的救生艇给乘客和船员.虽然幸存下来有一些运气因素,但 ...
随机推荐
- Git命令行中文显示错误
中文文件名乱码(git status.git log.git pull .git push) #不对0x80以上的字符进行quote,解决git status/commit时中文文件名乱码git co ...
- python文件引用其他文件中的变量
问题: 然后再另一个文件中引用该变量 报错:Cannot find reference 'User_Agent' in '__init__.py' less... (Ctrl+F1) 正确写法: fr ...
- c++中赋值运算符重载为什么要用引用做返回值?
class string{ public: string(const char *str=NULL); string(const string& str); //copy构造函数的参数 ...
- python xml dom
http://www.cnblogs.com/coser/archive/2012/01/10/2318298.html
- 自定义Qt组件-通讯模块(P2)
1. 抽象协议AbstractProtocol 抽象协议AbstractProtocol定义CommManager与协议之间的接口.AbstractProtocol中的一些属性(如enabled)用 ...
- 前端如何做好SEO优化
https://www.cnblogs.com/weiyf/p/9511021.html 一:什么是SEO? 搜索引擎优化(Search Engine Optimization),简称SEO.是按照搜 ...
- .NET Core 部署到CentOS–3.supervisord守护进
1. 安装 sudo yum install python-setuptoolssudo easy_install supervisor 2. 配置 安装成功后,输入supervisord 会显示配置 ...
- Mysql慢查询 [第一篇]
一.简介 开启慢查询日志,可以让MySQL记录下查询超过指定时间的语句,通过定位分析性能的瓶颈,才能更好的优化数据库系统的性能. 二.参数说明 slow_query_log 慢查询开启状态slow_q ...
- Lync二次开发关于Lync启动退出问题
以前使用C++开发的version.dll文件,由于各个用户环境的不同,造成某些用户加载不了我们开发的插件,并且写version.dll的同事还没找到好的解决办法,所以得换一种思路去解决这个问题,就是 ...
- C++基础--sizeof和strlen的区别
首先,来运行一段程序: #include "stdafx.h" #include <stdio.h> #include <string.h> int mai ...