Ask Your Question

Parallelize chain of blurs

asked 2017-04-01 19:15:37 -0500

lovaj gravatar image

I have this code (revisited version of this):

void HessianDetector::detectOctaveKeypoints(const Mat &firstLevel, ...)
   vector<Mat> blurs (par.numberOfScales+3, Mat());
   blurs[1] = firstLevel;
   for (int i = 1; i < par.numberOfScales+2; i++){
       float sigma = par.sigmas[i]* sqrt(sigmaStep * sigmaStep - 1.0f);
       blurs[i+1] = gaussianBlur(blurs[i], sigma);


Mat gaussianBlur(const Mat input, const float sigma)
   Mat ret(input.rows, input.cols, input.type());
   int size = (int)(2.0 * 3.0 * sigma + 1.0); if (size % 2 == 0) size++;      
   GaussianBlur(input, ret, Size(size, size), sigma, sigma, BORDER_REPLICATE);
   return ret;

So, as you can see, each blurs[i+1] depends on blurs[i], so it cannot be parallelized. My question is: is there an equivalent way to obtain the same result but using firstLevel instead of blurs[i]? So it should so look something like:

for (int i = 1; i < par.numberOfScales+2; i++){
  float sigma = //something;
  blurs[i+1] = gaussianBlur(firstLevel, sigma);

Is it possible?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2017-04-01 23:52:51 -0500

Tetragramm gravatar image

From the wikipedia page on Gaussian blur.

Applying multiple, successive gaussian blurs to an image has the same effect as applying a single, larger gaussian blur, whose radius is the square root of the sum of the squares of the blur radii that were actually applied. For example, applying successive gaussian blurs with radii of 6 and 8 gives the same results as applying a single gaussian blur of radius 10, since sqrt {6^{2}+8^{2}}=10. Because of this relationship, processing time cannot be saved by simulating a gaussian blur with successive, smaller blurs — the time required will be at least as great as performing the single large blur.

edit flag offensive delete link more


@Tetragramm Thanks for your answer! Since (as you can see) I'm not expert with gaussian blurs, the radius is sigma in the opencv function, right?

lovaj gravatar imagelovaj ( 2017-04-02 04:19:00 -0500 )edit

Ah, yes, sorry. So sigma blur1 then blur2 = sqrt(sigma1^2+sigma2^2)

Tetragramm gravatar imageTetragramm ( 2017-04-02 08:35:59 -0500 )edit

@Tegragramm could please give a look at this question?

lovaj gravatar imagelovaj ( 2017-04-14 08:41:03 -0500 )edit

Question Tools

1 follower


Asked: 2017-04-01 19:15:37 -0500

Seen: 90 times

Last updated: Apr 01 '17