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人遇难.沉船导致大量伤亡的原因之一是没有足够的救生艇给乘客和船员.虽然幸存下来有一些运气因素,但 ...
随机推荐
- C#中Internal关键字的总结
https://blog.csdn.net/baidu_32134295/article/details/51285603 版权声明:本文为博主原创文章,未经博主允许不得转载. https:/ ...
- 使用xUnit为.net core程序进行单元测试
第1部分: http://www.cnblogs.com/cgzl/p/8283610.html 第2部分: http://www.cnblogs.com/cgzl/p/8287588.html ...
- gitlab 的安装、汉化、卸载
新机 dell服务器 2核4G 官网: https://about.gitlab.com/install/ 1.本次安装选择版本v10.8.4 wget https://mirrors.tuna.ts ...
- 数据结构---Java---数组
**************************************************************前言************************************ ...
- 使用summernote编辑器上传图片,重写onImageUpload
JS部分:$('.summernote').summernote({ height: 200,//高度 tabsize: 2,//页面上的summernote编辑框的个数 lang: 'zh-CN', ...
- maya2017安装失败如何卸载重装
AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...
- ubuntu安装软件依赖解决
sudo apt-get install -f zsh@zsh:~/Downloads/dist$ sudo dpkg --install Kitematic_0.17.3_amd64.deb (正在 ...
- Classes as objects
Before understanding metaclasses, you need to master classes in Python. And Python has a very peculi ...
- Hadoop2.X HA架构与部署
HDFS-HA原理及配置 1.HDFS-HA架构原理介绍 hadoop2.x之后,Clouera提出了QJM/Qurom Journal Manager,这是一个基于Paxos算法实现的HDFS HA ...
- typescript的lambads解决this关键字找不到属性
var people = { name: ["abc", "jack", "pepter", "jim"], getna ...