# Weird map orientation using sobel gradients

I tried to follow this method of drawing orientation map http://answers.opencv.org/question/9493/fingerprint-orientation-map-through-gradient/

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);

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

Mat orientation = Mat(grad_x.rows, grad_y.cols, CV_32F);

for(int i = 0; i < grad_x.rows; i++){
for(int j = 0; j < grad_x.cols; j++){
// Retrieve a single value
float valueX = grad_x.at<float>(i,j);
float valueY = grad_x.at<float>(i,j);
// 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::Mat original_Mat=cv::imread("Source.bmp", 1);

cv::Mat grad = cv::Mat::zeros(original_Mat.size(),CV_64F);

/// Generate grad_x and grad_y
cv::Mat grad_x = cv::Mat::zeros(original_Mat.size(), CV_64F);
cv::Mat grad_y = cv::Mat::zeros(original_Mat.size(), CV_64F);
cv::Mat grad_angle = cv::Mat::zeros(original_Mat.size(), CV_64F);

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

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

Mat orientation = Mat(grad_x.rows, grad_y.cols, CV_32F); //to store the gradients
Mat img=Mat(grad_x.rows, grad_y.cols, CV_32F);//to draw out the map
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
float valueX = grad_x.at<float>(i,j);
float valueY = grad_x.at<float>(i,j);
// 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