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

#include <volume_segment.h>

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

Public Member Functions

void readParams ()
 Read arguments. More...
 
void show () const
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void produce_side_info ()
 
void segment (Image< double > &mask)
 
void run ()
 
- 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 fn_vol
 Input volume. More...
 
String method
 Segmentation method. More...
 
double voxel_mass
 
double dalton_mass
 Desired mass (in Daltons). Not necessary if voxel_mass is provided. More...
 
double aa_mass
 Desired mass (in aminoacids). Not necessary if voxel_mass is provided. More...
 
double sampling_rate
 Sampling rate (in A/pixel). Not necessary if voxel_mass is provided. More...
 
FileName fn_mask
 Output mask. If not given it is not written. More...
 
bool en_threshold
 Enable a single threshold measure. More...
 
double threshold
 Threshold. More...
 
bool otsu
 Use Otse. More...
 
bool do_prob
 From here on by Sjors. More...
 
int wang_radius
 radius for B.C. Wang-like smoothing procedure More...
 
Image< double > 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

Segment parameters.

Definition at line 37 of file volume_segment.h.

Member Function Documentation

◆ defineParams()

void ProgVolumeSegment::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 90 of file volume_segment.cpp.

91 {
92  addParamsLine(" -i <volume> : Volume to segment");
93  addParamsLine(" [-o <mask=\"\">] : Output mask");
94  addParamsLine(" --method <method> : Segmentation method");
95  addParamsLine(" where <method>");
96  addParamsLine(" voxel_mass <mass> : Mass in voxels");
97  addParamsLine(" dalton_mass <mass> <Tm=1> : Mass in daltons");
98  addParamsLine(" : Tm is the sampling rate (A/pixel)");
99  addParamsLine(" aa_mass <mass> <Tm=1> : Mass in aminoacids");
100  addParamsLine(" : Tm is the sampling rate (A/pixel)");
101  addParamsLine(" threshold <th> : Thresholding");
102  addParamsLine(" otsu : Otsu's method segmentation");
103  addParamsLine(" prob <radius=-1> : Probabilistic solvent mask (typical value 3)");
104  addParamsLine(" : Radius [pix] is used for B.C. Wang cone smoothing");
105 }
void addParamsLine(const String &line)

◆ produce_side_info()

void ProgVolumeSegment::produce_side_info ( )

Produce side info. Read the input volume, and compute the number of voxels if not given. An exception is thrown if no way is given to compute the voxel mass

Definition at line 108 of file volume_segment.cpp.

109 {
110  V.read(fn_vol);
111  if (method=="dalton_mass" || method=="aa_mass")
112  {
113  if ((dalton_mass == -1 && aa_mass == -1) || sampling_rate == -1)
114  REPORT_ERROR(ERR_VALUE_INCORRECT, "No way to compute voxel mass");
115  double sampling_rate3 = sampling_rate * sampling_rate * sampling_rate;
116  if (dalton_mass != -1)
117  voxel_mass = dalton_mass * 1.207 / sampling_rate3;
118  else
119  voxel_mass = aa_mass * 110 * 1.207 / sampling_rate3;
120  std::cout << std::endl << "Derived voxel_mass=" << voxel_mass << std::endl;
121  }
122 }
Image< double > V
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
String method
Segmentation method.
FileName fn_vol
Input volume.
double aa_mass
Desired mass (in aminoacids). Not necessary if voxel_mass is provided.
double sampling_rate
Sampling rate (in A/pixel). Not necessary if voxel_mass is provided.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
double dalton_mass
Desired mass (in Daltons). Not necessary if voxel_mass is provided.
Incorrect value received.
Definition: xmipp_error.h:195

◆ readParams()

void ProgVolumeSegment::readParams ( )
virtual

Read arguments.

Reimplemented from XmippProgram.

Definition at line 32 of file volume_segment.cpp.

33 {
35  sampling_rate=-1;
36  threshold=-1;
37  wang_radius=-1;
38  en_threshold=false;
39  do_prob=false;
40  otsu=false;
41 
42  fn_vol = getParam("-i");
43  fn_mask = getParam("-o");
44  method=getParam("--method");
45  if (method=="voxel_mass")
46  voxel_mass = getDoubleParam("--method", 1);
47  else if (method=="dalton_mass")
48  {
49  dalton_mass = getDoubleParam("--method", 1);
50  sampling_rate = getDoubleParam("--method", 2);
51  }
52  else if (method=="aa_mass")
53  {
54  aa_mass = getDoubleParam("--method", 1);
55  sampling_rate = getDoubleParam("--method", 2);
56  }
57  else if (method=="threshold")
58  {
59  en_threshold = true;
60  threshold = getDoubleParam("--method", 1);
61  }
62  else if (method=="otsu")
63  otsu=true;
64  else if (method=="prob")
65  {
66  do_prob = true;
67  wang_radius = getIntParam("--method", 1);
68  }
69 }
double getDoubleParam(const char *param, int arg=0)
String method
Segmentation method.
FileName fn_mask
Output mask. If not given it is not written.
bool en_threshold
Enable a single threshold measure.
const char * getParam(const char *param, int arg=0)
double threshold
Threshold.
FileName fn_vol
Input volume.
double aa_mass
Desired mass (in aminoacids). Not necessary if voxel_mass is provided.
bool otsu
Use Otse.
double sampling_rate
Sampling rate (in A/pixel). Not necessary if voxel_mass is provided.
double dalton_mass
Desired mass (in Daltons). Not necessary if voxel_mass is provided.
int wang_radius
radius for B.C. Wang-like smoothing procedure
int getIntParam(const char *param, int arg=0)
bool do_prob
From here on by Sjors.

◆ run()

void ProgVolumeSegment::run ( )
virtual

Run

Reimplemented from XmippProgram.

Definition at line 369 of file volume_segment.cpp.

370 {
371  Image<double> mask;
372  show();
374  segment(mask);
375 }
void show() const
Show.
void segment(Image< double > &mask)

◆ segment()

void ProgVolumeSegment::segment ( Image< double > &  mask)

Really compute the mask. If a mask name is given then it is written to disk.

Definition at line 293 of file volume_segment.cpp.

294 {
295  double th_min, th_max, val_min=0., val_max=0.;
296  V().computeDoubleMinMax(val_min, val_max);
297  th_min = val_min;
298  th_max = val_max;
299 
300  bool ok = false;
301  if (!otsu)
302  {
303  if (!en_threshold)
304  {
305  // Perform a bracketing search until the mass is
306  // within a 0.1% of the desired mass
307  do
308  {
309  double th_med = (th_min + th_max) * 0.5;
310  double mass_med = segment_threshold(&V, &mask, th_med, do_prob);
311  std::cout << "Threshold= " << th_med
312  << " mass of the main piece= " << mass_med << std::endl;
313  if (ABS(mass_med - voxel_mass) / voxel_mass < 0.001)
314  {
315  ok = true;
316  break;
317  }
318  if ((th_max - th_min) / (val_max - val_min) < 0.0001)
319  break;
320  if (mass_med < voxel_mass)
321  {
322  th_max = th_med;
323  }
324  else
325  {
326  th_min = th_med;
327  }
328  }
329  while (true);
330  }
331  else
332  {
333  // Perform a single thresholding
334  double mass_med = segment_threshold(&V, &mask, threshold, do_prob);
335  std::cout << "Threshold= " << threshold
336  << " mass of the main piece= " << mass_med << std::endl;
337  ok = true;
338  }
339  }
340 
341  if (otsu)
342  {
343  mask()=V();
344  double th=EntropyOtsuSegmentation(mask());
345  std::cout << "Threshold " << th << std::endl;
346  ok=true;
347  }
348 
349  if (do_prob)
350  {
351  // Wang-Leslie like modification of the input volume
352  if (wang_radius >= 3)
353  {
354  Image<double> Vwang;
355  wang_smoothing(&V, &Vwang, wang_radius);
356  V = Vwang;
357  }
358  // Terwilliger-like calculation of P(solv|x) through P(x|solv) & P(x|prot)
359  probabilistic_solvent(&V, &mask);
360  }
361 
362  // Save mask if necessary
363  if (fn_mask != "" && (ok || do_prob))
364  mask.write(fn_mask);
365  if (!ok && !do_prob)
366  std::cout << "Segment: Cannot find an appropriate threshold\n";
367 }
Image< double > V
void wang_smoothing(const Image< double > *V_in, Image< double > *V_out, int radius)
void probabilistic_solvent(Image< double > *V_in, Image< double > *V_out)
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)
FileName fn_mask
Output mask. If not given it is not written.
bool en_threshold
Enable a single threshold measure.
double EntropyOtsuSegmentation(MultidimArray< double > &V, double percentil, bool binarizeVolume)
Definition: filters.cpp:1145
double segment_threshold(const Image< double > *V_in, Image< double > *V_out, double threshold, bool do_prob)
#define ABS(x)
Definition: xmipp_macros.h:142
double threshold
Threshold.
bool otsu
Use Otse.
int wang_radius
radius for B.C. Wang-like smoothing procedure
bool do_prob
From here on by Sjors.

◆ show()

void ProgVolumeSegment::show ( ) const
virtual

Show.

Reimplemented from XmippProgram.

Definition at line 72 of file volume_segment.cpp.

73 {
74  std::cout
75  << "Input file : " << fn_vol << std::endl
76  << "Voxel mass : " << voxel_mass << std::endl
77  << "Dalton mass : " << dalton_mass << std::endl
78  << "AA mass : " << aa_mass << std::endl
79  << "Sampling rate: " << sampling_rate << std::endl
80  << "Output mask : " << fn_mask << std::endl
81  << "Enable thres.: " << en_threshold << std::endl
82  << "Threshold : " << threshold << std::endl
83  << "Otsu : " << otsu << std::endl
84  << "Wang radius : " << wang_radius << std::endl
85  << "Probabilistic: " << do_prob << std::endl
86  ;
87 }
FileName fn_mask
Output mask. If not given it is not written.
bool en_threshold
Enable a single threshold measure.
double threshold
Threshold.
FileName fn_vol
Input volume.
double aa_mass
Desired mass (in aminoacids). Not necessary if voxel_mass is provided.
bool otsu
Use Otse.
double sampling_rate
Sampling rate (in A/pixel). Not necessary if voxel_mass is provided.
double dalton_mass
Desired mass (in Daltons). Not necessary if voxel_mass is provided.
int wang_radius
radius for B.C. Wang-like smoothing procedure
bool do_prob
From here on by Sjors.

Member Data Documentation

◆ aa_mass

double ProgVolumeSegment::aa_mass

Desired mass (in aminoacids). Not necessary if voxel_mass is provided.

Definition at line 50 of file volume_segment.h.

◆ dalton_mass

double ProgVolumeSegment::dalton_mass

Desired mass (in Daltons). Not necessary if voxel_mass is provided.

Definition at line 48 of file volume_segment.h.

◆ do_prob

bool ProgVolumeSegment::do_prob

From here on by Sjors.

Definition at line 64 of file volume_segment.h.

◆ en_threshold

bool ProgVolumeSegment::en_threshold

Enable a single threshold measure.

Definition at line 56 of file volume_segment.h.

◆ fn_mask

FileName ProgVolumeSegment::fn_mask

Output mask. If not given it is not written.

Definition at line 54 of file volume_segment.h.

◆ fn_vol

FileName ProgVolumeSegment::fn_vol

Input volume.

Definition at line 41 of file volume_segment.h.

◆ method

String ProgVolumeSegment::method

Segmentation method.

Definition at line 43 of file volume_segment.h.

◆ otsu

bool ProgVolumeSegment::otsu

Use Otse.

Definition at line 60 of file volume_segment.h.

◆ sampling_rate

double ProgVolumeSegment::sampling_rate

Sampling rate (in A/pixel). Not necessary if voxel_mass is provided.

Definition at line 52 of file volume_segment.h.

◆ threshold

double ProgVolumeSegment::threshold

Threshold.

Definition at line 58 of file volume_segment.h.

◆ V

Image<double> ProgVolumeSegment::V

Definition at line 70 of file volume_segment.h.

◆ voxel_mass

double ProgVolumeSegment::voxel_mass

Desired mass (in voxels), if not given computed from the mass and the sampling rate by produce_info.

Definition at line 46 of file volume_segment.h.

◆ wang_radius

int ProgVolumeSegment::wang_radius

radius for B.C. Wang-like smoothing procedure

Definition at line 66 of file volume_segment.h.


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