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

#include <classify_extract_features.h>

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

Public Member Functions

 ProgExtractFeatures ()=default
 
 ProgExtractFeatures (const ProgExtractFeatures &)=delete
 
 ProgExtractFeatures (const ProgExtractFeatures &&)=delete
 
 ~ProgExtractFeatures ()
 
ProgExtractFeaturesoperator= (const ProgExtractFeatures &)=delete
 
ProgExtractFeaturesoperator= (const ProgExtractFeatures &&)=delete
 
void readParams ()
 Read argument. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
int facs (int n)
 Function for returning factorial up to n=4. More...
 
void extractEntropy (const MultidimArray< double > &I, MultidimArray< double > &Imasked, std::vector< double > &fv)
 Extracting entropy features. More...
 
void extractGranulo (const MultidimArray< double > &I, std::vector< double > &fv)
 Extracting granulometry features. More...
 
void extractHistDist (const MultidimArray< double > &I, std::vector< double > &fv)
 Extracting histogram distances. More...
 
void extractLBP (const MultidimArray< double > &I, std::vector< double > &fv)
 
void extractRamp (const MultidimArray< double > &I, std::vector< double > &fv)
 Gray ramp coefficients. More...
 
void extractVariance (const MultidimArray< double > &I, std::vector< double > &fv)
 Extracting variance features. More...
 
void extractZernike (const MultidimArray< double > &I, std::vector< double > &fv)
 
void run ()
 Main routine. 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 fnSel
 
FileName fnOut
 
bool applyDenoising
 
bool useEntropy
 
bool useGranulo
 
bool useHistDist
 
bool useLBP
 
bool useRamp
 
bool useVariance
 
bool useZernike
 
MultidimArray< int > masks [7]
 
MultidimArray< int > rampMask
 
FitPointfitPoints =nullptr
 
int NmaskPoints
 
- 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

Definition at line 37 of file classify_extract_features.h.

Constructor & Destructor Documentation

◆ ProgExtractFeatures() [1/3]

ProgExtractFeatures::ProgExtractFeatures ( )
default

◆ ProgExtractFeatures() [2/3]

ProgExtractFeatures::ProgExtractFeatures ( const ProgExtractFeatures )
delete

◆ ProgExtractFeatures() [3/3]

ProgExtractFeatures::ProgExtractFeatures ( const ProgExtractFeatures &&  )
delete

◆ ~ProgExtractFeatures()

ProgExtractFeatures::~ProgExtractFeatures ( )

Definition at line 33 of file classify_extract_features.cpp.

34 {
35  if (fitPoints!=nullptr)
36  delete []fitPoints;
37 }

Member Function Documentation

◆ defineParams()

void ProgExtractFeatures::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 74 of file classify_extract_features.cpp.

75 {
76  addUsageLine("Clusters a set of images");
77  addParamsLine(" -i <selfile> : Images to be clustered");
78  addParamsLine(" [-o <selfile=\"\">] : Output selfile");
79  addParamsLine(" [--applyDenoising] : Turn on denoising");
80  addParamsLine(" [--entropy] : Extract entropy features");
81  addParamsLine(" [--granulo] : Extract granulo features");
82  addParamsLine(" [--histdist] : Extract histogram distances");
83  addParamsLine(" [--lbp] : Extract LBP features");
84  addParamsLine(" [--ramp] : Extract Ramp coefficients");
85  addParamsLine(" [--variance] : Extract variance features");
86  addParamsLine(" [--zernike] : Extract Zernike moments");
87 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ extractEntropy()

void ProgExtractFeatures::extractEntropy ( const MultidimArray< double > &  I,
MultidimArray< double > &  Imasked,
std::vector< double > &  fv 
)

Extracting entropy features.

Definition at line 98 of file classify_extract_features.cpp.

101 {
102  int hist[256] = {};
103  int val;
104 
105  // entropy of entire image
106  double m, M;
107  I.computeDoubleMinMax(m,M);
109  {
110  val = floor(((DIRECT_MULTIDIM_ELEM(I, n) - m) * 255.0) / (M - m));
111  hist[val]++;
112  }
113 
114  double entropy = 0;
115  for (int i = 0; i < 256; i++)
116  entropy += std::max(hist[i], 1) * log2((std::max(hist[i], 1)));
117 
118  fv.push_back(-1*entropy);
119 
120  // preparing masks for feature extraction, will be performed only once
121  if (XSIZE(masks[0]) < 1)
122  {
123  for (int i = 0; i < (sizeof(masks)/sizeof(*masks)); i++)
124  {
125  masks[i].resize(I);
127  }
128 
129  int wave_size = XSIZE(I) / 2;
130  int wave_size_step = XSIZE(I) / 32;
131 
132  // simple inner-circle regions without negative values
133 // for (int i=2; i<(sizeof(masks)/sizeof(*masks)); i++)
134 // {
135 // BinaryCircularMask(masks[0], wave_size);
136 // BinaryCircularMask(masks[1], wave_size - wave_size_step);
137 //
138 // // if we want overlapping regions (rings)
139 // // BinaryCircularMask(masks[1], wave_size - 2*wave_size_step);
140 //
141 // FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(masks[0])
142 // DIRECT_MULTIDIM_ELEM(masks[i],n) = DIRECT_MULTIDIM_ELEM(masks[0],n) -
143 // DIRECT_MULTIDIM_ELEM(masks[1],n);
144 //
145 // wave_size -= wave_size_step;
146 // }
147 
148  for (int i = 2; i < (sizeof(masks)/sizeof(*masks)); i++)
149  {
150  BinaryCircularMask(masks[0], wave_size);
151  BinaryCircularMask(masks[1], wave_size - wave_size_step);
152 
156 
157  BinaryCircularMask(masks[1], wave_size - 2*wave_size_step);
161 
162 
163  wave_size -= wave_size_step; // overlapping regions (rings)
164  //wave_size -= 2*wave_size_step; // non-overlapping regions (rings)
165  }
166  }
167 
168  // extracting entropy from unmasked regions
169  for (int i = 2; i < (sizeof(masks)/sizeof(*masks)); i++)
170  {
171  apply_binary_mask(masks[i], I, Imasked);
172  int hist[256] = {};
173  int idx;
174  Imasked.computeDoubleMinMax(m,M);
176  {
177  idx = floor(((DIRECT_MULTIDIM_ELEM(Imasked, n) - m) * 255.0) / (M-m));
178  hist[idx]++;
179  }
180 
181  double entropy = 0;
182  for (int i = 0; i < 256; i++)
183  entropy += std::max(hist[i], 1) * log2(std::max(hist[i], 1));
184 
185  fv.push_back(-1*entropy);
186  }
187 }
double log2(double x, ae_state *_state)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
__host__ __device__ float2 floor(const float2 v)
void apply_binary_mask(const MultidimArray< int > &mask, const MultidimArray< T > &m_in, MultidimArray< T > &m_out, T subs_val=(T) 0)
Definition: mask.h:857
void BinaryCircularMask(MultidimArray< int > &mask, double radius, int mode, double x0, double y0, double z0)
Definition: mask.cpp:193
#define i
#define XSIZE(v)
void computeDoubleMinMax(double &minval, double &maxval) const
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int m
MultidimArray< int > masks[7]
int * n

◆ extractGranulo()

void ProgExtractFeatures::extractGranulo ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Extracting granulometry features.

Definition at line 190 of file classify_extract_features.cpp.

192 {
193  Image<double> G;
194  G().resizeNoCopy(I);
195  double m, M;
196  I.computeDoubleMinMax(m, M);
197 
198  if (XSIZE(I) < 15 || YSIZE(I) < 15)
199  {
200  std::cerr << "ERROR: Input image must be at least 15x15px"
201  << "to extract granulo features!\n";
202  exit(1);
203  }
204 
205  for (int N = 1; N < 7; N++)
206  {
207  // creating circular structuring element
208  int size = N*2 + 1;
209  bool struct_elem[size][size];
210  for (int y = 0; y < size; y++)
211  {
212  for (int x = 0; x < size; x++)
213  struct_elem[x][y] = ((x-N)*(x-N) + (y-N)*(y-N)) <= N*N;
214  }
215 
216  // morphological erosion
217  double sum = 0.0;
218  for (int y = 0; y < YSIZE(I); y++)
219  {
220  for (int x = 0; x < XSIZE(I); x++)
221  {
222  double struct_min = M;
223 
224  for (int yy = y-N; yy <= y+N; yy++)
225  {
226  if (yy < 0 || yy >= YSIZE(I)) continue;
227 
228  for (int xx = x-N; xx <= x+N; xx++)
229  {
230  if (xx < 0 || xx >= XSIZE(I)) continue;
231 
232  if (struct_elem[xx+N-x][yy+N-y] &&
233  DIRECT_A2D_ELEM(I, yy, xx) < struct_min)
234  struct_min = DIRECT_A2D_ELEM(I, yy, xx);
235  }
236  }
237  DIRECT_A2D_ELEM(G(), y, x) = struct_min;
238  }
239  }
240 
241  // morphological dilation (dilation after erosion = opening)
242  for (int y = 0; y < YSIZE(I); y++)
243  {
244  for (int x = 0; x < XSIZE(I); x++)
245  {
246  double struct_max = m;
247 
248  for (int yy = y-N; yy <= y+N; yy++)
249  {
250  if (yy < 0 || yy >= YSIZE(I)) continue;
251 
252  for (int xx = x-N; xx <= x+N; xx++)
253  {
254  if (xx < 0 || xx >= XSIZE(I)) continue;
255 
256  if (struct_elem[xx+N-x][yy+N-y] &&
257  DIRECT_A2D_ELEM(G(), yy, xx) > struct_max)
258  struct_max = DIRECT_A2D_ELEM(G(), yy, xx);
259  }
260  }
261  sum += struct_max;
262  }
263  }
264  fv.push_back(sum);
265  }
266 }
#define YSIZE(v)
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
doublereal * x
#define XSIZE(v)
void computeDoubleMinMax(double &minval, double &maxval) const
int m

◆ extractHistDist()

void ProgExtractFeatures::extractHistDist ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Extracting histogram distances.

Definition at line 269 of file classify_extract_features.cpp.

271 {
272  MultidimArray<double> Ipart;
273  Ipart.resize(XSIZE(I)/3, YSIZE(I)/3);
274  for (int yy = 1; yy <= 3; yy++)
275  {
276  int y_max = YSIZE(I) / 3 * yy;
277  int y_min = YSIZE(I) / 3 * (yy-1);
278  for (int xx = 1; xx <= 3; xx++)
279  {
280  int x_max = XSIZE(I) / 3 * xx;
281  int x_min = XSIZE(I) / 3 * (xx-1);
282  int ypart = 0;
283  for (int y = y_min; y < y_max; y++)
284  {
285  int xpart = 0;
286  for (int x = x_min; x < x_max; x++)
287  {
288  DIRECT_A2D_ELEM(Ipart, ypart, xpart) =
289  DIRECT_A2D_ELEM(I, y, x);
290  xpart++;
291  }
292  ypart++;
293  }
294 
295  int count = XSIZE(Ipart) + YSIZE(Ipart);
296  int hist[256] = {};
297  int low_thresh, high_thresh;
298  int low_thresh_cnt = 0, high_thresh_cnt = 0;
299  typedef std::pair<int, int> pairs;
300  std::set<pairs> low_inten_pts, high_inten_pts;
301 
302  int temp;
303  double m, M;
304  Ipart.computeDoubleMinMax(m, M);
306  {
307  temp = floor(((DIRECT_MULTIDIM_ELEM(Ipart, n)- m)*255.0) / (M-m));
308  hist[temp]++;
309  DIRECT_MULTIDIM_ELEM(Ipart, n) = temp;
310  }
311 
312  for (low_thresh = 0; low_thresh_cnt < count; low_thresh++)
313  low_thresh_cnt += hist[low_thresh];
314  for (high_thresh = 255; high_thresh_cnt < count; high_thresh--)
315  high_thresh_cnt += hist[high_thresh];
316 
318  {
319  if (DIRECT_A2D_ELEM(Ipart, i, j) < low_thresh)
320  low_inten_pts.insert(std::make_pair(i, j));
321  else if (DIRECT_A2D_ELEM(Ipart, i, j) > high_thresh)
322  high_inten_pts.insert(std::make_pair(i, j));
323  }
324 
325  double dist_high = 0.0, dist_low = 0.0;
326  int comparisons = 0;
327 
328  for (std::set<pairs>:: iterator it1 = high_inten_pts.begin();
329  it1 != --high_inten_pts.end(); ++it1)
330  {
331  pairs p1 = *it1;
332  for (std::set<pairs>::iterator it2 = ++it1;
333  it2 != high_inten_pts.end(); ++it2)
334  {
335  pairs p2 = *it2;
336  dist_high += sqrt((p1.first - p2.first) * (p1.first - p2.first) +
337  (p1.second - p2.second) * (p1.second - p2.second));
338  comparisons++;
339  }
340  --it1;
341  }
342  fv.push_back(dist_high / comparisons);
343 
344  comparisons = 0;
345  for (std::set<pairs>:: iterator it1 = low_inten_pts.begin();
346  it1 != --low_inten_pts.end(); ++it1)
347  {
348  pairs p1 = *it1;
349  for (std::set<pairs>::iterator it2 = ++it1;
350  it2 != low_inten_pts.end(); ++it2)
351  {
352  pairs p2 = *it2;
353  dist_low += sqrt((p1.first - p2.first) * (p1.first - p2.first) +
354  (p1.second - p2.second) * (p1.second - p2.second));
355  comparisons++;
356  }
357  --it1;
358  }
359  fv.push_back(dist_low / comparisons);
360  }
361  }
362 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
__host__ __device__ float2 floor(const float2 v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
void sqrt(Image< double > &op)
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
doublereal * x
#define i
#define XSIZE(v)
void computeDoubleMinMax(double &minval, double &maxval) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
int m
int * n

◆ extractLBP()

void ProgExtractFeatures::extractLBP ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Extracting LBP features See method at Ojala, Timo, Matti Pietikainen, and Topi Maenpaa. "Multiresolution gray-scale and rotation invariant texture classification with local binary patterns." IEEE Transactions on Pattern Analysis and Machine Intelligence 24.7 (2002): 971-987.

Definition at line 365 of file classify_extract_features.cpp.

367 {
368  std::vector<double> min_idxs, min_idxs_sort;
369 
370  unsigned char code;
371  double center;
372  int lbp_hist[256] = {};
373 
374  for (int i = 0; i < 256; i++)
375  {
376  code = i;
377  auto code_min = (int) code;
378  for (int ii = 0; ii < 7; ii++)
379  {
380  unsigned char c = code & 1;
381  code >>= 1;
382  code |= (c << 7);
383  if ((int) code < code_min)
384  code_min = (int) code;
385  }
386  min_idxs.push_back(code_min);
387  }
388  min_idxs_sort = min_idxs;
389  std::sort(min_idxs_sort.begin(), min_idxs_sort.end());
390  auto last=std::unique(min_idxs_sort.begin(), min_idxs_sort.end());
391  min_idxs_sort.erase(last,min_idxs_sort.end());
392 
393  for (int y = 1; y < (YSIZE(I)-1); y++)
394  {
395  for (int x = 1; x < (XSIZE(I)-1); x++)
396  {
397  code = 0;
398  center = DIRECT_A2D_ELEM(I,y,x);
399  code |= (DIRECT_A2D_ELEM(I,y-1,x-1) > center) << 7;
400  code |= (DIRECT_A2D_ELEM(I,y-1,x ) > center) << 6;
401  code |= (DIRECT_A2D_ELEM(I,y-1,x+1) > center) << 5;
402  code |= (DIRECT_A2D_ELEM(I,y, x+1) > center) << 4;
403  code |= (DIRECT_A2D_ELEM(I,y+1,x+1) > center) << 3;
404  code |= (DIRECT_A2D_ELEM(I,y+1,x ) > center) << 2;
405  code |= (DIRECT_A2D_ELEM(I,y+1,x-1) > center) << 1;
406  code |= (DIRECT_A2D_ELEM(I,y ,x-1) > center) << 0;
407  int idx = min_idxs[(int) code];
408  lbp_hist[idx]++;
409  }
410  }
411 
412  for (int i = 0; i < 36; i++)
413  {
414  int idx = min_idxs_sort[i];
415  fv.push_back(lbp_hist[idx]);
416  }
417 }
#define YSIZE(v)
doublereal * c
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
doublereal * x
#define i
#define XSIZE(v)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18

◆ extractRamp()

void ProgExtractFeatures::extractRamp ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Gray ramp coefficients.

Definition at line 419 of file classify_extract_features.cpp.

421 {
422  if (XSIZE(rampMask)==0)
423  {
424  rampMask.resize(I);
429  }
430  size_t idx=0;
432  {
433  if (A2D_ELEM(rampMask, i, j))
434  {
435  FitPoint &p=fitPoints[idx++];
436  p.x = j;
437  p.y = i;
438  p.z = A2D_ELEM(I, i, j);
439  p.w = 1.;
440  }
441  }
442 
443  double pA, pB, pC;
445  fv.push_back(pA);
446  fv.push_back(pB);
447  fv.push_back(pC);
448 }
#define A2D_ELEM(v, i, j)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void least_squares_plane_fit(FitPoint *IN_points, int Npoints, double &plane_a, double &plane_b, double &plane_c)
Definition: geometry.cpp:101
MultidimArray< int > rampMask
double z
z coordinate, assumed to be a function of x and y
Definition: geometry.h:190
void BinaryCircularMask(MultidimArray< int > &mask, double radius, int mode, double x0, double y0, double z0)
Definition: mask.cpp:193
double x
x coordinate
Definition: geometry.h:186
double w
Weight of the point in the Least-Squares problem.
Definition: geometry.h:192
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define XSIZE(v)
double y
y coordinate
Definition: geometry.h:188
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
double sum() const

◆ extractVariance()

void ProgExtractFeatures::extractVariance ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Extracting variance features.

Definition at line 451 of file classify_extract_features.cpp.

453 {
454  double var_i_sum = 0.0;
455  double var_o_sum = 0.0;
456  for (int yy = 1; yy <= 4; yy++)
457  {
458  int y_max = YSIZE(I) / 4 * yy;
459  int y_min = YSIZE(I) / 4 * (yy-1);
460  for (int xx = 1; xx <= 4; xx++)
461  {
462  int x_max = XSIZE(I) / 4 * xx;
463  int x_min = XSIZE(I) / 4 * (xx-1);
464 
465  double mean = 0.0;
466  int count = 0;
467  double var_i = 0.0;
468  double var_o = 0.0;
469 
470  for (int y = y_min; y < y_max; y++)
471  {
472  for (int x = x_min; x < x_max; x++)
473  {
474  mean += DIRECT_A2D_ELEM(I,y,x);
475  count++;
476  }
477  }
478  mean = mean / count;
479 
480  for (int y = y_min; y < y_max; y++)
481  {
482  for (int x = x_min; x < x_max; x++)
483  {
484  if (yy > 1 && yy < 4 && xx > 1 && xx < 4)
485  var_i += (DIRECT_A2D_ELEM(I,y,x) - mean) *
486  (DIRECT_A2D_ELEM(I,y,x) - mean);
487  else
488  var_o += (DIRECT_A2D_ELEM(I,y,x) - mean) *
489  (DIRECT_A2D_ELEM(I,y,x) - mean);
490  }
491  }
492 
493  if (yy > 1 && yy < 4 && xx > 1 && xx < 4)
494  {
495  var_i_sum += var_i / count;
496  fv.push_back(var_i / count);
497  }
498  else
499  {
500  var_o_sum += var_o / count;
501  fv.push_back(var_o / count);
502  }
503  }
504  }
505 
506  fv.push_back((var_i_sum / 4) / (var_o_sum / 12));
507 }
#define YSIZE(v)
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
doublereal * x
#define XSIZE(v)

◆ extractZernike()

void ProgExtractFeatures::extractZernike ( const MultidimArray< double > &  I,
std::vector< double > &  fv 
)

Extracting Zernike moments See method at A. Tahmasbi, F. Saki, S. B. Shokouhi, Classification of Benign and Malignant Masses Based on Zernike Moments, Comput. Biol. Med., vol. 41, no. 8, pp. 726-735, 2011 and also F. Saki, A. Tahmasbi, H. Soltanian-Zadeh, S. B. Shokouhi, Fast opposite weight learning rules with application in breast cancer diagnosis, Comput. Biol. Med., vol. 43, no. 1, pp. 32-41, 2013.

Definition at line 510 of file classify_extract_features.cpp.

512 {
513  MultidimArray<double> R, Theta, Rad;
514  R.resize(I); R.setXmippOrigin();
515  Theta.resize(I); Theta.setXmippOrigin();
516  Rad.resize(I); Rad.setXmippOrigin();
517 
518  double c;
519  int Sy = YSIZE(I);
520  int Sx = XSIZE(I);
521  const std::complex<double> i(0.0, 1.0);
522 
523  for (int y = 0; y < Sy; y++)
524  {
525  int r2 = 2*(y+1)-Sy-1;
526 
527  for (int x = 0; x < Sx; x++)
528  {
529  int r1 = 2*(x+1)-Sy-1;
530  DIRECT_A2D_ELEM(R,y,x) = sqrt(r1*r1 + r2*r2) / Sy;
531  if (DIRECT_A2D_ELEM(R,y,x) > 1) DIRECT_A2D_ELEM(R,y,x) = 0;
532 
533  DIRECT_A2D_ELEM(Theta,y,x) = atan2((Sy+1-2*(y+1)), (2*(x+1)-Sy-1));
534  }
535  }
536 
537  for (int n = 1; n < 5; n++)
538  {
539  for (int m = -n; m < 0; m+=2)
540  {
541  int mn = (n - abs(m)) / 2;
542  int nm = (n + abs(m)) / 2;
543  std::complex<double> product = 0.0;
544 
545  for (int y = 0; y < Sy; y++)
546  {
547  for (int x = 0; x < Sx; x++)
548  {
549  DIRECT_A2D_ELEM(Rad,y,x) = 0;
550  for (int s = 0; s <= mn; s++)
551  {
552  int ns = n - 2*s;
553  c = ((s%2 == 0) ? 1 : -1) *
554  facs(n-s) / (facs(s) *
555  facs(nm-s) *
556  facs(mn-s));
557 
558  DIRECT_A2D_ELEM(Rad,y,x) += c *
559  pow(DIRECT_A2D_ELEM(R,y,x), ns);
560  }
561 
562  product += DIRECT_A2D_ELEM(I,y,x) *
563  DIRECT_A2D_ELEM(Rad,y,x) *
564  exp(-1.0 * i * (double)m *
565  DIRECT_A2D_ELEM(Theta,y,x));
566  }
567  }
568  fv.push_back(std::abs(product));
569  }
570  }
571 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
doublereal * c
void sqrt(Image< double > &op)
static double * y
int facs(int n)
Function for returning factorial up to n=4.
#define DIRECT_A2D_ELEM(v, i, j)
void abs(Image< double > &op)
doublereal * x
#define i
#define XSIZE(v)
int m
float r2
int * n
float r1

◆ facs()

int ProgExtractFeatures::facs ( int  n)

Function for returning factorial up to n=4.

Definition at line 90 of file classify_extract_features.cpp.

91 {
92  return (n == 1 || n == 0) ? 1 :
93  (n == 2) ? 2 :
94  (n == 3) ? 6 : 24;
95 }
int * n

◆ operator=() [1/2]

ProgExtractFeatures& ProgExtractFeatures::operator= ( const ProgExtractFeatures )
delete

◆ operator=() [2/2]

ProgExtractFeatures& ProgExtractFeatures::operator= ( const ProgExtractFeatures &&  )
delete

◆ readParams()

void ProgExtractFeatures::readParams ( )
virtual

Read argument.

Reimplemented from XmippProgram.

Definition at line 40 of file classify_extract_features.cpp.

41 {
42  fnSel = getParam("-i");
43  fnOut = getParam("-o");
44  applyDenoising = checkParam("--applyDenoising");
45  useEntropy = checkParam("--entropy");
46  useGranulo = checkParam("--granulo");
47  useHistDist = checkParam("--histdist");
48  useLBP = checkParam("--lbp");
49  useRamp = checkParam("--ramp");
50  useVariance = checkParam("--variance");
51  useZernike = checkParam("--zernike");
52 }
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)

◆ run()

void ProgExtractFeatures::run ( )
virtual

Main routine.

Reimplemented from XmippProgram.

Definition at line 574 of file classify_extract_features.cpp.

575 {
576  MetaDataVec SF;
577  SF.read(fnSel);
578  Image<double> I, Imasked;
579  FileName fnImg;
580  CorrelationAux aux;
581  std::vector<double> fv;
582 
583  if (verbose>0)
584  init_progress_bar(SF.size());
585  size_t idx=0;
586  for (size_t objId : SF.ids())
587  {
588  SF.getValue(MDL_IMAGE, fnImg, objId);
589  I.read(fnImg);
590  I().setXmippOrigin();
591  centerImageTranslationally(I(), aux);
592 
593  if (applyDenoising)
594  denoiseTVFilter(I(), 200);
595 
596  if (useEntropy)
597  {
598  extractEntropy(I(), Imasked(), fv);
599  SF.setValue(MDL_SCORE_BY_ENTROPY, fv, objId);
600  fv.clear();
601  }
602  if (useGranulo)
603  {
604  extractGranulo(I(), fv);
605  SF.setValue(MDL_SCORE_BY_GRANULO, fv, objId);
606  fv.clear();
607  }
608  if (useHistDist)
609  {
610  extractHistDist(I(), fv);
611  SF.setValue(MDL_SCORE_BY_HISTDIST, fv, objId);
612  fv.clear();
613  }
614  if (useLBP)
615  {
616  extractLBP(I(), fv);
617  SF.setValue(MDL_SCORE_BY_LBP, fv, objId);
618  fv.clear();
619  }
620  if (useRamp)
621  {
622  extractRamp(I(), fv);
623  SF.setValue(MDL_SCORE_BY_RAMP, fv, objId);
624  fv.clear();
625  }
626  if (useVariance)
627  {
628  extractVariance(I(), fv);
629  SF.setValue(MDL_SCORE_BY_VARIANCE, fv, objId);
630  fv.clear();
631  }
632  if (useZernike)
633  {
634  extractZernike(I(), fv);
635  SF.setValue(MDL_SCORE_BY_ZERNIKE, fv, objId);
636  fv.clear();
637  }
638 
639  idx++;
640  if (idx%100==0 && verbose>0)
641  progress_bar(idx);
642  }
643  if (verbose>0) progress_bar(SF.size());
644  if (fnOut == "") fnOut = fnSel;
645  SF.write(fnOut, MD_APPEND);
646 }
void init_progress_bar(long total)
void extractGranulo(const MultidimArray< double > &I, std::vector< double > &fv)
Extracting granulometry features.
Feature vectors used to classify particles (vector double)
< Micrographs Gini Coeff. (double)
void denoiseTVFilter(MultidimArray< double > &xnew, int maxIter)
Definition: filters.cpp:4129
void extractEntropy(const MultidimArray< double > &I, MultidimArray< double > &Imasked, std::vector< double > &fv)
Extracting entropy features.
void centerImageTranslationally(MultidimArray< double > &I, CorrelationAux &aux)
Definition: filters.cpp:3212
void extractHistDist(const MultidimArray< double > &I, std::vector< double > &fv)
Extracting histogram distances.
Feature vectors used to classify particles (vector double)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
Feature vectors used to classify particles (vector double)
Feature vectors used to classify particles (vector double)
void extractRamp(const MultidimArray< double > &I, std::vector< double > &fv)
Gray ramp coefficients.
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
virtual IdIteratorProxy< false > ids()
size_t size() const override
bool setValue(const MDObject &mdValueIn, size_t id)
void progress_bar(long rlen)
int verbose
Verbosity level.
bool getValue(MDObject &mdValueOut, size_t id) const override
Feature vectors used to classify particles (vector double)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void extractVariance(const MultidimArray< double > &I, std::vector< double > &fv)
Extracting variance features.
void extractZernike(const MultidimArray< double > &I, std::vector< double > &fv)
void extractLBP(const MultidimArray< double > &I, std::vector< double > &fv)
Name of an image (std::string)
Feature vectors used to classify particles (vector double)

◆ show()

void ProgExtractFeatures::show ( )

Show.

Definition at line 55 of file classify_extract_features.cpp.

56 {
57  if (verbose==0)
58  return;
59  std::cerr
60  << "Input selfile: " << fnSel << std::endl
61  << "Output selfile: " << fnOut << std::endl
62  << "Turn on denoising: " << applyDenoising << std::endl
63  << "Extract entropy features: " << useEntropy << std::endl
64  << "Extract granulo features: " << useGranulo << std::endl
65  << "Extract histog. distances: " << useHistDist << std::endl
66  << "Extract LBP features: " << useLBP << std::endl
67  << "Extract ramp coefficients: " << useRamp << std::endl
68  << "Extract variance features: " << useVariance << std::endl
69  << "Extract Zernike moments: " << useZernike << std::endl
70  ;
71 }
int verbose
Verbosity level.

Member Data Documentation

◆ applyDenoising

bool ProgExtractFeatures::applyDenoising

Parameter for turning on denoising

Definition at line 47 of file classify_extract_features.h.

◆ fitPoints

FitPoint* ProgExtractFeatures::fitPoints =nullptr

Definition at line 130 of file classify_extract_features.h.

◆ fnOut

FileName ProgExtractFeatures::fnOut

Filename output root

Definition at line 44 of file classify_extract_features.h.

◆ fnSel

FileName ProgExtractFeatures::fnSel

Filename selection file containing the images

Definition at line 41 of file classify_extract_features.h.

◆ masks

MultidimArray<int> ProgExtractFeatures::masks[7]

Masks for entropy features

Definition at line 127 of file classify_extract_features.h.

◆ NmaskPoints

int ProgExtractFeatures::NmaskPoints

Definition at line 131 of file classify_extract_features.h.

◆ rampMask

MultidimArray<int> ProgExtractFeatures::rampMask

Definition at line 129 of file classify_extract_features.h.

◆ useEntropy

bool ProgExtractFeatures::useEntropy

Parameter for using entropy features

Definition at line 50 of file classify_extract_features.h.

◆ useGranulo

bool ProgExtractFeatures::useGranulo

Parameter for using granulometry-based features

Definition at line 53 of file classify_extract_features.h.

◆ useHistDist

bool ProgExtractFeatures::useHistDist

Parameter for using histogram distances features

Definition at line 56 of file classify_extract_features.h.

◆ useLBP

bool ProgExtractFeatures::useLBP

Parameter for using LBP

Definition at line 59 of file classify_extract_features.h.

◆ useRamp

bool ProgExtractFeatures::useRamp

Parameter for ramp

Definition at line 62 of file classify_extract_features.h.

◆ useVariance

bool ProgExtractFeatures::useVariance

Parameter for using variance features

Definition at line 65 of file classify_extract_features.h.

◆ useZernike

bool ProgExtractFeatures::useZernike

Parameter for using Zernike moments

Definition at line 68 of file classify_extract_features.h.


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