# 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.

// 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!

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...

( 2013-03-18 12:00:55 -0600 )edit

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.

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.

( 2013-03-18 12:56:20 -0600 )edit

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

( 2013-03-19 06:00:43 -0600 )edit

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.

( 2013-03-19 07:54:11 -0600 )edit
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.

( 2013-03-19 08:30:44 -0600 )edit

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

( 2013-03-19 09:24:14 -0600 )edit

( 2013-03-19 11:21:01 -0600 )edit

Hello @ssvenkatesh6666. How did you get the gradients?

( 2013-03-25 05:49:54 -0600 )edit

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

( 2013-03-25 08:05:11 -0600 )edit

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

( 2013-03-27 12:13:25 -0600 )edit

7 Computed the destination points of vectors: destination pointx = Sourcepointx + magnitude * cos(angle) destination pointy = Sourcepointy + magnitude * sin(angle) 8 drew lines: cv::line(src, point1, point2, cv::Scalar(0,0,200), 2, CV_AA);
So, am I doing it good?:)

( 2013-03-27 12:14:33 -0600 )edit

First of all, what you are receiving from cartToPolar is not correct. This is NOT the angle that you want but the angle of the polar coordinate system. This will yield wrong results. For the rest you are doing well, so what you mean with getting misses?

( 2013-03-27 13:35:15 -0600 )edit

So what should I do now?

( 2013-03-27 14:28:44 -0600 )edit

First use the arctangens function, as already explained ... than improve your algorithm / parameters until the result satisfies you.

( 2013-03-27 15:21:57 -0600 )edit

Are you sure it isnt the same? In documentation I found this: float fastAtan2(float y, float x) - Calculates the angle of a 2D vector in degrees void cartToPolar - Calculates the magnitude and angle of 2d vectors. And if I use your function how could I compute the magnitude of vectors? I got only a point and an angle.

( 2013-03-28 12:21:53 -0600 )edit

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