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

#include <resolution_ibw.h>

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

Public Member Functions

void readParams ()
 
void defineParams ()
 
void show () const
 
void run ()
 
void edgeWidth (const MultidimArray< double > &volCoeffs, const MultidimArray< double > &edges, MultidimArray< double > &widths, const Matrix1D< double > &dir, double step=0.25) const
 
double calculateIBW (MultidimArray< double > &widths) const
 
- 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 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 fnVol
 Input volume. More...
 
FileName fnOut
 Output volume with local widths. More...
 
Image< double > V
 Volume to evaluate. More...
 
- 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

Parameter class for the resolution IBW program. The program is based on P. Marziliano, F. Dufaux, S. Winkler, T. Ebrahimi. Perceptual blur and ringing metrics: application to JPEG2000. Signal Processing: Image Communication, 19: 163-172 (2004)

Definition at line 42 of file resolution_ibw.h.

Member Function Documentation

◆ calculateIBW()

double ProgResolutionIBW::calculateIBW ( MultidimArray< double > &  widths) const

Calculate the inverse border width. The calculation is only performed at the border pixels.

Definition at line 307 of file resolution_ibw.cpp.

308 {
309  double total, count;
310  total=count=0;
311 
313  {
314  double width=A3D_ELEM(widths,k,i,j);
315  if (width<1e4)
316  {
317  total+=width;
318  count++;
319  }
320  }
321  double avg = total/count;
322  return 1.0/avg;
323 }
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define j

◆ defineParams()

void ProgResolutionIBW::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 39 of file resolution_ibw.cpp.

40 {
41  addUsageLine("Evaluate the resolution of a volume through the inverse border widths");
42  addParamsLine(" -i <file> : Volume to evaluate");
43  addParamsLine(" [-o <file=\"\">] : Volume with the border widths of the edge voxels");
44 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ edgeWidth()

void ProgResolutionIBW::edgeWidth ( const MultidimArray< double > &  volCoeffs,
const MultidimArray< double > &  edges,
MultidimArray< double > &  widths,
const Matrix1D< double > &  dir,
double  step = 0.25 
) const

Compute the edge width at the edge pixels in a given direction. step controls how fine is the search of the border width.

Definition at line 205 of file resolution_ibw.cpp.

209 {
210  double forward_count, backward_count, slope;
211  Matrix1D<double> pos_aux_fw(3), pos_aux_bw(3), pos(3), pos_aux(3), next_pos(3), Kdir;
212 
213  Kdir=step*dir;
214 
215  //Visit all elements in volume
217  {
218  //Check for border pixels
219  if (A3D_ELEM(edges,k,i,j)!=0)
220  {
221  //reset all counters
222  forward_count=0;
223  backward_count=0;
224  VECTOR_R3(pos_aux_fw,j,i,k);
225  pos_aux_bw=pos=pos_aux_fw;
226 
227  //find out if pixel magnitude grows or decreases
228  pos_aux=pos;
229  pos_aux+=dir;
230  double value_plus_dir=volCoeffs.interpolatedElementBSpline3D(XX(pos_aux),YY(pos_aux),ZZ(pos_aux));
231 
232  pos_aux=pos;
233  pos_aux-=dir;
234  double value_minus_dir=volCoeffs.interpolatedElementBSpline3D(XX(pos_aux),YY(pos_aux),ZZ(pos_aux));
235 
236  slope=value_plus_dir-value_minus_dir;
237 
238  double sign;
239  if (slope>0)
240  sign=1;
241  else
242  sign=-1;
243 
244  //current_pixel is multiplied by the sign, so only one condition is enough to detect an
245  //extremum no matter if the pixel values increase or decrease
246  double current_pixel=sign*volCoeffs.interpolatedElementBSpline3D
247  (XX(pos_aux_fw),YY(pos_aux_fw),ZZ(pos_aux_fw));
248 
249  double next_pixel;
250  bool not_found;
251 
252  //Search for local extremum ahead of the edge in the given direction
253  do
254  {
255  not_found=true;
256  next_pos=pos_aux_fw+Kdir;
257  next_pixel=sign*volCoeffs.interpolatedElementBSpline3D
258  (XX(next_pos),YY(next_pos),ZZ(next_pos));
259 
260  if(next_pixel>current_pixel)
261  {
262  current_pixel=next_pixel;
263  pos_aux_fw=next_pos;
264  forward_count++;
265  }
266  else
267  {
268  not_found=false;
269  }
270  }
271  while(not_found);
272 
273  current_pixel=sign*volCoeffs.interpolatedElementBSpline3D
274  (XX(pos_aux_bw),YY(pos_aux_bw),ZZ(pos_aux_bw));
275 
276  //Search for local extremum behind of the edge in the given direction
277  do
278  {
279  not_found=true;
280  next_pos=pos_aux_bw-Kdir;
281  next_pixel=sign*volCoeffs.interpolatedElementBSpline3D
282  (XX(next_pos),YY(next_pos),ZZ(next_pos));
283 
284  if(next_pixel<current_pixel)
285  {
286  current_pixel=next_pixel;
287  pos_aux_bw=next_pos;
288  backward_count++;
289  }
290  else
291  {
292  not_found=false;
293  }
294  }
295  while(not_found);
296 
297  //If the width found for this position is smaller than the one stores in edges volume
298  //before it is overwritten
299  if ((forward_count+backward_count)<A3D_ELEM(widths,k,i,j))
300  {
301  A3D_ELEM(widths,k,i,j)=forward_count+backward_count;
302  }
303  }
304  }
305 }
double sign
T interpolatedElementBSpline3D(double x, double y, double z, int SplineDegree=3) const
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define XX(v)
Definition: matrix1d.h:85
#define j
#define YY(v)
Definition: matrix1d.h:93
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
#define ZZ(v)
Definition: matrix1d.h:101

◆ readParams()

void ProgResolutionIBW::readParams ( )
virtual

Read from a command line.

Reimplemented from XmippProgram.

Definition at line 32 of file resolution_ibw.cpp.

33 {
34  fnVol = getParam("-i");
35  fnOut = getParam("-o");
36 }
const char * getParam(const char *param, int arg=0)
FileName fnOut
Output volume with local widths.
FileName fnVol
Input volume.

◆ run()

void ProgResolutionIBW::run ( )
virtual

Compute the correlation for all micrographs

Reimplemented from XmippProgram.

Definition at line 58 of file resolution_ibw.cpp.

59 {
60  V.read(fnVol);
61 
62  //Mask generation
63  Image<double> aux;
64  double bg_mean;
66  detectBackground(V(),aux(),0.1,bg_mean);
67 #ifdef DEBUG
68 
69  aux.write("PPPmask_no_ero_03.vol");
70 #endif
71 
72  //Mask volume erosion to expand the mask boundaries
73  Vmask.initZeros(V());
74  erode3D(aux(),Vmask, 18,0,2);
75 
76  //Correction of some flaws produced in the edges of the mask volume
78  if (k<=4 || i<=4 || j<=4 ||
79  k>=ZSIZE(Vmask)-4 || i>=YSIZE(Vmask)-4 || j>=XSIZE(Vmask)-4)
80  DIRECT_A3D_ELEM(Vmask,k,i,j)=1;
81 
82  aux()=Vmask;
83 #ifdef DEBUG
84 
85  aux.write("PPPmask_ero_03.vol");
86 #endif
87 
88  //Sobel edge detection applied to original volume
89  Image<double> Vedge;
90  computeEdges(V(),Vedge());
91 #ifdef DEBUG
92 
93  Vedge.write("PPPvolume_sobel_unmask_03.vol");
94 #endif
95 
96  //Masked volume generation
97  const MultidimArray<double> &mVedge=Vedge();
99  if (DIRECT_MULTIDIM_ELEM(Vmask,n)==1)
100  DIRECT_MULTIDIM_ELEM(mVedge,n)=0;
101 #ifdef DEBUG
102 
103  Vedge.write("volume_sobel_mask_03.vol");
104 #endif
105 
106  double minval, maxval, avg, stddev;
107 
108  //Invert the mask to meet computeStats_within_binary_mask requirements
110  if (DIRECT_MULTIDIM_ELEM(Vmask,n)==1)
111  DIRECT_MULTIDIM_ELEM(Vmask,n)=0;
112  else
113  DIRECT_MULTIDIM_ELEM(Vmask,n)=1;
114 
115  //Threshold is 3 times the standard deviation of unmasked pixel values
116  double thresh;
117  computeStats_within_binary_mask(Vmask,mVedge,minval, maxval, avg, stddev);
118  thresh=3*stddev;
119 
120  //Final edge volume generated by setting to 1 positions with values > threshold
121  Image<double> Vaux;
122  Vaux().initZeros(mVedge);
124  if (DIRECT_MULTIDIM_ELEM(mVedge,n)>=thresh)
125  DIRECT_MULTIDIM_ELEM(Vaux(),n)=1;
126 
127 #ifdef DEBUG
128 
129  Vaux.write("volumen_bordes_definitivo_03.vol");
130 #endif
131 
132  const MultidimArray<double> &mVaux=Vaux();
133 
134  //Spline coefficient volume from original volume, to allow <1 step sizes
135  MultidimArray<double> Volcoeffs;
136  Volcoeffs.initZeros(V());
137 
138  produceSplineCoefficients(3,Volcoeffs,V());
139 
140  //Width parameter volume initialization
141  Image<double> widths;
142  widths().resizeNoCopy(V());
143  widths().initConstant(1e5);
144  double step=0.25;
145 
147 
148  //Calculation of edge width for 10 different directions, if a smaller value is found for a different
149  //direction on a given position the former value is overwritten
150 
151  //Direction (1,0,0)
152  VECTOR_R3(direction,1,0,0);
153  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
154 
155  //Direction (0,1,0)
156  VECTOR_R3(direction,0,1,0);
157  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
158 
159  //Direction (0,0,1)
160  VECTOR_R3(direction,0,0,1);
161  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
162 
163  //Direction (1,1,0)
164  VECTOR_R3(direction,(1/sqrt(2)),(1/sqrt(2)),0);
165  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
166 
167  //Direction (1,0,1)
168  VECTOR_R3(direction,(1/sqrt(2)),0,(1/sqrt(2)));
169  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
170 
171  //Direction (0,1,1)
172  VECTOR_R3(direction,0,(1/sqrt(2)),(1/sqrt(2)));
173  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
174 
175  //Direction (1,1,1)
176  VECTOR_R3(direction,(1/sqrt(3)),(1/sqrt(3)),(1/sqrt(3)));
177  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
178 
179  //Direction (-1,1,1)
180  VECTOR_R3(direction,-(1/sqrt(3)),(1/sqrt(3)),(1/sqrt(3)));
181  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
182 
183  //Direction (1,1,-1)
184  VECTOR_R3(direction,(1/sqrt(3)),(1/sqrt(3)),-(1/sqrt(3)));
185  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
186 
187  //Direction (1,-1,1)
188  VECTOR_R3(direction,(1/sqrt(3)),-(1/sqrt(3)),(1/sqrt(3)));
189  edgeWidth(Volcoeffs, mVaux, widths(), direction, step);
190 
191 #ifdef DEBUG
192 
193  std::cout << "width stats: ";
194  widths().printStats();
195  std::cout << std::endl;
196  widths.write("PPPwidths.vol");
197 #endif
198 
199  double ibw=calculateIBW(widths());
200  std::cout << "Resolution ibw= " << ibw << std::endl;
201  if (fnOut!="")
202  widths.write(fnOut);
203 }
#define YSIZE(v)
void erode3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:407
void sqrt(Image< double > &op)
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 FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
void detectBackground(const MultidimArray< double > &vol, MultidimArray< double > &mask, double alpha, double &final_mean)
Definition: filters.cpp:197
void produceSplineCoefficients(int SplineDegree, MultidimArray< double > &coeffs, const MultidimArray< T > &V1)
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define ZSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void computeEdges(const MultidimArray< double > &vol, MultidimArray< double > &vol_edge)
Definition: filters.cpp:3517
void direction(const MultidimArray< double > &orMap, MultidimArray< double > &qualityMap, double lambda, int size, MultidimArray< double > &dirMap, int x, int y)
#define DIRECT_A3D_ELEM(v, k, i, j)
Image< double > V
Volume to evaluate.
FileName fnOut
Output volume with local widths.
#define j
FileName fnVol
Input volume.
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void edgeWidth(const MultidimArray< double > &volCoeffs, const MultidimArray< double > &edges, MultidimArray< double > &widths, const Matrix1D< double > &dir, double step=0.25) const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void initZeros(const MultidimArray< T1 > &op)
double calculateIBW(MultidimArray< double > &widths) const
int * n

◆ show()

void ProgResolutionIBW::show ( ) const
virtual

Show parameters.

Reimplemented from XmippProgram.

Definition at line 47 of file resolution_ibw.cpp.

48 {
49  if (verbose==0)
50  return;
51  std::cout << "Input volume: " << fnVol << std::endl
52  << "Output widths: " << fnOut << std::endl
53  ;
54 }
int verbose
Verbosity level.
FileName fnOut
Output volume with local widths.
FileName fnVol
Input volume.

Member Data Documentation

◆ fnOut

FileName ProgResolutionIBW::fnOut

Output volume with local widths.

Definition at line 49 of file resolution_ibw.h.

◆ fnVol

FileName ProgResolutionIBW::fnVol

Input volume.

Definition at line 46 of file resolution_ibw.h.

◆ V

Image<double> ProgResolutionIBW::V

Volume to evaluate.

Definition at line 53 of file resolution_ibw.h.


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