title: How to speed up Frangi filtering in opencv (c++)
body: <p>I have this image:</p>
  
  <p><a href="https://i.stack.imgur.com/BdIoW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BdIoW.png" alt="enter image description here"></a></p>
  
  <p>I want to detect anomalies on this image by using Frangi filter. Code for it i got here: <a href="https://github.com/ntnu-bioopt/libfrangi/blob/master/README.md" rel="nofollow noreferrer">Frangi filter</a>. I use this parameters for frangi filter:</p>
  
  <pre><code>  // Manualy edited parameters of frangi filter.
  #define DEFAULT_SIGMA_START 1
  #define DEFAULT_SIGMA_END 3
  #define DEFAULT_SIGMA_STEP 1
  #define DEFAULT_BETA_ONE 1.6
  #define DEFAULT_BETA_TWO 1.2
  #define DEFAULT_BLACKWHITE true
  </code></pre>
  
  <p>Anomaly detection works very ok. The problem is speed of calculation. The time for filtering is: 7 seconds. What can be possible solutions for speeding up while mainaining good detection with Frangi Filter?</p>
  
  <p>EDIT 1: The code where the most time is spend is for loop inside of a frangi2d algorithm:</p>
  
  <pre><code>for (float sigma = opts.sigma_start; sigma &lt;= opts.sigma_end; sigma += opts.sigma_step) {
          //create 2D hessians
          Mat Dxx, Dyy, Dxy;
          frangi2d_hessian(src, Dxx, Dxy, Dyy, sigma);
  
          //correct for scale
          Dxx = Dxx*sigma*sigma;
          Dyy = Dyy*sigma*sigma;
          Dxy = Dxy*sigma*sigma;
  
          //calculate (abs sorted) eigenvalues and vectors
          Mat lambda1, lambda2, Ix, Iy;
          frangi2_eig2image(Dxx, Dxy, Dyy, lambda1, lambda2, Ix, Iy);
  
          //compute direction of the minor eigenvector
          Mat angles;
          phase(Ix, Iy, angles);
          ALLangles.push_back(angles);
  
          //compute some similarity measures
          lambda2.setTo(nextafterf(0, 1), lambda2 == 0);
          Mat Rb = lambda1.mul(1.0 / lambda2);
          Rb = Rb.mul(Rb);
          Mat S2 = lambda1.mul(lambda1) + lambda2.mul(lambda2);
  
          //compute output image
          Mat tmp1, tmp2;
          exp(-Rb / beta, tmp1);
          exp(-S2 / c, tmp2);
  
          Mat Ifiltered = tmp1.mul(Mat::ones(src.rows, src.cols, src.type()) - tmp2);
          if (opts.BlackWhite) {
              Ifiltered.setTo(0, lambda2 &lt; 0);
          }
          else {
              Ifiltered.setTo(0, lambda2 &gt; 0);
          }
  
          //store results
          ALLfiltered.push_back(Ifiltered);
  
          cout &lt;&lt; "Interation done" &lt;&lt; endl;
      }
  </code></pre>