Superpixel Benchmark
Superpixel benchmark, tools and algorithms.
evaluation_summary.h
Go to the documentation of this file.
1 
32 #ifndef EVALUATION_SUMMARY_H
33 #define EVALUATION_SUMMARY_H
34 
35 #include <vector>
36 #include <boost/filesystem.hpp>
37 #include <opencv2/opencv.hpp>
38 
45 public:
46 
51  mean(false), pre_rec(false), ue(false) {};
52 
54  bool contour;
56  bool random;
60  bool mean;
62  bool pre_rec;
64  bool ue;
65 
69  bool any() {
70  return contour || random || perturbed_mean || mean || pre_rec || ue;
71  }
72  };
73 
77  EvaluationMetrics() : ue(true), oe(true), rec(true), pre(true),
78  ue_np(true), ue_levin(true), asa(true), sse_rgb(true), sse_xy(true),
79  co(true), ev(true), mde(true), icv(true), cd(true),
80  reg(true), sp(true), sp_size(true) {};
81 
83  bool ue;
85  bool oe;
87  bool rec;
89  bool pre;
91  bool ue_np;
93  bool ue_levin;
95  bool asa;
97  bool sse_rgb;
99  bool sse_xy;
101  bool co;
103  bool ev;
105  bool mde;
107  bool icv;
109  bool cd;
111  bool reg;
113  bool sp;
115  bool sp_size;
116  };
117 
121 
122  EvaluationStatistics() : mean(true), median_and_quartiles(true),
123  min_and_max(true), mid_range(true), std(true) {};
124 
126  bool mean;
132  bool mid_range;
134  bool std;
135  };
136 
150  EvaluationSummary(boost::filesystem::path sp_directory,
151  boost::filesystem::path gt_directory, boost::filesystem::path img_directory);
152 
161  EvaluationSummary(boost::filesystem::path sp_directory,
162  boost::filesystem::path gt_directory, boost::filesystem::path img_directory,
164 
174  EvaluationSummary(boost::filesystem::path sp_directory,
175  boost::filesystem::path gt_directory, boost::filesystem::path img_directory,
178 
182  void computeSummary(int &gt_max);
183 
187  void setAppendFile(const boost::filesystem::path &append_file);
188 
193 
198 
203 
208 
213 
218 
223 
227  bool getComputeCorrelation();
228 
229 protected:
230 
234  int countMetrics();
235 
240  void evaluateHeader(std::stringstream &output, std::vector<std::string> &metric_order);
241 
249  void evaluate(const cv::Mat &sp_segmentation, const cv::Mat &gt_segmentation,
250  const cv::Mat &image, cv::Mat &data, std::stringstream &output);
251 
259  void visualize(const cv::Mat &sp_segmentation, const cv::Mat &gt_segmentation,
260  const cv::Mat &image, std::string name, int t = 0);
261 
268  void correlate(const cv::Mat &mat_results, const std::vector<std::string> &metric_order,
269  cv::Mat &mat_correlation, std::string &csv_correlation);
270 
275  int countStatistics(int gt_max);
276 
279  void validateStatistics();
280 
284  void summaryHeader(const std::vector<int> &gt, std::stringstream &output);
285 
294  void summarize(const std::vector<int> &gt, const cv::Mat &data,
295  int j, cv::Mat &mat_summary, std::stringstream &output);
296 
305  float computeMean(const std::vector<int> gt, const cv::Mat &data, int j,
306  std::vector<float> &mean, float &mean_min, float &mean_max);
307 
316  float comuteMedian(const std::vector<int> gt, const cv::Mat &data, int j,
317  std::vector<float> &median, float &median_min, float &median_max);
318 
333  void comuteMedianFirstAndThirdQuartile(const std::vector<int> gt, const cv::Mat &data, int j,
334  std::vector<float> &median, std::vector<float> &first_q, std::vector<float> &thrid_q,
335  float &median_min, float &first_q_min, float &third_q_min, float &median_max,
336  float &first_q_max, float &second_q_max);
337 
349  void comuteMinMax(const std::vector<int> gt, const cv::Mat &data, int j,
350  std::vector<float> &min, std::vector<float> &max, float &min_min,
351  float &max_min, float &min_max, float&max_max);
352 
362  float computeStandardDeviation(const std::vector<int> gt, const cv::Mat &data, int j,
363  const std::vector<float> &mean, std::vector<float> &std, float &std_min,
364  float &std_max);
365 
372 
375 
377  boost::filesystem::path sp_directory;
379  boost::filesystem::path gt_directory;
381  boost::filesystem::path img_directory;
383  boost::filesystem::path results_file;
385  boost::filesystem::path correlation_file;
387  boost::filesystem::path summary_file;
389  boost::filesystem::path vis_directory;
391  boost::filesystem::path append_file;
392 };
393 
394 #endif /* EVALUATION_SUMMARY_H */
395 
bool sp
Whether to compute the number of superpixels.
Definition: evaluation_summary.h:113
bool oe
Whether to use Oversegmentation Error.
Definition: evaluation_summary.h:85
void summarize(const std::vector< int > &gt, const cv::Mat &data, int j, cv::Mat &mat_summary, std::stringstream &output)
Summarize a specific column of the evaluation data (corresponding to a particular metric)...
Definition: evaluation_summary.cpp:635
bool sp_size
Whether to compute superpixel size.
Definition: evaluation_summary.h:115
bool pre_rec
Whether to visualize false positives and negatives in the Recall/Precision sense. ...
Definition: evaluation_summary.h:62
Available superpixel visualizations, see visualization.h.
Definition: evaluation_summary.h:49
bool ev
Whether to use Explained Variation.
Definition: evaluation_summary.h:103
bool sse_xy
Whether to use the sum-of-squared error on xy coordinates.
Definition: evaluation_summary.h:99
bool mid_range
Whether to compute the mid range.
Definition: evaluation_summary.h:132
boost::filesystem::path summary_file
Path to summary file.
Definition: evaluation_summary.h:387
void getSuperpixelVisualizations(EvaluationSummary::SuperpixelVisualizations &superpixel_visualizations)
Get the visualizations used.
Definition: evaluation_summary.cpp:1380
void getEvaluationStatistics(EvaluationSummary::EvaluationStatistics &evaluation_statistics)
Get the evaluation statistics used.
Definition: evaluation_summary.cpp:1364
EvaluationMetrics evaluation_metrics
Evaluation metrics to use.
Definition: evaluation_summary.h:367
bool pre
Whether to use Boundary Precision.
Definition: evaluation_summary.h:89
SuperpixelVisualizations()
Definition: evaluation_summary.h:50
bool std
Whether to compute the standard deviation.
Definition: evaluation_summary.h:134
void computeSummary(int &gt_max)
Summarize the results; this is the main entrance point.
Definition: evaluation_summary.cpp:1137
Available metrics, see evaluation.h.
Definition: evaluation_summary.h:76
void setAppendFile(const boost::filesystem::path &append_file)
Add CSV file to append CSV output to.
Definition: evaluation_summary.cpp:1332
boost::filesystem::path correlation_file
Path to correlation file.
Definition: evaluation_summary.h:385
bool rec
WHether to use Boundary Recal.
Definition: evaluation_summary.h:87
void setEvaluationStatistics(const EvaluationStatistics &evaluation_statistics)
Set the evaluation statistics to compute.
Definition: evaluation_summary.cpp:1340
bool mde
Whether to use Mean Distance to Edge.
Definition: evaluation_summary.h:105
void setEvaluationMetrics(const EvaluationMetrics &evaluation_metrics)
Set the evaluation metrics to compute.
Definition: evaluation_summary.cpp:1348
Available statistics that may be computed for each metric.
Definition: evaluation_summary.h:120
void evaluateHeader(std::stringstream &output, std::vector< std::string > &metric_order)
Add header to output.
Definition: evaluation_summary.cpp:165
bool icv
Whether to use Intra-Cluster Variation.
Definition: evaluation_summary.h:107
boost::filesystem::path gt_directory
Directory of ground truth segmentations.
Definition: evaluation_summary.h:379
float computeMean(const std::vector< int > gt, const cv::Mat &data, int j, std::vector< float > &mean, float &mean_min, float &mean_max)
Compute mean statistic.
Definition: evaluation_summary.cpp:809
bool mean
Whether to visualize superpixels using mean color.
Definition: evaluation_summary.h:60
bool sse_rgb
Whether to use the sum-of-squared error on RGB color.
Definition: evaluation_summary.h:97
void evaluate(const cv::Mat &sp_segmentation, const cv::Mat &gt_segmentation, const cv::Mat &image, cv::Mat &data, std::stringstream &output)
Actually do the evaluation.
Definition: evaluation_summary.cpp:247
bool cd
Whether to use Contour Density.
Definition: evaluation_summary.h:109
bool any()
Decide if any visualization is requested.
Definition: evaluation_summary.h:69
void setComputeCorrelation(bool compute_correlation)
Set whether to compute correlation.
Definition: evaluation_summary.cpp:1388
bool getComputeCorrelation()
Get whether correlation is computed.
Definition: evaluation_summary.cpp:1396
boost::filesystem::path sp_directory
Directory of superpixel segmentations.
Definition: evaluation_summary.h:377
void visualize(const cv::Mat &sp_segmentation, const cv::Mat &gt_segmentation, const cv::Mat &image, std::string name, int t=0)
Visualize given segmentation.
Definition: evaluation_summary.cpp:429
void summaryHeader(const std::vector< int > &gt, std::stringstream &output)
Add the summary header to output.
Definition: evaluation_summary.cpp:578
void comuteMedianFirstAndThirdQuartile(const std::vector< int > gt, const cv::Mat &data, int j, std::vector< float > &median, std::vector< float > &first_q, std::vector< float > &thrid_q, float &median_min, float &first_q_min, float &third_q_min, float &median_max, float &first_q_max, float &second_q_max)
Compute median, first quartile and third quartile.
Definition: evaluation_summary.cpp:892
bool ue_levin
Whether to use Levinshtein&#39;s definition of the Undersegmentation Error.
Definition: evaluation_summary.h:93
bool reg
Whether to use Regularity.
Definition: evaluation_summary.h:111
float comuteMedian(const std::vector< int > gt, const cv::Mat &data, int j, std::vector< float > &median, float &median_min, float &median_max)
Compute median statistic.
void validateStatistics()
Validate and correct statistics.
Definition: evaluation_summary.cpp:565
boost::filesystem::path results_file
Path to results file.
Definition: evaluation_summary.h:383
bool min_and_max
Compute minimum and maximum over all images.
Definition: evaluation_summary.h:130
bool ue
Whether to use Undersegmentation Error.
Definition: evaluation_summary.h:80
bool ue
Whether to color the undersegmentation error.
Definition: evaluation_summary.h:64
SuperpixelVisualizations superpixel_visualizations
Visualizations to compute.
Definition: evaluation_summary.h:371
boost::filesystem::path img_directory
Directory of images.
Definition: evaluation_summary.h:381
bool co
Whether to use Compactness.
Definition: evaluation_summary.h:101
void comuteMinMax(const std::vector< int > gt, const cv::Mat &data, int j, std::vector< float > &min, std::vector< float > &max, float &min_min, float &max_min, float &min_max, float &max_max)
Compute min/max over all ground truth segmentations.
Definition: evaluation_summary.cpp:984
bool contour
Whether to visualize contours.
Definition: evaluation_summary.h:51
bool median_and_quartiles
Compute median, first and third quantile over all images.
Definition: evaluation_summary.h:128
EvaluationMetrics()
Definition: evaluation_summary.h:77
bool random
Whether to visualize superpixels as randomly colored.
Definition: evaluation_summary.h:56
EvaluationSummary(boost::filesystem::path sp_directory, boost::filesystem::path gt_directory, boost::filesystem::path img_directory)
Create an evaluation summary for the given directory.
Definition: evaluation_summary.cpp:45
bool asa
Whether to use Achievable Segmentation Accuracy.
Definition: evaluation_summary.h:95
bool ue_np
Whether to use Neubert and Protzel&#39;s definition of the Undersegmentation Error.
Definition: evaluation_summary.h:91
void getEvaluationMetrics(EvaluationSummary::EvaluationMetrics &evaluation_metrics)
Get the evaluation metrics used.
Definition: evaluation_summary.cpp:1372
boost::filesystem::path append_file
Path to file to append summary to.
Definition: evaluation_summary.h:391
float computeStandardDeviation(const std::vector< int > gt, const cv::Mat &data, int j, const std::vector< float > &mean, std::vector< float > &std, float &std_min, float &std_max)
Compute standard deviation over all ground truth segmentations.
Definition: evaluation_summary.cpp:1051
bool perturbed_mean
Whether to visualize superpixels using a slightly perturbed mean color.
Definition: evaluation_summary.h:58
boost::filesystem::path vis_directory
Path to visualization directory.
Definition: evaluation_summary.h:389
int countStatistics(int gt_max)
Count the number of statistics to be used.
Definition: evaluation_summary.cpp:541
bool mean
Compute the mean over all images.
Definition: evaluation_summary.h:123
EvaluationStatistics evaluation_statistics
Evaluation statistics to use.
Definition: evaluation_summary.h:369
Given a directory of superpixel segmentations and a directory of ground truth segmentations, this class is used to generate a CSV file of statistics of different metrics.
Definition: evaluation_summary.h:44
void setSuperpixelVisualizations(const SuperpixelVisualizations &superpixel_visualizations)
Set the superpixel visualizations to compute.
Definition: evaluation_summary.cpp:1356
EvaluationStatistics()
Definition: evaluation_summary.h:122
void correlate(const cv::Mat &mat_results, const std::vector< std::string > &metric_order, cv::Mat &mat_correlation, std::string &csv_correlation)
Compute correlation between all metrics.
Definition: evaluation_summary.cpp:478
int countMetrics()
Count number of metrics used.
Definition: evaluation_summary.cpp:102
bool compute_correlation
Whether to compute correlation.
Definition: evaluation_summary.h:374