Skip to content

Instantly share code, notes, and snippets.

@Seanmatthews
Created October 30, 2016 22:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seanmatthews/704eec1b62c49271f1e84c8d5e4bf1e8 to your computer and use it in GitHub Desktop.
Save Seanmatthews/704eec1b62c49271f1e84c8d5e4bf1e8 to your computer and use it in GitHub Desktop.
cv::Mat createLOGKernel1D(int ksize, float sigma)
{
using namespace cv;
float std2 = sigma * sigma;
std::vector<float> seq(ksize);
std::iota(begin(seq), end(seq), -(ksize-1)/2);
Mat_<float> kSeq(1, ksize, seq.data());
Mat XX;
multiply(kSeq, kSeq, XX);
Mat H = -(XX / (2.*std2));
exp(H, H);
double minVal, maxVal;
minMaxIdx(H, &minVal, &maxVal);
Mat mask = H < std::numeric_limits<float>::epsilon()*maxVal;
H.setTo(0, mask);
float sumh = sum(H)[0];
if (sumh != 0) H /= sumh;
Mat H1;
multiply(H, (XX - 2.*std2)/(std2 * std2), H1);
H = H1 - sum(H1)[0] / ksize;
return H;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment