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类别数据处理的更多相关文章

  1. 笔记:基于DCNN的图像语义分割综述

    写在前面:一篇魏云超博士的综述论文,完整题目为<基于DCNN的图像语义分割综述>,在这里选择性摘抄和理解,以加深自己印象,同时达到对近年来图像语义分割历史学习和了解的目的,博古才能通今!感 ...

  2. Google的分布式计算模型Map Reduce map函数将输入分割成key/value对

    http://www.nowamagic.net/librarys/veda/detail/1768 上一篇 大规模分布式数据处理平台Hadoop的介绍 中提到了Google的分布式计算模型Map R ...

  3. [论文][半监督语义分割]Adversarial Learning for Semi-Supervised Semantic Segmentation

    Adversarial Learning for Semi-Supervised Semantic Segmentation 论文原文 摘要 创新点:我们提出了一种使用对抗网络进行半监督语义分割的方法 ...

  4. Atitit 研发体系建立 数据存储与数据知识点体系知识图谱attilax 总结

    Atitit 研发体系建立 数据存储与数据知识点体系知识图谱attilax 总结 分类具体知识点原理规范具体实现(oracle,mysql,mssql是否可以自己实现说明 数据库理论数据库的类型 数据 ...

  5. 查看 table,view,sp的定义

    1, 查看用户创建的Proc,View, UDF,trigger 的定义 sys.sql_modules Returns a row for each object that is an SQL la ...

  6. R语法学习 第十二篇:因子

    因子(factor)是R语言中比较特殊的一个类型, 它是一个用于存储类别的类型,因子的行为有时像字符串,有时像整数.因子也是一个向量,每个元素都是字符类型.因子具有因子水平(Levels),用于限制因 ...

  7. 论文笔记:Mask R-CNN

    之前在一次组会上,师弟诉苦说他用 UNet 处理一个病灶分割的任务,但效果极差,我看了他的数据后发现,那些病灶区域比起整张图而言非常的小,而 UNet 采用的损失函数通常是逐像素的分类损失,如此一来, ...

  8. 从Learning to Segment Every Thing说起

    原文地址:https://arxiv.org/pdf/1711.10370.pdf 这是何恺明老师发表于CVPR2018的一篇优秀paper. 先简单回顾一下语义分割领域之前的工作 那么什么是语义分割 ...

  9. 数据分析-kaggle泰坦尼克号生存率分析

    概述 1912年4月15日,泰坦尼克号在首次航行期间撞上冰山后沉没,2224名乘客和机组人员中有1502人遇难.沉船导致大量伤亡的原因之一是没有足够的救生艇给乘客和船员.虽然幸存下来有一些运气因素,但 ...

随机推荐

  1. my17_Mysql 主从切换

    注意事项: 从库提升为主库read_only要设置为OFF原主库改为从库后,read_only要设置ONread_only=ON并不能对root生效,确保root不会进行数据写入从主库进行 flush ...

  2. 手工安装XDB 组件in oracle 11g

    #############. sample 1 install guide below step is only for oracle 11g database installation, 10g d ...

  3. MongoDB系列—— Window 搭建Mongodb 集群

    Mongodb的集群方式的搭建有三种:Replica Set / Sharding / Master-Slaver.这里只说明最简单的集群搭建方式(Replica Set) Replica Set M ...

  4. android 闹钟设置问题

    Android开发中,alarmManager在5.0以上系统,启动时间设置无效的问题 做一个app,需要后台保持发送心跳包.由于锁屏后CPU休眠,导致心跳包线程被挂起,所以尝试使用alarmMana ...

  5. qt安装

    在以下网页选择一个国内的下载地址即可 http://download.qt.io/official_releases/qt/5.7/5.7.0/qt-opensource-linux-x64-5.7. ...

  6. git分布式的理解----简单服务端搭建

    Git是分布式的,并没有服务端跟客户端之分,所谓的服务端安装的其实也是git.Git支持四种协议,file,ssh,git,http.ssh是使用较多的,下面使用ssh搭建一个免密码登录的服务端. 1 ...

  7. pat1025. PAT Ranking (25)

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  8. 关于docker remote api未授权访问漏洞的学习与研究

    漏洞介绍: 该未授权访问漏洞是因为docker remote api可以执行docker命令,从官方文档可以看出,该接口是目的是取代docker 命令界面,通过url操作docker. docker ...

  9. java.lang.ArrayIndexOutOfBoundsException: 160

    项目突然出现这个问题java.lang.ArrayIndexOutOfBoundsException: 160,找了好大半天没有找出来哪里的问题,最后发现时fastjson.jar 版本太低了造成的, ...

  10. mysql中count(*)和found_rows()的区别

    count(*)和found_rows()都可以用来求查询记录的数量 而count(*)往往单独使用,found_rows()却可以跟上前面一个查询,即select * from table limi ...