Search code examples
opencvcomputer-visiongimp

Implementation of 'Difference of Gaussians' in OpenCV


For a Project I am trying to extract pretty dim contours from an Image. While playing around with GIMP I found a way to extract and threshold those contours beautifully using "Difference of Gaussians" with radius1=1 and radius2=25 (or even greater). However when trying to reimplement this workflow in OpenCV my results are not as good as with GIMP (dimmer, less crisp): Difference in DoG Implementation OpenCV vs. GIMP

I have skimmed through GIMPs Sourcecode and found that in the newest Version (which I am using) there are two implementations of DoG. I used the non-legacy one, which is based on GEGL, Sourcecode can be found here.

My implementation as per here:

{
  Mat g1, g2, result;
  GaussianBlur(input, g1, Size(0, 0), gaussian1, gaussian1);
  GaussianBlur(input, g2, Size(0, 0), gaussian2, gaussian2);
  cv::subtract(g1, g2, result);
  return result;
}

So as you can see, my implementation and the GEGL one are superficially identical, however the results are vastly different. I already tried playing around with cv::equalizeHist()to enhance the contrast of my result, but this also did not yield anything usable.

I would gladly appreciate any ideas on what is going on here. Thanks!


Solution

  • I found a way to (partially) achieve what I wanted, thanks to a Pointer by @xenoid.

    What I did now is take the Codesnippet from above and simply multiply the Mat result by a factor. Full Codesnippet:

    
    cv::Mat differenceOfGaussians(cv::Mat input, int gaussian1, int gaussian2)
    {
      Mat g1, g2, result;
      GaussianBlur(input, g1, Size(0, 0), gaussian1, gaussian1);
      GaussianBlur(input, g2, Size(0, 0), gaussian2, gaussian2);
      cv::subtract(g1, g2, result);
      result = result * gammaInt;
      return result;
    }
    

    gammaInt being a global int variable controlled via slider. The result (for a better image with some Contrastamplification done by the camera itself) can be found here: DoG with linear amplification