opencv彩色图像可视化实例

来源:互联网 发布:数据库的安全防护措施 编辑:程序博客网 时间:2024/04/29 03:48
输入:groundtruth 图像目录和程序分割结果目录

输出:差异图像,在每一幅图像中TP FP TN FN像素分别用4种颜色表示。

// // valueTest.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <fstream>#include <cmath>#include "opencv2/core.hpp"#include <string>#include <string.h>#include "opencv2/opencv.hpp"#include <vector>#include "opencv2/imgproc.hpp"#include "opencv2/imgproc/types_c.h"#include <io.h>using namespace std;using namespace cv;bool get_filelist_from_dir(string path, vector<string>& files){long hFile = 0;struct _finddata_t fileinfo;files.clear();if ((hFile = _findfirst(path.c_str(), &fileinfo)) != -1){do{if (!(fileinfo.attrib&_A_SUBDIR))files.push_back(fileinfo.name);} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);return true;}elsereturn false;}int main(){string in = "stares";string file1 = "../../视网膜血管分割0725/" + in + "/分割最终结果/";string ground_path = "../../视网膜血管分割0725/" + in + "/stare-groudtruth1/";string showcolor = "../../视网膜血管分割0725/" + in + "/color/";string search_path = file1 + "*.tif";string search_path_groundtruth = ground_path + "*.ppm";vector<string> file_list;vector<string> file_list_g;double avgAcc = 0, avgSe = 0, avgSp = 0, avgF = 0;if (!get_filelist_from_dir(search_path, file_list))cout << "open file error!" << endl;if (!get_filelist_from_dir(search_path_groundtruth, file_list_g))cout << "open file error!" << endl;double start = double(getTickCount());for (int a = 0; a < file_list.size(); a++){string image_path = file1 + file_list[a];Mat image = imread(image_path, IMREAD_GRAYSCALE);string image_g = ground_path + file_list_g[a];Mat groundtruth = imread(image_g, IMREAD_GRAYSCALE);Mat tmpColor = imread(image_g, IMREAD_COLOR);//tmpColor.convertTo(tmpColor,CV_64FC1);string c;ostringstream oss;oss.str("");oss << a + 1;c = oss.str();//计算准确率,召回率和误判率double k1 = 0.0, k2 = 0.0, k3 = 0.0, k4 = 0.0;for (int m2 = 0; m2 < image.rows; m2++){for (int n2 = 0; n2 < image.cols; n2++){if (image.at<uchar>(m2, n2) == 255 && groundtruth.at<uchar>(m2, n2) == 0){k1 += 1.0;//fptmpColor.at<Vec3b>(m2, n2)[0] = 255;tmpColor.at<Vec3b>(m2, n2)[1] = 0;tmpColor.at<Vec3b>(m2, n2)[2] = 0;}if (image.at<uchar>(m2, n2) == 255 && groundtruth.at<uchar>(m2, n2) == 255){k2 += 1.0;//tptmpColor.at<Vec3b>(m2, n2)[0] = 0;tmpColor.at<Vec3b>(m2, n2)[1] = 255;tmpColor.at<Vec3b>(m2, n2)[2] = 0;}if (image.at<uchar>(m2, n2) == 0 && groundtruth.at<uchar>(m2, n2) == 255){k3 += 1.0;//fntmpColor.at<Vec3b>(m2, n2)[0] = 0;tmpColor.at<Vec3b>(m2, n2)[1] = 0;tmpColor.at<Vec3b>(m2, n2)[2] = 255;}if (image.at<uchar>(m2, n2) == 0 && groundtruth.at<uchar>(m2, n2) == 0){k4 += 1.0;//tntmpColor.at<Vec3b>(m2, n2)[0] = 128;tmpColor.at<Vec3b>(m2, n2)[1] = 128;tmpColor.at<Vec3b>(m2, n2)[2] = 128;}}}string tmpImg = showcolor + c + ".tif";    imwrite(tmpImg,tmpColor);}return 0;}


0 0
原创粉丝点击