Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <compare_density.h>

Inheritance diagram for ProgCompareDensity:
Inheritance graph
[legend]
Collaboration diagram for ProgCompareDensity:
Collaboration graph
[legend]

Public Member Functions

void defineParams ()
 Define params. More...
 
void readParams ()
 Read arguments from command line. More...
 
void show ()
 Show. More...
 
void run ()
 Run. More...
 
void computeCorrImage (int i)
 Compute corr image. More...
 
void compare (Image< double > &op1, const Image< double > &op2)
 Compare binary images. More...
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fnVol1
 Volumes to compare. More...
 
FileName fnVol2
 
FileName fnImgOut
 Output corelation image. More...
 
double degstep
 Degree step. More...
 
Image< double > V1
 Images. More...
 
Image< double > V2
 
Image< double > CorrImg
 
std::vector< double > tilt_v
 Rot and tilt vectors. More...
 
std::vector< double > rot_v
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Sph Alignment Parameters.

Definition at line 38 of file compare_density.h.

Member Function Documentation

◆ compare()

void ProgCompareDensity::compare ( Image< double > &  op1,
const Image< double > &  op2 
)

Compare binary images.

Definition at line 140 of file compare_density.cpp.

141 {
142  MultidimArray<double> &mOp1 = op1();
143  const MultidimArray<double> &mOp2 = op2();
145  {
146  dAi(mOp1, n) = dAi(mOp1, n) == dAi(mOp2, n) ? 0 : (dAi(mOp1, n) < dAi(mOp2, n) ? -1 : 1 );
147  }
148 }
#define dAi(v, i)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
int * n

◆ computeCorrImage()

void ProgCompareDensity::computeCorrImage ( int  i)

Compute corr image.

Definition at line 97 of file compare_density.cpp.

98 {
99  Projection P1, P2;
100  auto &mCorrImg = CorrImg();
101  auto &mV1 = V1();
102  auto &mV2 = V2();
103  auto &mP1 = P1();
104  auto &mP2 = P2();
105  int size_x = XSIZE(mV1);
106  int size_y = YSIZE(mV1);
107  auto rot = rot_v[i];
108 
109  // Filter
110  FourierFilter filter;
111  filter.FilterBand=LOWPASS;
112  filter.w1=1.0/12.0;
113  filter.raised_w=0.02;
114 
115  for (int j = 0; j < tilt_v.size(); j++)
116  {
117  projectVolume(mV1, P1, size_y, size_x, rot, tilt_v[j], 0.);
118  projectVolume(mV2, P2, size_y, size_x, rot, tilt_v[j], 0.);
119  auto &mP1 = P1();
120  auto &mP2 = P2();
121  filter.applyMaskSpace(mP1);
122  filter.applyMaskSpace(mP2);
123  OtsuSegmentation(mP1);
124  OtsuSegmentation(mP2);
125  MultidimArray<double> cmP1 = mP1;
126  MultidimArray<double> cmP2 = mP2;
127  keepBiggestComponent(cmP1);
128  keepBiggestComponent(cmP2);
129  mP1 = mP1 - cmP1;
130  mP2 = mP2 - cmP2;
131  compare(P1, P2);
132  double sum_cmp = mP1.sum();
133  if (sum_cmp > 0.0)
134  DIRECT_A2D_ELEM(mCorrImg, i, j) = 1.0;
135  else if (sum_cmp < 0.0)
136  DIRECT_A2D_ELEM(mCorrImg, i, j) = -1.0;
137  }
138 }
#define YSIZE(v)
std::vector< double > tilt_v
Rot and tilt vectors.
double OtsuSegmentation(MultidimArray< double > &V)
Definition: filters.cpp:1028
#define DIRECT_A2D_ELEM(v, i, j)
#define i
Image< double > V2
void compare(Image< double > &op1, const Image< double > &op2)
Compare binary images.
Image< double > V1
Images.
Image< double > CorrImg
#define XSIZE(v)
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
#define j
void keepBiggestComponent(MultidimArray< double > &I, double percentage, int neighbourhood)
Definition: filters.cpp:713
std::vector< double > rot_v
#define LOWPASS
void applyMaskSpace(MultidimArray< double > &v)

◆ defineParams()

void ProgCompareDensity::defineParams ( )
virtual

Define params.

Reimplemented from XmippProgram.

Definition at line 38 of file compare_density.cpp.

38  {
39  addUsageLine("Compute the deformation that properly fits two volumes using spherical harmonics");
40  addParamsLine(" -v1 <volume> : First volume to compare");
41  addParamsLine(" -v2 <volume> : Second volume to compare");
42  addParamsLine(" [-o <image=\"\">] : Output correlation image");
43  addParamsLine(" [--degstep <d=5.0>] : Degrees step size for rot and tilt angles");
44  addParamsLine(" [--thr <N=-1>] : Maximal number of the processing CPU threads");
45  addExampleLine("xmipp_compare_density -v1 vol1.vol -v2 vol2.vol -o corr_img.xmp");
46 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgCompareDensity::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 49 of file compare_density.cpp.

49  {
50  std::string aux;
51  fnVol1 = getParam("-v1");
52  fnVol2 = getParam("-v2");
53  fnImgOut = getParam("-o");
54  degstep = getDoubleParam("--degstep");
55 
56  if (fnImgOut=="")
57  fnImgOut="Rot_tilt_corr_map.xmp";
58 
59  V1.read(fnVol1);
60  V1().setXmippOrigin();
61  V2.read(fnVol2);
62  V2().setXmippOrigin();
63 
64  // Update degstep to have evenly spaced points in the interval [0,180]
65  degstep = 360. / ROUND(360./degstep);
66 
67  int size_rot = 360./degstep;
68  int size_tlt = 180./degstep;
69  tilt_v.resize(size_tlt + 1);
70  rot_v.resize(size_rot + 1);
71  CorrImg().initZeros(size_rot + 1, size_tlt + 1);
72  CorrImg().setXmippOrigin();
73 
74  std::generate(tilt_v.begin(), tilt_v.end(), [&, n = -degstep] () mutable { return n+=degstep; });
75  std::generate(rot_v.begin(), rot_v.end(), [&, n = -degstep] () mutable { return n+=degstep; });
76 
77  int threads = getIntParam("--thr");
78  if (0 >= threads) {
79  threads = CPU::findCores();
80  }
81  m_threadPool.resize(threads);
82 }
double getDoubleParam(const char *param, int arg=0)
std::vector< double > tilt_v
Rot and tilt vectors.
static unsigned findCores()
Definition: cpu.h:41
void resize(int nThreads)
Definition: ctpl.h:70
FileName fnImgOut
Output corelation image.
Image< double > V2
double degstep
Degree step.
const char * getParam(const char *param, int arg=0)
Image< double > V1
Images.
Image< double > CorrImg
#define ROUND(x)
Definition: xmipp_macros.h:210
std::vector< double > rot_v
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int getIntParam(const char *param, int arg=0)
int * n
FileName fnVol1
Volumes to compare.

◆ run()

void ProgCompareDensity::run ( )
virtual

Run.

Reimplemented from XmippProgram.

Definition at line 151 of file compare_density.cpp.

151  {
152  auto futures = std::vector<std::future<void>>();
153  futures.reserve(V1().zdim);
154 
155  auto routine = [this](int thrId, int i) {
157  };
158 
159  for (int i=0; i<rot_v.size(); i++)
160  {
161  futures.emplace_back(m_threadPool.push(routine, i));
162  }
163 
164  for (auto &f : futures) {
165  f.get();
166  }
167 
169 }
auto push(F &&f, Rest &&... rest) -> std::future< decltype(f(0, rest...))>
Definition: ctpl.h:152
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)
#define i
FileName fnImgOut
Output corelation image.
double * f
Image< double > V1
Images.
Image< double > CorrImg
std::vector< double > rot_v
void computeCorrImage(int i)
Compute corr image.

◆ show()

void ProgCompareDensity::show ( )

Show.

Definition at line 85 of file compare_density.cpp.

85  {
86  if (verbose==0)
87  return;
88  std::cout
89  << "First volume: " << fnVol1 << std::endl
90  << "Second volume: " << fnVol2 << std::endl
91  << "Output image: " << fnImgOut << std::endl
92  << "Degree step: " << degstep << std::endl
93  ;
94 
95 }
FileName fnImgOut
Output corelation image.
double degstep
Degree step.
int verbose
Verbosity level.
FileName fnVol1
Volumes to compare.

Member Data Documentation

◆ CorrImg

Image<double> ProgCompareDensity::CorrImg

Definition at line 53 of file compare_density.h.

◆ degstep

double ProgCompareDensity::degstep

Degree step.

Definition at line 49 of file compare_density.h.

◆ fnImgOut

FileName ProgCompareDensity::fnImgOut

Output corelation image.

Definition at line 46 of file compare_density.h.

◆ fnVol1

FileName ProgCompareDensity::fnVol1

Volumes to compare.

Definition at line 42 of file compare_density.h.

◆ fnVol2

FileName ProgCompareDensity::fnVol2

Definition at line 43 of file compare_density.h.

◆ rot_v

std::vector<double> ProgCompareDensity::rot_v

Definition at line 56 of file compare_density.h.

◆ tilt_v

std::vector<double> ProgCompareDensity::tilt_v

Rot and tilt vectors.

Definition at line 56 of file compare_density.h.

◆ V1

Image<double> ProgCompareDensity::V1

Images.

Definition at line 53 of file compare_density.h.

◆ V2

Image<double> ProgCompareDensity::V2

Definition at line 53 of file compare_density.h.


The documentation for this class was generated from the following files: