Created
June 19, 2015 04:35
-
-
Save rajithv/dd577bb3135eca429f1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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