Skip to content

Instantly share code, notes, and snippets.

@rajithv
Created June 19, 2015 04:38
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/6d8ff7cbe561fb632aeb to your computer and use it in GitHub Desktop.
Save rajithv/6d8ff7cbe561fb632aeb to your computer and use it in GitHub Desktop.
vector<int> calculateIntegrals(Mat &gray, int _case){
// Calculating integral projections
vector<int> integral;
// _case 1 : Horizontal Differentiation : Vertical Integration
if(_case == 1){
integral.clear();
for (int i = 0; i < gray.cols; i++) {
int temp_sum = 0;
for (int j = 0; j < gray.rows; j++) {
temp_sum += (int)gray.at<uchar>(j, i);
}
integral.push_back(temp_sum);
}
}
// _case 2 : Vertical Differentiation : Horizontal Integration
else if(_case == 2){
integral.clear();
for (int i = 0; i < gray.rows; i++) {
int temp_sum = 0;
for (int j = 0; j < gray.cols; j++) {
temp_sum += (int)gray.at<uchar>(i, j);
}
integral.push_back(temp_sum);
}
}
// _case 3 : Differentiation along -ve Diagonal : Integration along +ve Diagonal
else if(_case == 3){
integral.clear();
for (int i=0; i < gray.rows; i++){
int j = 0;
int temp_sum = 0;
for(int k=0; i-k > 0 && j+k < gray.cols; k++){
temp_sum += (int)gray.at<uchar>(i-k, j+k);
}
integral.push_back(temp_sum);
}
for (int j=1; j < gray.cols; j++){
int i = gray.rows-1;
int temp_sum = 0;
for(int k=0; i-k > 0 && j+k < gray.cols; k++){
temp_sum += (int)gray.at<uchar>(i-k, j+k);
}
integral.push_back(temp_sum);
}
}
// _case 4 : Differentiation along +ve Diagonal : Integration along -ve Diagonal
else if(_case == 4){
integral.clear();
for (int i=0; i < gray.rows; i++){
int j = 0;
int temp_sum = 0;
for(int k=0; i+k < gray.rows && j+k < gray.cols; k++){
temp_sum += (int)gray.at<uchar>(i+k, j+k);
}
integral.push_back(temp_sum);
}
for (int j=1; j < gray.cols; j++){
int i = 0;
int temp_sum = 0;
for(int k=0; i+k < gray.rows && j+k < gray.cols; k++){
temp_sum += (int)gray.at<uchar>(i+k, j+k);
}
integral.push_back(temp_sum);
}
}
return integral;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment