Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.