Ask Your Question

opencv_newbie90's profile - activity

2014-04-09 00:39:32 -0600 asked a question 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 ...
(more)
2014-04-08 05:04:31 -0600 asked a question What is gradient from Sobel operator mean?

I have the gradients from the Sobel operator for each pixel. In my case 320x480. But how can I relate them with the orientation? For an example, I'm planning to draw an orientation map for fingerprints. So, how do I start?

Is it by dividing the gradients into blocks (example 16x24) then adding the gradients together and diving it by 384 to get the average gradients? Then from there draw a line from the center of the block using the average gradient?

Correct me if i'm wrong. Thank you.

2014-03-29 09:23:29 -0600 received badge  Editor (source)
2014-03-29 09:21:50 -0600 asked a question Orientation map+ sobel+histogram

Hi, I'm trying to get a edge orientation map to detect the "core" feature of a fingerprint. Now I'm stuck in creating the orientation map. I'm using sobel and trying to create a map for it. Can someone enlighten me on what's wrong with this code? It "stopped working". Btw I can detect terminations & bifurcations for fingerprints but I can't match them due to variation in areas n rotation. Any method I can solve this apart from using orientation map to detect the core feature and linking it from there? Thanks

void orientation_map()
{

IplImage* grayimg=cvLoadImage("combined_blur.bmp");

IplImage* dst=cvCreateImage(cvGetSize(grayimg),IPL_DEPTH_8U,1); 
IplImage*df_dx = cvCreateImage(cvGetSize(grayimg),IPL_DEPTH_8U,1); 

IplImage*df_dy = cvCreateImage(cvGetSize(grayimg),IPL_DEPTH_8U,1); 
IplImage*dydx = cvCreateImage(cvGetSize(grayimg),IPL_DEPTH_8U,1);
cvSobel(grayimg, df_dx, 1, 0, 3) ;
cvSobel(grayimg, df_dy, 0, 1, 3) ;

float x,y,ori;

for(int i=0;i=grayimg->height;i++)
{
for(int j=0;grayimg->width;j++)
{

     x = (df_dx->imageData+i*df_dx->widthStep)[j]; 
 y = (df_dy->imageData+i*df_dy->widthStep)[j]; 
 ori = atan2(y,x);  
(dst->imageData+i*dst->widthStep)[j]= ori; 
}
}


float rng[] = { -CV_PI, CV_PI }; 
float *ranges = {rng}; 
CvHistogram*hist = cvCreateHist( 1, 0, CV_HIST_ARRAY, &ranges, 1 ); 
cvCalcHist( &dst, hist, 0, 0 ); 

cvSaveImage( "histogram.bmp", dst );




return;
}