Xmipp  v3.23.11-Nereus
evaluate_coordinates.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Tomas Majtner tmajtner@cnb.csic.es (2017)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "evaluate_coordinates.h"
27 
28 // Read arguments ==========================================================
30 {
31  fnGt = getParam("-g");
32  fnEval = getParam("-e");
33  numMic = getIntParam("-n");
34  errMargin = getIntParam("-t");
35  rootName = getParam("--root");
36 }
37 
38 // Show ====================================================================
40 {
41  if (verbose==0)
42  return;
43  std::cerr
44  << "Ground truth coordinates: " << fnGt << std::endl
45  << "Coordinates to evaluate: " << fnEval << std::endl
46  << "Number of micrographs: " << numMic << std::endl
47  << "Tolerance of center misplacement: " << errMargin << std::endl
48  << "Root name: " << rootName << std::endl
49  ;
50 }
51 
52 // Usage ===================================================================
54 {
55  addUsageLine("Evaluates the set of coordinates against the ground truth");
56  addParamsLine(" -g <selfile> : Selfile containing ground truth coordinates");
57  addParamsLine(" -e <selfile> : Selfile containing coordinates to evaluate");
58  addParamsLine(" -n <int> : Number of micrographs");
59  addParamsLine(" [-t <int=10>] : Tolerance of center misplacement");
60  addParamsLine(" --root <rootName> : Root name of the micrographs");
61 }
62 
64 {
65  int evalXCoor, evalYCoor, gtXCoor, gtYCoor;
66  int truePosivites = 0, totalEval = 0, totalGT = 0;
67 
68  for (int m = 1; m <= numMic; m++)
69  {
70  // Here you need to change the identifiers based on datasets
71  // TODO: loading names and counts of mics automatically?
72  FileName micGT = formatString("%s_%04d@%s", rootName.c_str(), m, fnGt.c_str());
73  FileName micEval = formatString("%s_%04d@%s", rootName.c_str(), m, fnEval.c_str());
74 
75  GT.read(micGT);
76  Eval.read(micEval);
77 
78  int iterE = 1;
79  for (size_t objIdEval : Eval.ids())
80  {
81  MDRowVec row;
82  Eval.getRow(row, iterE);
83  row.getValue(MDL_XCOOR, evalXCoor);
84  row.getValue(MDL_YCOOR, evalYCoor);
85 
86  int iterG = 1;
87  for (size_t objIdGT : GT.ids())
88  {
89  GT.getRow(row, iterG);
90  row.getValue(MDL_XCOOR, gtXCoor);
91  row.getValue(MDL_YCOOR, gtYCoor);
92 
93  if ((evalXCoor > (gtXCoor-errMargin-1)) &&
94  (evalXCoor < (gtXCoor+errMargin+1)) &&
95  (evalYCoor > (gtYCoor-errMargin-1)) &&
96  (evalYCoor < (gtYCoor+errMargin+1)))
97  truePosivites++;
98 
99  iterG++;
100  }
101  iterE++;
102  }
103  totalEval += Eval.size();
104  totalGT += GT.size();
105  }
106 
107  std::cout << std::endl;
108  std::cout << "True positives (correctly picked particles): ";
109  std::cout << truePosivites << std::endl;
110  std::cout << "False positives (incorrectly picked particles): ";
111  std::cout << totalEval - truePosivites << std::endl;
112  std::cout << "False negatives (missed particles): ";
113  std::cout << totalGT - truePosivites << std::endl << std::endl;
114 
115  std::cout << "How many relevant particles are picked:" << std::endl;
116  std::cout << "True positive rate: ";
117  double truePositiveRate = (0 == totalGT) ? 0 : (double) truePosivites / totalGT;
118  std::cout << truePositiveRate << std::endl << std::endl;
119 
120  std::cout << "Ratio of wrongly picked particles and all picked particles:";
121  std::cout << std::endl;
122  std::cout << "False positive rate: ";
123  std::cout << (double) (totalEval - truePosivites) / totalEval;
124  std::cout << std::endl << std::endl;
125 }
void readParams()
Read argument.
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
virtual IdIteratorProxy< false > ids()
std::unique_ptr< MDRow > getRow(size_t id) override
size_t size() const override
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
X component (int)
int verbose
Verbosity level.
int m
void defineParams()
Define parameters.
String formatString(const char *format,...)
Y component (int)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)