#include
#include
#include
#include
#include
#include
#include
using namespace std;
Using the namespace CV;
Void marrEdge (const Mat SRC, Mat result, int kerValue, double delta)
{
//calculate the LOG operator
Mat kernel;
//radius
Int kerLen=kerValue/2;
The kernel=Mat_ & lt; Double> (kerValue kerValue);
//sliding window
For (int I=- kerLen; I & lt;=kerLen; I++)
{
For (int j=- kerLen; J & lt;=kerLen; J++)
{
//generated nuclear factor
The kernel. At
Exp (- ((j, 2) + (pow pow (I, 2))/(delta, 2) * 2) (pow) * (((j, 2) + (pow pow (I, 2) - 2 * pow (delta, 2))/(2 * pow (delta, 4)))));
}
}
//set the output parameters
Int kerOffset=kerValue/2;
Mat Laplacian=(Mat_ & lt; Double> (SRC. Rows - kerOffset * 2, SRC, cols - kerOffset * 2));
Result=Mat: : zeros (SRC. Rows - kerOffset * 2, SRC cols - kerOffset * 2, SRC. The type ());
Double sumLaplacian;
//traversal calculation of Laplacian convolution image
For (int I=kerOffset; I & lt; The SRC. Rows - kerOffset; + + I)
{
For (int j=kerOffset; J
SumLaplacian=0;
For (int k=- kerOffset; k <=kerOffset; + + k)
{
For (int m=- kerOffset; M & lt;=kerOffset; + + m)
{
//based on convolution image
SumLaplacian +=SRC. At
}
}
Laplacian. Ats & lt; Double & gt; (I - kerOffset, j - kerOffset)=sumLaplacian;
}
}
//zero cross should be in accordance with the edge pixels
For (int y=1; Y & lt; Result. The rows 1; + + y)
{
For (int x=1; X & lt; Result. The cols; + + x)
{
Result. At
//neighborhood judging
If (Laplacian. At
Result. At
If (Laplacian. At
Result. At
If (Laplacian. At
Result. At
If (Laplacian. At
Result. At
}
}
}
Int main ()
{
Mat srcImage=imread (" 1. JPG ");
if (! SrcImage. Data)
return -1;
Mat srcGray (srcImage. The size (), srcImage. The type ());
CvtColor (srcImage srcGray, CV_BGR2GRAY);
Mat edge;
MarrEdge (srcGray, edge, 9, 1.6);
Imshow (" SRC ", srcImage);
Imshow (" edge ", edge);
WaitKey (0);
return 0;
}