# Weird map orientation using sobel gradients

And i used a block size of 5x5 on my 480x320 image. The gradients i got was from 0-270 degrees. And there are constant values that keep on repeating like 44.7623 and 224.762. I wonder if my gradients are wrong.

After that, i add all the gradients in the 5x5 block and divide them by 25 (averaging) like what the link said. I divided the degrees into 8 sections of 45degree intervals and plotted them out. But it looks nothing like my original image. Can anyone tell me what's wrong? I just want to detect the core(circle-like) feature of the image.

My original image is this _________________________________________________ But my orientation map is this:  This is what I'm doing What's wrong ? =(

I got the gradients from this method :

/// Gradient X
cv::Sobel(original_Mat, grad_x, CV_32FC1, 1, 0, 3);

cv::Sobel(original_Mat, grad_y, CV_32FC1, 0, 1, 3);

for(int i = 0; i < grad_x.rows; i++){
for(int j = 0; j < grad_x.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;

}
}


Here's the full code.

 int main()
{

cv::Sobel(original_Mat, grad_x, CV_32FC1, 1, 0, 3);

cv::Sobel(original_Mat, grad_y, CV_32FC1, 0, 1, 3);

img = cv::Scalar(255,255,255);//all white

// Calculate orientations of gradients --> in degrees
// Loop over all matrix values and calculate the accompanied orientation

for(int i = 0; i < grad_x.rows; i++){
for(int j = 0; j < grad_x.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;

}
}

int i=0,j=0;
int x1=0,x2=0;
float results;

for(int l=0;l<96;l++) //to loop all the rows
{
int x1=(5+(l*5)); // to get 5x5 block sizes

for(int k=0;k<64;k++)//to loop all the columns
{

int x2=(5+(k*5)); // to get 5x5 block sizes
results=0;

//to get the total of 5x5 gradient values
for(i=(x1-5); i < x1; i++){
for(j=(x2-5); j ...
edit retag close merge delete