# fingerprint orientation map through gradient method - opencv c++ I am trying to develop a fingerprint system using OpenCV 2.4.3 and C++ in Visual Studio 2010. I need to form the orientation map of the input fingerprint in order to use it in Gabor filters. I have computed the gradient x and y values using Sobel filters. But I don't how to form a orientation map from this. Can anyone help me with the steps to do so. Thanks in advance.

edit retag close merge delete

Sort by » oldest newest most voted

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
float valueX = gradientX.at<float>(i,j);
float valueY = gradientY.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;
}
}

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!

As suggested, these angles can be used to create arrows that point in the angle direction and take the absolute vector size when combining both gradients as length. An example result of those orientation map on a microscopic organism can be seen below, which is done by using matlab, but i get similar images in OpenCV, just havent created one lately. more

I asked a question yesterday and I think we are looking for the same thing.. From this question I made the two mat containers of gradients and applied this function on it, but I dont really understand how these thins work :S Should I display the result ? When I try it, i get some errors...

Ok first of all, you should basically understand what a gradient orientation is. It means the direction in which the gradient in that pixel is. Using basic giometry, one knows that the arctangens (inverse tangens) can be used to calculate the angle in which the combined gradient of X and Y points.

Link to geometry : http://bit.ly/YCuaoL

Also, when visualizing this, just think about what a gradient actually is. It can be displayed with an arrow, that has the pixel as starting point, and which points in the direction of the angle searched (orientation here) and as size, the actual length of the combined vector, which is algebra again.

Be aware that when you display this, you display the arrows for lets say, every 5 pixels, else your screen will be filled with arrows and show as a block.

What must be the types of the input gradient containers in your function? If I use CV_8U what is returned from Sobel function it gives me errors. When I converted it to 32F it gives me the same result for each pixel about 44 (degrees if I understand good? )

Thanks for your kind reply StevenPuttemans. As per your suggestion should i apply to a 5x5 block or to every 5 pixels in the image? and can i use the input fingerprint image rather than orientation matrix from your example to get the arrows along the ridges of the fingerprint.

1

@Milanista : Input gradient containers are of type CV_32F since this is expected by the algorithms I process later on those data. About the actual same degrees for each point ,that is not possible if your gradient elements are not constant for the complete image. Can you link me to an example input image?

@ssvenkatesh6666 : my code only generates the angle of the orientation for each pixel of your gradient image. You still have to do postprocessing to get the actual arrow displayed as i said. Indeed use 5x5 pixel blocks, for displaying, meaning you take stepsize of 5 pixels in each dimension, each time you visualize an element.

thanks for the help!, I will try this and will return to you for further guidance :)

For getting the gradients I used this tutorial: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html After it I converted "abs_grad_x" like this: abs_grad_x.convertTo(abs2_grad_x, CV_32F, 1./255); I used "abs2_grad_x" (and y) in your function.

getting gradients is pretty simple, just use the sobel functionality, and define the x or y direction in which you want to calculate the result. It is also good to first process your image by applying some gaussian blur and converting it to a grayscale input. Link : http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=sobel#cv.Sobel

Thank you @StevenPuttemans. I think I'm in the finish line, just something misses. I got this picture, but it doesnt seem very good: http://imageshack.us/photo/my-images/22/orientl.jpg/ I made it this way: 1. I applied Gaussian filter on it : GaussianBlur( src, src, Size(15,15), 0, 0, BORDER_DEFAULT ); 2. I computed gradient for x and y like this : Sobel( src_gray, grad_x, ddepth, 1, 0, 3, scale, delta, BORDER_DEFAULT ); 3. converted it to CV_64F 4. I computed the average of grad in 3030 blocks (I have bigger picture about 12001100) 5. I found this function for getting angle and magnitude : cv::cartToPolar 6. I averaged the angle and magnitude in blocks

Hi, i'm a student in master degree and i work on fingerprint recognition using opencv c++ with ms vc++. i read your post and i'm interest on your code. please help me My email [email protected] Thanks in advance

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2013-03-17 22:37:38 -0500

Seen: 6,517 times

Last updated: Mar 19 '13