Skip to content

Instantly share code, notes, and snippets.

@rajithv
Created June 19, 2015 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajithv/dd577bb3135eca429f1f to your computer and use it in GitHub Desktop.
Save rajithv/dd577bb3135eca429f1f to your computer and use it in GitHub Desktop.
Mat applyFilter(Mat &gray_1, Mat &kernal){
Point anchor = Point (-1,1);
double delta = 0;
int ddepth = -1;
Mat temp; // temporarily store the image
Mat gray; // final grayscale image after differentiation
// Apply the differential filter
filter2D(gray_1, temp, ddepth, kernal, anchor, delta, BORDER_DEFAULT);
// Raise to the square
pow(temp, 2, gray);
return gray;
}
vector<Mat> applyFilter(Mat &color){
Mat temp;
Mat gray;
vector<Mat> result;
// Convert the picture into Grayscale
cvtColor (color, gray, CV_RGB2GRAY);
// Kernal for horizontal differentiation
Mat hor_kernal = (Mat_<double>(3,3) << 1, 0, -1, 2, 0, -2, 1, 0, -1);
result.push_back(applyFilter(gray, hor_kernal));
// Kernal for vertical differentiaiton
Mat ver_kernal = (Mat_<double>(3,3) << 1, 2, 1, 0, 0, 0, -1, -2, -1);
result.push_back(applyFilter(gray, ver_kernal));
// Kernal for differentiation along the negative diagonal
Mat dia_kernal = (Mat_<double>(3,3) << 2, 1, 0, 1, 0, -1, 0, -1, -2);
result.push_back(applyFilter(gray, dia_kernal));
// Kernal for differentation along the positive diagonal
Mat dia2_kernal = (Mat_<double>(3,3) << 0, 1, 2, -1, 0, 1, -2, -1, 0);
result.push_back(applyFilter(gray, dia2_kernal));
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment