# Revision history [back]

The following code is some sample code from a project I am doing in C++. It uses as input two gradient containers to define the orientation of the gradient for each point.

Mat calculateOrientations(Mat gradientX, Mat gradientY){
// Create container element

// Calculate orientations of gradients --> in degrees
// Loop over all matrix values and calculate the accompagnied orientation
for(int i = 0; i < gradientX.rows; i++){
for(int j = 0; j < gradientX.cols; j++){
// Retrieve a single value
// Calculate the corresponding single direction, done by applying the arctangens function
float result = fastAtan2(valueX,valueY);
// Store in orientation matrix element
orientation.at<float>(i,j) = result;
}
}

return orientation;
}


Using this information, you can decide to calculate the average orientation for like a bin of 5x5 pixels easily. Hope this helps you out!

The following code is some sample code from a project I am doing in C++. It uses as input two gradient containers to define the orientation of the gradient for each point.

Mat calculateOrientations(Mat gradientX, Mat gradientY){
// Create container element

// Calculate orientations of gradients --> in degrees
// Loop over all matrix values and calculate the accompagnied orientation
for(int i = 0; i < gradientX.rows; i++){
for(int j = 0; j < gradientX.cols; j++){
// Retrieve a single value
// Calculate the corresponding single direction, done by applying the arctangens function
float result = fastAtan2(valueX,valueY);
// Store in orientation matrix element
orientation.at<float>(i,j) = result;
}
}

return orientation;
}


Using this information, you can decide to calculate the average orientation for like a bin of 5x5 pixels easily. Hope this helps you out!