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. java——为什么要有接口?和抽象类有什么不一样?

    1.接口不是类,为什么? 接口如果是类,那就失去了java引入接口的意义了. java之所以引入接口,就是为了弥补不能多继承的缺点,在java中每个类只能有一个超类,但却可以实现多个接口. 2.接口可 ...

  2. 转 使用隐含Trace参数诊断Oracle Data Pump故障

    http://blog.itpub.net/17203031/viewspace-772718/ Data Pump数据泵是Oracle从10g开始推出的,用于取代传统exp/imp工具的数据备份还原 ...

  3. RobotFramework AppiumLibrary 用户关键字

    RobotFramework AppiumLibrary 用户关键字 最近在用robotframework搞安卓app 的自动化,其中用到了 AppiumLlibrary 的关键字,我都映射成了用户关 ...

  4. Eclipse代码规范工具-Checkstyle安装和使用

    您首先可以参考这里:http://www.ibm.com/developerworks/cn/java/j-ap01117/index.html 那么首先您应该下载CheStyle: http://s ...

  5. JAVA生成word的几种方法对比

    首先介绍几种java导出word方案 1.Jacob是Java-COM Bridge的缩写,它在Java与微软的COM组件之间构建一座桥梁.使用Jacob自带的DLL动态链接库,并通过JNI的方式实现 ...

  6. Selenium2(WebDriver)中执行JavaScript代码 (转)

    在用selenium编写web页面的自动化测试代码时,可能需要执行一些JavaScript代码,selenium本身就支持执行js,我们在代码中可以使用executeScript.executeAsy ...

  7. JavaScript DOM基础总结

    上个月在进行百度三面时候,面试官提问JavaScript DOM方法,我回答的有点少,前面太关注JavaScript 兼容性,框架方面,JavaScript 原生DOM基础没有记牢,心中有点遗憾.下来 ...

  8. Mvc内建功能(DefaultModelBinder)自动绑定。

    在做Asp.Net MVC项目中,都知道View负责页面展示数据或者提供页面收集数据,而所展示的数据或者收集的数据都是从Controller的Action中获取或提交到Controller的Actio ...

  9. 使用Zxing生成一维码和二维码

    首先引用zxing.dll 到项目中引用 using System; using System.Collections.Generic; using System.Drawing; using Sys ...

  10. postMessage解决跨域跨窗口消息传递

    平时做web开发的时候关于消息传递,除了客户端与服务器传值还有几个经常会遇到的问题 页面和其打开的新窗口的数据传递 页面与嵌套的iframe消息传递 这些问题都有一些解决办法,但html5引入的mes ...