Xmipp  v3.23.11-Nereus
coordinates_noisy_zones_filter.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Maluenda (dmaluenda@cnb.csic.es)
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 
27 
29 {
30  // Parameters
31  addParamsLine(" --pos <coordinates> : Input coordinates");
32  addParamsLine(" --mic <micrograph> : Reference volume");
33  addParamsLine(" [--patchSize <n=50>] : Patch size for the variance filter");
34  addParamsLine(" [-o <coordinates>] : Output coordinates (if not passed, "
35  "the input is overwritten)");
36 }
37 
39 {
40  fnInCoord = getParam("--pos");
41  fnInMic = getParam("--mic");
42  if (checkParam("-o"))
43  fnOut = getParam("-o");
44  else
45  fnOut = fnInCoord;
46  patchSize = getIntParam("--patchSize");
47 }
48 
50 {
51  if (verbose)
52  std::cout
53  << "Input Coordinates: " << fnInCoord << std::endl
54  << "Input Micrograph: " << fnInMic << std::endl
55  << "Output coordinates: " << fnOut << std::endl
56  << "Patch size: " << patchSize << std::endl
57  ;
58 }
59 
60 //#define DEBUG
62 {
63  show();
64 
65  Micrograph mic;
67  mic.read_coordinates(0, (String)"particles@"+fnInCoord);
68  mic.add_label("");
69 
70  Image<double> im;
71  im.read(fnInMic);
72 
73  // std::cout << " - Starting normalization " << std::endl;
74  MultidimArray<double> &matrixMic = im();
75  matrixMic.selfNormalizeInterval();
76 
77  if (verbose>1)
78  {
79  Image<double> aux(matrixMic);
80  aux.write(fnInCoord.withoutExtension()+"_normalized.mrc");
81  }
82 
83  // giniCoeff(Image, patchSize) returns the giniCoeff of the Image and
84  // applies a variance filter to the Image with a patchSize
85  double giniV = giniCoeff(matrixMic, patchSize);
86 
87  if (verbose>1)
88  {
89  Image<double> aux(matrixMic);
90  aux.write(fnInCoord.withoutExtension()+"_varianceFilter.mrc");
91  std::cout << " Gini Coeff: " << giniV << std::endl
92  << "(" << fnInMic << ")" << std::endl;
93  }
94 
95  // adding the variance value of the zone to every coordinate
96  std::vector<Particle_coords> &allCoords=mic.coords;
97  std::vector<double> varValue;
98  for (size_t i=0; i<allCoords.size(); ++i)
99  {
100  Particle_coords &coord=allCoords[i];
101  varValue.push_back(DIRECT_A2D_ELEM(matrixMic,coord.Y,coord.X));
102  }
103 
104  // creating a MetaData with the coordinates and the Scores VAR and GINI
105  MetaDataVec MD;
106  int imax = allCoords.size();
107  size_t id;
108  for (int i = 0; i < imax; i++)
109  if (allCoords[i].valid && allCoords[i].cost > 0
110  && allCoords[i].label == 0)
111  {
112  id = MD.addObject();
113  MD.setValue(MDL_XCOOR, allCoords[i].X, id);
114  MD.setValue(MDL_YCOOR, allCoords[i].Y, id);
115  MD.setValue(MDL_SCORE_BY_VAR, varValue[i], id);
116  MD.setValue(MDL_SCORE_BY_GINI, giniV, id);
117  }
118  MD.write((String)"particles@"+fnOut);
119 }
120 #undef DEBUG
int Y
Y position.
Definition: micrograph.h:62
double giniCoeff(MultidimArray< double > &I, int varKernelSize)
Definition: filters.cpp:972
void read_coordinates(int label, const FileName &fn_coords)
Definition: micrograph.cpp:216
#define DIRECT_A2D_ELEM(v, i, j)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
std::vector< Particle_coords > coords
Definition: micrograph.h:118
int X
X position.
Definition: micrograph.h:60
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
int add_label(const std::string &label)
Definition: micrograph.h:501
size_t size() const override
#define i
void open_micrograph(const FileName &fn_micrograph)
Definition: micrograph.cpp:61
const char * getParam(const char *param, int arg=0)
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
< Particle variance (double)
X component (int)
int verbose
Verbosity level.
FileName withoutExtension() const
std::string String
Definition: xmipp_strings.h:34
void selfNormalizeInterval(double minPerc=0.25, double maxPerc=0.75, int Npix=1000)
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Y component (int)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)