LogGabor function problem

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

52 Replies - 1341 Views - Last Post: 29 July 2013 - 02:19 AM Rate Topic: -----

#1 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

LogGabor function problem

Posted 03 July 2013 - 05:26 AM

Hi, I have no compiling error in my work , but running it stops entering in logGabor function. When I enter I see in the debugging(Eclipse) Segmentation fault.
The function:
Mat logGabor(matriz filter,Mat filter,double r_o,double theta_o,double sigma_theta, matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize){

Mat rpad;
int k=*padSize;

printf("Welcome to the function"); //Here the error about seg fault
...


In main I have:
Mat chrRpad[4][5]; //chrOrient=4;chrScales=5
 for(int i_or=1;i_or<chrOrient;i_or++){
  for(int i_sc=1;i_sc<chrScales;i_sc++){
   //some math calculation
   chrRpad[i_or-1][i_sc-1]=abs(logGabor(filter,imftt2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize));
  }
 }


This part I try to use a vector of Mat too and not using the Mat chrRpad [][] and after using as:
vec.push_back(abs(logGabor(......));

The matriz type:
typedef double** matriz;
//main
matriz filter,radius,theta;
filter=createmat(rows,cols);
//function to allocate
double **createmat(int rows,int cols){

    double **m;

    m=new double*[rows];
     for(int i=0;i<rows;i++)
         m[i]=new double[cols];

    return m;
}



Is This A Good Question/Topic? 0
  • +

Replies To: LogGabor function problem

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 03 July 2013 - 07:30 AM

You need to provide the smallest possible complete program that illustrates your problem. One that we can compile to see the problem ourselves. The snippets you have provided don't show nearly enough.


Jim
Was This Post Helpful? 0
  • +
  • -

#3 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 03 July 2013 - 09:46 AM

#include <stdio.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <vector>

using namespace cv;
using namespace std;

typedef double** matriz;

#define PI 3.14159265

struct ts{
   Mat data;
}tiese[4];

Mat colorDecorrelation(Mat img,int numColComp);
Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c);
int roundIt(double num);
void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows);
Mat logGabor(matriz filter,Mat imfft,double r_o, double theta_o,double sigma_theta,matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize);
Mat whitening_sqr_meanDistance(Mat X);
void ftshifting(matriz filter,int rows,int cols);
double **createmat(int rows,int cols);

int main(){

 double achrScales,achrOrient,achrLambda_min,achrScFactor,achrDeltaAng,achrBwF,achrLambda_max,chrScales,chrOrient,chrLambda_min,chrScFactor,chrDeltaAng,chrBwF,chrLambda_max,sigma_r,wavelengths,sigma_theta,sigma,r_o,theta_o;
 int nChannels,numColComp,*padSize,rows,cols,maxhw,*sz2filt_r,*sz2filt_c;
 Mat img = imread("/home/elvio/workspace/aws/src/andaina.JPG");
 Mat rgbDecorrImg,imfft,imfft2,imgDecorr,conspic1,conspic,conspic2,Tsquared,inCompImg,Salmap,SumSalmap,maxT,GaussKernel;
 Mat achrRpad[4][7],chrRpad[4][5];
 vector<Mat>stack;

 if(img.empty()){
     printf("The image is empty \n");
     return -1;
 }

 namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
 imshow("Image Display", img);
 waitKey(0);
 destroyWindow("Image Display");

 padSize=(int*)malloc(sizeof(int));
 sz2filt_r=(int*)malloc(sizeof(int));
 sz2filt_c=(int*)malloc(sizeof(int));

 rows=img.rows;
 cols= img.cols;
 nChannels= img.channels();
 numColComp = nChannels ;

 inCompImg = img.reshape(numColComp,rows*cols);

 imgDecorr = colorDecorrelation(inCompImg,numColComp);

 rows=imgDecorr.rows;
 cols=imgDecorr.cols;
 nChannels= imgDecorr.channels();

 imgDecorr.convertTo(rgbDecorrImg,CV_8UC3);
 rgbDecorrImg = rgbDecorrImg.reshape(numColComp,img.rows);

  chrScales=5;
  chrOrient=4;
  chrLambda_min=6;
  chrScFactor=2;
  chrDeltaAng = 1.7;
  chrBwF=1.1;
  chrLambda_max= (chrLambda_min) * (pow(chrScFactor,chrScales-1));


     conspic2 = Mat::zeros(img.rows,img.cols,CV_8UC3);

     for(int i_c_comp=2;i_c_comp<numColComp;i_c_comp++){


        imfft=FourierTrasform2D(rgbDecorrImg,chrLambda_max,imfft,padSize,sz2filt_r,sz2filt_c);
        rows=*sz2filt_r;
        cols=*sz2filt_c;

        imfft.convertTo(imfft2,CV_8UC3);
        imfft2= imfft2.reshape(numColComp,rows);

       matriz radius,theta,filter;
       radius = createmat(rows,cols);
       theta = createmat(rows,cols);
       filter = createmat(rows,cols);

        printf("Before prefilter\n");
        pre_filter_Computations(radius,theta,cols,rows);
        printf("Exit prefilter\n");

         sigma_r = exp(-(pow(2,chrBwF) -1)/(pow(2,chrBwF) + 1));
         sigma_theta = (PI/chrOrient)/chrDeltaAng;

       for(int i_orient=1;i_orient<=chrOrient;i_orient++){
          for(int i_scale=1;i_scale<=chrScales;i_scale++){
             Mat prova;
             wavelengths = chrLambda_min * (pow(chrScFactor,i_scale -1));
             r_o = 2/wavelengths;
             theta_o = (i_orient-1)*(PI/chrOrient);
             //stack.push_back(abs(logGabor(filter,imfft2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize))); EVENTUALLY
             chrRpad[i_orient-1][i_scale-1]=abs(logGabor(filter,imfft2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize));
           }
       }

      conspic = Mat::zeros(img.rows,img.cols,CV_8UC3);

        for(int i_orient=1;i_orient<=achrOrient;i_orient++){
                for(int i_scale=1;i_scale<=achrScales;i_scale++){

                    stack.push_back(achrRpad[i_orient-1][i_scale-1]);

                }
        }

      for(int i_orient=1;i_orient<=achrOrient;i_orient++){

          inCompImg = Mat(stack).reshape(numColComp).t();
          inCompImg = inCompImg.reshape(0,rows*cols);
        Tsquared=whitening_sqr_meanDistance(inCompImg);
        Tsquared.convertTo(img,CV_8UC3);
        img = img.reshape(numColComp,rows);

        tiese[i_orient-1].data= Tsquared.reshape(0,rows);

        for(int a=1;a<=chrOrient;a++){
            maxT=max(0,tiese[a-1].data);
        }

        tiese[i_orient-1].data= tiese[i_orient-1].data/ maxT;

        maxhw = max(0,(int)floor(min(rows/2,cols/2)-1));
        sigma = max(rows,cols)*(0.025);
        GaussianBlur(tiese[i_orient-1].data,tiese[i_orient-1].data,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);


        conspic=conspic + tiese[i_orient-1].data;

      }
        divide(conspic,max(0,conspic),conspic);

        GaussianBlur(conspic,conspic,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);

        conspic2 = conspic2 + conspic;
    }

   multiply(conspic1,2,Salmap);
   Salmap= Salmap + conspic2;
   SumSalmap= sum(Salmap);
   Salmap = Salmap / SumSalmap;

   namedWindow("Salmap Display", CV_WINDOW_AUTOSIZE);
   imshow("Salmap Display", Salmap);
   waitKey(0);
   destroyWindow("Salmap Display");

   return 0;
 }

}


Mat colorDecorrelation(Mat img,int numColComp){

   Mat V,D,A,Xdecorr,img_tr,img_f;
   Scalar mu;
   SVD svd;

   if(numColComp>1){

        img.convertTo(img_f,CV_32FC3);
        img_f=img_f.reshape(1,img.rows*img.cols);

         mu=mean(img_f);
         subtract(img_f,mu,img_f);
        transpose(img_f,img_tr);
         A = img_tr * img_f;
        V = svd(A).u;
        Xdecorr = img_f*V;

  }
  else
      Xdecorr=img;

  return Xdecorr;
}

Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c){

   int padding;
   Mat pad;

   *padSize = roundIt(Lambda_max/2);
   padding = *padSize;

   Mat padded(img.rows + padding,img.cols + padding,img.type());
    copyMakeBorder(img,padded,padding/2,padding/2,padding/2,padding/2,BORDER_CONSTANT);

   *sz2filt_r=padded.rows;
   *sz2filt_c=padded.cols;

   padded.convertTo(pad,CV_32FC3);
   pad=pad.reshape(1,pad.rows);

   dft(pad,imfft);

   return imfft;

}

int roundIt(double num){
   int numero;
   double diff = fabs(num - (int)num);

   if((diff >= 0.5 && num < 0) || (diff < 0.5 && num >= 0))
      return numero=(int)num;
   else if(diff >=0.5 && num >= 0)
      return numero=(int)num + 1;
   else if(diff >0.5 && num < 0)
      return numero=(int)num - 1;
}

void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows){

  double X[rows][cols],Y[rows][cols];
  double x[cols],y[rows];
  double epsilon = 0.0001;


  for(int i=0;i<cols;i++){
      x[i]=((double)i-(cols/2))/((double)cols/2);
  }

  for(int z=0;z<rows;z++){
       y[z]=-(((double)z-(rows/2))/((double)rows/2));
   }


 for(int m=0;m<rows;m++){
  for(int n=0;n<cols;n++){
       X[m][n]=x[n];
       Y[m][n]=y[m];
  }
 }

 for(int a=0;a<rows;a++){
      for(int b=0;b<cols;b++){

             X[a][b] = pow(X[a][b],2);
             Y[a][b] = pow(Y[a][b],2);
             X[a][b] = X[a][b] + Y[a][b];
              radius[a][b] = sqrt(X[a][b]);

        }
  }
      radius[(int)floor(rows/2+1)][(int)floor(cols/2+1)]=1;

      for(int a=0;a<rows;a++){
           for(int b=0;b<cols;b++){
               radius [a][b]= radius[a][b] + epsilon;
               theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
           }
      }
}

Mat whitening_sqr_meanDistance(Mat X){

  Mat X_f,X_tr,A,V,D,S,Z,Xwh,whMat;
  Scalar mu,mu_wh;
  SVD svd;
  double epsilon = 0.0001;
  int r,c;

  X.convertTo(X_f,CV_32FC3);
  X_f=X_f.reshape(1,X.rows*X.cols);

  mu = mean(X_f);
  subtract(X_f,mu,X_f);
  transpose(X_f,X_tr);
  A=X_tr * X_f;

  V = svd(A).u;
  D = svd(D).w;

  r= X.rows;
  c= 1;

  S= Mat::eye((int)r*epsilon,(int)c*epsilon,CV_8UC3);

  Z=(D+S);
  Z=Z.inv(DECOMP_LU);
  sqrt(Z,S);
  whMat=V*S;

  Xwh=X*whMat;

  mu_wh=mean(Xwh);
  subtract(Xwh,mu_wh,Xwh);

  Z= Mat::zeros(r,c,CV_32FC3);

  sqrt(Xwh,Z);

 return Z;
}


Mat logGabor(matriz filter,Mat imfft,double r_o, double theta_o,double sigma_theta,matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize){

  Mat rpad;
  int k=*padSize;
  double sintheta[rows][cols],costheta[rows][cols],dalpha[rows][cols],spread[rows][cols];
  double ds[rows][cols],dc[rows][cols],divis[rows][cols],divis2[rows][cols];

  printf("LogGabor\n"); //DOESN ENTER

  for(int a=0; a<rows; a++){
      for(int b=0; b<cols; b++){

        sintheta[a][b]=sin(theta[a][b]);
        costheta[a][b]=cos(theta[a][b]);
        ds[a][b] = (sintheta[a][b] * cos(theta_o) - costheta[a][b] * sin(theta_o));
        dc[a][b] = (costheta[a][b] * cos(theta_o) + sintheta[a][b] * sin(theta_o));
        dalpha[a][b] = abs(atan2(ds[a][b],dc[a][b]));
        divis[a][b] = -(dalpha[a][b]*dalpha[a][b])/(2*(sigma_theta*sigma_theta));
        spread[a][b]= exp(divis[a][b]);
        divis2[a][b]= -(log((radius[a][b]/r_o) * (radius[a][b]/r_o))/(2*log(sigma_r*sigma_r)));
        filter[a][b]= exp(divis2[a][b]);
        filter[a][b]= spread[a][b]*(filter[a][b]);

      }
  }

  ftshifting(filter,rows,cols);

  for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++) {

          imfft =  imfft.mul(filter[m][n]);

      }
  }

  dft(imfft,rpad, DFT_INVERSE | DFT_REAL_OUTPUT);

  Rect roi(k,k,rpad.rows-(2*k),rpad.cols-(2*k));
  rpad = rpad(roi);

 return rpad;
}

void ftshifting(matriz filter,int rows,int cols){

  double tmp1_3,tmp2_4;
  int r2,c2;

  r2 = (rows+1)/2;
  c2 = (cols+1)/2;

  for (int i = 0; i<rows/2; i++){
     for (int k = 0; k<cols/2; k++){

          tmp1_3 = filter[i][k];
          filter[i][k] = filter[i+r2][k+c2];
          filter[i+r2][k+c2] = tmp1_3;

          tmp2_4 = filter[i+r2][k];
          filter[i+r2][k] = filter[i][k+c2];
          filter[i][k+c2] = tmp2_4;
     }
  }
}

double **createmat(int rows,int cols){

    double **m;

    m=new double*[rows];
     for(int i=0;i<rows;i++)
         m[i]=new double[cols];

    return m;
}


Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 03 July 2013 - 10:07 AM

First why are you mixing malloc and new? You need to decide if you're writing a C or C++ program.

If your writing a C++ program then why all the pointers, you should probably be passing references instead.

Also never hide pointers in a typedef:
typedef double** matriz; // ????? WHY ?????


Also instead of the array think about using a vector instead.

By the way this not a small or complete program. You are using several non-standard include files that are required to build this program.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 03 July 2013 - 10:53 AM

the problem is I studied just C in University and this is my thesis project. Using OpenCV I can have to use C++ expressions. For what you said about vectors. It caused a glibc error. As my teacher said there were some problems with the vector of vectors I created. Maybe compatibility. So I had to use a new type of data. I used an allocation with new and there is no change in the output of my work.
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 03 July 2013 - 11:56 AM

Quote

or. As my teacher said there were some problems with the vector of vectors I created.

Then why didn't you fix the problem with the vectors?

You still haven't answered the question as to why you're mixing malloc and new. Don't mix these two, the mixing can cause problems!

Quote

Using OpenCV I can have to use C++ expressions.

Why? From the following link: OpenCV

Quote

OpenCV is released under a BSD license and hence its free for both academic and commercial use. It has C++, C, Python and Java interfaces


You need to figure out if you're going to use C or C++. Pick one and use it. Don't mix C-isms with C++, especially manual memory management.

Jim
Was This Post Helpful? 0
  • +
  • -

#7 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 08 July 2013 - 10:25 AM

Hi can u see what i wrote in the answer you close, I tried to do what u did more or less, but can not use the vector. just answer first 2 points. thanks
Was This Post Helpful? 0
  • +
  • -

#8 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 687
  • View blog
  • Posts: 2,376
  • Joined: 31-December 10

Re: LogGabor function problem

Posted 08 July 2013 - 10:31 AM

Post your updated code here so we can have a look instead of having to go find the other thread.
Was This Post Helpful? 0
  • +
  • -

#9 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 08 July 2013 - 11:19 AM

#include <stdio.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <vector>

using namespace cv;
using namespace std;

typedef double** matriz;

#define PI 3.14159265

struct ts{
   Mat data;
}tiese[4];

Mat colorDecorrelation(Mat img,int numColComp);
Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c);
int roundIt(double num);
void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows);
Mat logGabor(matriz filter,Mat imfft,double r_o, double theta_o,double sigma_theta,matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize);
Mat whitening_sqr_meanDistance(Mat X);
void ftshifting(matriz filter,int rows,int cols);
double **createmat(int rows,int cols);

int main(){

 double achrScales,achrOrient,achrLambda_min,achrScFactor,achrDeltaAng,achrBwF,achrLambda_max,chrScales,chrOrient,chrLambda_min,chrScFactor,chrDeltaAng,chrBwF,chrLambda_max,sigma_r,wavelengths,sigma_theta,sigma,r_o,theta_o;
 int nChannels,numColComp,*padSize,rows,cols,maxhw,*sz2filt_r,*sz2filt_c;
 Mat img = imread("/home/elvio/workspace/aws/src/andaina.JPG");
 Mat rgbDecorrImg,imfft,imfft2,imgDecorr,conspic1,conspic,conspic2,Tsquared,inCompImg,Salmap,SumSalmap,maxT,GaussKernel;
 Mat achrRpad[4][7],chrRpad[4][5];
 vector<Mat>stack;

 if(img.empty()){
     cout<< "The image is empty \n";
     return -1;
 }

 namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
 imshow("Image Display", img);
 waitKey(0);
 destroyWindow("Image Display");

 padSize = new int;
 sz2filt_r = new int;
 sz2filt_c = new int;

 rows=img.rows;
 cols= img.cols;
 nChannels= img.channels();
 numColComp = nChannels ;

 inCompImg = img.reshape(numColComp,rows*cols);

 imgDecorr = colorDecorrelation(inCompImg,numColComp);

 rows=imgDecorr.rows;
 cols=imgDecorr.cols;
 nChannels= imgDecorr.channels();

 imgDecorr.convertTo(rgbDecorrImg,CV_8UC3);
 rgbDecorrImg = rgbDecorrImg.reshape(numColComp,img.rows);

 namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
 imshow("Image Display", rgbDecorrImg);
 waitKey(0);
 destroyWindow("Image Display");


 chrScales=5;
 chrOrient=4;
 chrLambda_min=6;
 chrScFactor=2;
 chrDeltaAng = 1.7;
 chrBwF=1.1;
 chrLambda_max= (chrLambda_min) * (pow(chrScFactor,chrScales-1));


     conspic2 = Mat::zeros(img.rows,img.cols,CV_8UC3);

     for(int i_c_comp=2;i_c_comp<numColComp;i_c_comp++){


        imfft=FourierTrasform2D(rgbDecorrImg,chrLambda_max,imfft,padSize,sz2filt_r,sz2filt_c);
        rows=*sz2filt_r;
        cols=*sz2filt_c;

        imfft.convertTo(imfft2,CV_8UC3);
        imfft2= imfft2.reshape(numColComp,rows);

         namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
         imshow("Image Display", imfft2);
         waitKey(0);
         destroyWindow("Image Display");

       matriz radius,theta,filter;
       radius = createmat(rows,cols);
       theta = createmat(rows,cols);
       filter = createmat(rows,cols);

       pre_filter_Computations(radius,theta,cols,rows);

       sigma_r = exp(-(pow(2,chrBwF) -1)/(pow(2,chrBwF) + 1));
       sigma_theta = (PI/chrOrient)/chrDeltaAng;

       for(int i_orient=1;i_orient<=chrOrient;i_orient++){
          for(int i_scale=1;i_scale<=chrScales;i_scale++){

             wavelengths = chrLambda_min * (pow(chrScFactor,i_scale -1));
             r_o = 2/wavelengths;
             theta_o = (i_orient-1)*(PI/chrOrient);
             cout<< "BeforeLogGabor\n";
      stack.push_back(abs(logGabor(filter,imfft2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize)));
           }
       }

      for(int i_orient=1;i_orient<=achrOrient;i_orient++){

        inCompImg = Mat(stack).reshape(numColComp).t();
        inCompImg = inCompImg.reshape(0,rows*cols);
        Tsquared=whitening_sqr_meanDistance(inCompImg);
        Tsquared.convertTo(img,CV_8UC3);
        img = img.reshape(numColComp,rows);

        tiese[i_orient-1].data= Tsquared.reshape(0,rows);

        for(int a=1;a<=chrOrient;a++){
            maxT=max(0,tiese[a-1].data);
        }

        tiese[i_orient-1].data= tiese[i_orient-1].data/ maxT;

        maxhw = max(0,(int)floor(min(rows/2,cols/2)-1));
        sigma = max(rows,cols)*(0.025);
        GaussianBlur(tiese[i_orient-1].data,tiese[i_orient-1].data,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);


        conspic=conspic + tiese[i_orient-1].data;

      }
        divide(conspic,max(0,conspic),conspic);

        GaussianBlur(conspic,conspic,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);

        conspic2 = conspic2 + conspic;
    }

   multiply(conspic1,2,Salmap);
   Salmap= Salmap + conspic2;
   SumSalmap= sum(Salmap);
   Salmap = Salmap / SumSalmap;

   namedWindow("Salmap Display", CV_WINDOW_AUTOSIZE);
   imshow("Salmap Display", Salmap);
   waitKey(0);
   destroyWindow("Salmap Display");

   return 0;
 }

}


Mat colorDecorrelation(Mat img,int numColComp){

   Mat V,D,A,Xdecorr,img_tr,img_f;
   Scalar mu;
   SVD svd;

   if(numColComp>1){

        img.convertTo(img_f,CV_32FC3);
        img_f=img_f.reshape(1,img.rows*img.cols);

         mu=mean(img_f);
         subtract(img_f,mu,img_f);
        transpose(img_f,img_tr);
         A = img_tr * img_f;
        V = svd(A).u;
        Xdecorr = img_f*V;

  }
  else
      Xdecorr=img;

  return Xdecorr;
}

Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c){

   int padding;
   Mat pad;

   *padSize = roundIt(Lambda_max/2);
   padding = *padSize;

   Mat padded(img.rows + padding,img.cols + padding,img.type());
    copyMakeBorder(img,padded,padding/2,padding/2,padding/2,padding/2,BORDER_CONSTANT);

   namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
   imshow("Image Display", padded);
   waitKey(0);
   destroyWindow("Image Display");

   *sz2filt_r=padded.rows;
   *sz2filt_c=padded.cols;

   padded.convertTo(pad,CV_32FC3);
   pad=pad.reshape(1,pad.rows);

   dft(pad,imfft);

   return imfft;

}

int roundIt(double num){
   int numero;
   double diff = fabs(num - (int)num);

   if((diff >= 0.5 && num < 0) || (diff < 0.5 && num >= 0))
      return numero=(int)num;
   else if(diff >=0.5 && num >= 0)
      return numero=(int)num + 1;
   else if(diff >0.5 && num < 0)
      return numero=(int)num - 1;
}

void pre_filter_Computations(matriz radius,matriz theta,int cols,int rows){

  double X[rows][cols],Y[rows][cols];
  double x[cols],y[rows];
  double epsilon = 0.0001;

  for(int i=0;i<cols;i++){
      x[i]=((double)i-(cols/2))/((double)cols/2);
  }

  for(int z=0;z<rows;z++){
       y[z]=-(((double)z-(rows/2))/((double)rows/2));
   }


 for(int m=0;m<rows;m++){
  for(int n=0;n<cols;n++){
       X[m][n]=x[n];
       Y[m][n]=y[m];
  }
 }

 for(int a=0;a<rows;a++){
      for(int b=0;b<cols;b++){

             X[a][b] = pow(X[a][b],2);
             Y[a][b] = pow(Y[a][b],2);
             X[a][b] = X[a][b] + Y[a][b];
             radius[a][b] = sqrt(X[a][b]);
        }
  }
      radius[(int)floor(rows/2+1)][(int)floor(cols/2+1)]=1;

      for(int a=0;a<rows;a++){
           for(int b=0;b<cols;b++){
               radius [a][b]= radius[a][b] + epsilon;
               theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
           }
      }
}

Mat whitening_sqr_meanDistance(Mat X){

  Mat X_f,X_tr,A,V,D,S,Z,Xwh,whMat;
  Scalar mu,mu_wh;
  SVD svd;
  double epsilon = 0.0001;
  int r,c;

  X.convertTo(X_f,CV_32FC3);
  X_f=X_f.reshape(1,X.rows*X.cols);

  mu = mean(X_f);
  subtract(X_f,mu,X_f);
  transpose(X_f,X_tr);
  A=X_tr * X_f;

  V = svd(A).u;
  D = svd(A).w;

  r= X.rows;
  c= 1;

  S= Mat::eye((int)r*epsilon,(int)c*epsilon,CV_32FC3);
  S=S*epsilon;
  Z=(D+S);
  Z=Z.inv(DECOMP_LU);
  sqrt(Z,S);
  whMat=V*S;

  Xwh=X*whMat;
  mu_wh=mean(Xwh);
  subtract(Xwh,mu_wh,Xwh);

  Z= Mat::zeros(r,c,CV_32FC3);

  sqrt(Xwh,Z);

 return Z;
}


Mat logGabor(matriz filter,Mat imfft,double r_o, double theta_o,double sigma_theta,matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize){

  Mat rpad;
  int k=*padSize;
  double sintheta[rows][cols],costheta[rows][cols],dalpha[rows][cols],spread[rows][cols];
  double ds[rows][cols],dc[rows][cols],divis[rows][cols],divis2[rows][cols];

  cout<< "Inside LogGabor\n" ; // Here I can t print and console doesn' give nothing more as output

  for(int a=0; a<rows; a++){
      for(int b=0; b<cols; b++){

        sintheta[a][b]=sin(theta[a][b]);
        costheta[a][b]=cos(theta[a][b]);
        ds[a][b] = (sintheta[a][b] * cos(theta_o) - costheta[a][b] * sin(theta_o));
        dc[a][b] = (costheta[a][b] * cos(theta_o) + sintheta[a][b] * sin(theta_o));
        dalpha[a][b] = abs(atan2(ds[a][b],dc[a][b]));
        divis[a][b] = -(dalpha[a][b]*dalpha[a][b])/(2*(sigma_theta*sigma_theta));
        spread[a][b]= exp(divis[a][b]);
        divis2[a][b]= -(log((radius[a][b]/r_o) * (radius[a][b]/r_o))/(2*log(sigma_r*sigma_r)));
        filter[a][b]= exp(divis2[a][b]);
        filter[a][b]= spread[a][b]*(filter[a][b]);

      }
  }

  ftshifting(filter,rows,cols);

  for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++) {

          imfft =  imfft.mul(filter[m][n]);

      }
  }

  dft(imfft,rpad, DFT_INVERSE | DFT_REAL_OUTPUT);

  Rect roi(k,k,rpad.rows-(2*k),rpad.cols-(2*k));
  rpad = rpad(roi);

 return rpad;
}

void ftshifting(matriz filter,int rows,int cols){

  double tmp1_3,tmp2_4;
  int r2,c2;

  r2 = (rows+1)/2;
  c2 = (cols+1)/2;

  for (int i = 0; i<rows/2; i++){
     for (int k = 0; k<cols/2; k++){

          tmp1_3 = filter[i][k];
          filter[i][k] = filter[i+r2][k+c2];
          filter[i+r2][k+c2] = tmp1_3;

          tmp2_4 = filter[i+r2][k];
          filter[i+r2][k] = filter[i][k+c2];
          filter[i][k+c2] = tmp2_4;
     }
  }
}

double **createmat(int rows,int cols){

    double **m;

    m=new double*[rows];
     for(int i=0;i<rows;i++)
         m[i]=new double[cols];

    return m;
}


I wanna delete the typedef with pointer and to use vectors, but using vector of vectors I had an error compiling with glibc. For this I used the createmat function. Now I was thinking about just pass to this function a double ** variable without using the typedef. Every function works good , so you can not see inside the other function. I just have problem wit logGabor, when it stops (where i use cout) and another function, but it s used just after this function. PS now it works with image of type 8UC3. So question:

1)Is it good to modify it to:

double **filter,**theta,**radius;
radius=createmat(r,c); //the same for the other
// function createmat doesn t change but I have some errors changing it

2)Can I have the function's body after main in C++ or I have to change it?
3) Report if there is some line to change in C++
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 08 July 2013 - 11:29 AM

Quote

but using vector of vectors I had an error compiling with glibc.

You don't compile with glibc, that's the C standard library. You compile C++ code with g++.

If you know C like you say you do, why are you trying to use C++? The library you are trying to use has C and or C++ capabilities. You just need to make sure you're using the correct API.

Quote

2)Can I have the function's body after main in C++ or I have to change it?

Yes. Just like C you can have function implementations in any order. You just need to insure you have created your function prototypes before you try to use the functions.

Quote

3) Report if there is some line to change in C++

What? Your compiler will tell you if you have errors/warnings.


Jim
Was This Post Helpful? 0
  • +
  • -

#11 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 09 July 2013 - 05:10 AM

hi Jim,

the problem is the last version of OpenCV just works with linux and cpp. If the file is not .cpp it doesn t work. when i compiled with vector of vectors I had an error compiling that was GLIBC ERROR DETECTED. The compiler doesn t see no one errors. But as you said mixing C and C++ it might give some errors. For this I m trying to use just C++
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 09 July 2013 - 05:43 AM

Quote

the problem is the last version of OpenCV just works with linux and cpp

Not from what I can see, Open-CV has both C and C++ bindings, even the latest version. Show where you found and downloaded your version of this library.

Edit: It looks like this library is indeed going the C++ only route, although there still may be C support, you probably should be using C++.

Quote

hen i compiled with vector of vectors I had an error compiling that was GLIBC ERROR DETECTED.

Show the code that is causing the problems. Also post the exact error messages exactly as they appear in your development environment.

Quote

The compiler doesn t see no one errors. But as you said mixing C and C++ it might give some errors. For this I m trying to use just C++

Then you need to increase your compiler's warning level. Here are the warnings and errors I get when I compile your program.

Quote

main.cpp||In function ‘int main()’:|
main.cpp|32|warning: unused variable ‘achrScales’ [-Wunused-variable]|
main.cpp|32|warning: unused variable ‘achrLambda_min’ [-Wunused-variable]|
main.cpp|32|warning: unused variable ‘achrScFactor’ [-Wunused-variable]|
main.cpp|32|warning: unused variable ‘achrDeltaAng’ [-Wunused-variable]|
main.cpp|32|warning: unused variable ‘achrBwF’ [-Wunused-variable]|
main.cpp|32|warning: unused variable ‘achrLambda_max’ [-Wunused-variable]|
main.cpp|36|warning: unused variable ‘achrRpad’ [-Wunused-variable]|
main.cpp|36|warning: unused variable ‘chrRpad’ [-Wunused-variable]|
main.cpp||In function ‘void pre_filter_Computations(matriz, matriz, int, int)’:|
main.cpp|247|error: ISO C++ forbids variable length array ‘X’ [-Wvla]|
main.cpp|247|error: ISO C++ forbids variable length array ‘X’ [-Wvla]|
main.cpp|247|error: ISO C++ forbids variable length array ‘Y’ [-Wvla]|
main.cpp|247|error: ISO C++ forbids variable length array ‘Y’ [-Wvla]|
main.cpp|248|error: ISO C++ forbids variable length array ‘x’ [-Wvla]|
main.cpp|248|error: ISO C++ forbids variable length array ‘y’ [-Wvla]|
main.cpp||In function ‘cv::Mat logGabor(matriz, cv::Mat, double, double, double, matriz, matriz, int, int, double, int*)’:|
main.cpp|341|error: ISO C++ forbids variable length array ‘sintheta’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘sintheta’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘costheta’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘costheta’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘dalpha’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘dalpha’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘spread’ [-Wvla]|
main.cpp|341|error: ISO C++ forbids variable length array ‘spread’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘ds’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘ds’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘dc’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘dc’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘divis’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘divis’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘divis2’ [-Wvla]|
main.cpp|342|error: ISO C++ forbids variable length array ‘divis2’ [-Wvla]|
main.cpp||In function ‘int roundIt(double)’:|
main.cpp|242|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build finished: 22 errors, 9 warnings (0 minutes, 2 seconds) ===|


By the way these errors would be a problem for most C compilers as well. Only a C99 compliant compiler is guaranteed to support VLAs. I really suggest you fix these problems.

Also since I'm not familiar with OpenCV please tell me where and how Mat is defined.



Jim

This post has been edited by jimblumberg: 09 July 2013 - 06:14 AM

Was This Post Helpful? 0
  • +
  • -

#13 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 09 July 2013 - 11:31 AM

Hi,

When I compile that project I sent before I just have a warning (C99) .Now I copy with vector of vectors.

#include <stdio.h>
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <math.h>
#include <vector>

using namespace cv;
using namespace std;

#define PI 3.14159265

struct ts{
   Mat data;
}tiese[4];

Mat colorDecorrelation(Mat img,int numColComp);
Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c);
int roundIt(double num);
void pre_filter_Computations(vector< vector<double> > &radius,vector< vector<double> > &theta,int cols,int rows);
Mat logGabor(vector< vector<double> > &filter,Mat imfft,double r_o, double theta_o,double sigma_theta,vector< vector<double> > &radius,vector< vector<double> > &theta,int cols,int rows,double sigma_r,int *padSize);
Mat whitening_sqr_meanDistance(Mat X);
void ftshifting(vector< vector<double> > &filter,int rows,int cols);

int main(){

 double achrScales,achrOrient,achrLambda_min,achrScFactor,achrDeltaAng,achrBwF,achrLambda_max,chrScales,chrOrient,chrLambda_min,chrScFactor,chrDeltaAng,chrBwF,chrLambda_max,sigma_r,wavelengths,sigma_theta,sigma,r_o,theta_o;
 int nChannels,numColComp,*padSize,rows,cols,maxhw,*sz2filt_r,*sz2filt_c;
 Mat img = imread("/home/elvio/workspace/prova/source/andaina.bmp");
 Mat rgbDecorrImg,imfft,imfft2,imgDecorr,conspic1,conspic,conspic2,Tsquared,inCompImg,Salmap,SumSalmap,maxT,GaussKernel;
 vector<Mat>stack;

 if(img.empty()){
     cout<<"The image is empty\n";
     return -1;
 }

 namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
 imshow("Image Display", img);
 waitKey(0);
 destroyWindow("Image Display");

 padSize = new int;
 sz2filt_r = new int;
 sz2filt_c = new int;

 rows=img.rows;
 cols= img.cols;
 nChannels= img.channels();
 numColComp = nChannels ;

 inCompImg = img.reshape(numColComp,rows*cols);

 imgDecorr = colorDecorrelation(inCompImg,numColComp);

 rows=imgDecorr.rows;
 cols=imgDecorr.cols;
 nChannels= imgDecorr.channels();

 imgDecorr.convertTo(rgbDecorrImg,CV_8UC3);
 rgbDecorrImg = rgbDecorrImg.reshape(numColComp,img.rows);

 namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
 imshow("Image Display", rgbDecorrImg);
 waitKey(0);
 destroyWindow("Image Display");

 chrScales=5;
 chrOrient=4;
 chrLambda_min=6;
 chrScFactor=2;
 chrDeltaAng = 1.7;
 chrBwF=1.1;
 chrLambda_max= (chrLambda_min) * (pow(chrScFactor,chrScales-1));

     conspic2 = Mat::zeros(img.rows,img.cols,CV_8UC3);

     for(int i_c_comp=2;i_c_comp<numColComp;i_c_comp++){


        imfft=FourierTrasform2D(rgbDecorrImg,chrLambda_max,imfft,padSize,sz2filt_r,sz2filt_c);
        rows=*sz2filt_r;
        cols=*sz2filt_c;

        imfft.convertTo(imfft2,CV_8UC3);
        imfft2= imfft2.reshape(numColComp,rows);

         namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
         imshow("Image Display", imfft2);
         waitKey(0);
         destroyWindow("Image Display");

       vector< vector<double> >radius(rows,vector <double> (cols));
       vector< vector<double> >theta(rows,vector <double> (cols));
       vector< vector<double> >filter(rows,vector <double> (cols));

        pre_filter_Computations(radius,theta,cols,rows);

         sigma_r = exp(-(pow(2,chrBwF) -1)/(pow(2,chrBwF) + 1));
         sigma_theta = (PI/chrOrient)/chrDeltaAng;

       for(int i_orient=1;i_orient<=chrOrient;i_orient++){
          for(int i_scale=1;i_scale<=chrScales;i_scale++){
             Mat prova;
             wavelengths = chrLambda_min * (pow(chrScFactor,i_scale -1));
             r_o = 2/wavelengths;
             theta_o = (i_orient-1)*(PI/chrOrient);
             cout<< "Before Loggabor\n";
             stack.push_back(abs(logGabor(filter,imfft2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize)));
            }
       }

      conspic = Mat::zeros(img.rows,img.cols,CV_8UC3);

        for(int i_orient=1;i_orient<=achrOrient;i_orient++){
                for(int i_scale=1;i_scale<=achrScales;i_scale++){

                  stack.push_back(stack);

                }
        }

      for(int i_orient=1;i_orient<=achrOrient;i_orient++){

        inCompImg = Mat(stack).reshape(numColComp).t();
        inCompImg = inCompImg.reshape(0,rows*cols);
        Tsquared=whitening_sqr_meanDistance(inCompImg);
        Tsquared.convertTo(img,CV_8UC3);
        img = img.reshape(numColComp,rows);

        tiese[i_orient-1].data= Tsquared.reshape(0,rows);

        for(int a=1;a<=chrOrient;a++){
            maxT=max(0,tiese[a-1].data);
        }

        tiese[i_orient-1].data= tiese[i_orient-1].data/ maxT;

        maxhw = max(0,(int)floor(min(rows/2,cols/2)-1));
        sigma = max(rows,cols)*(0.025);
        GaussianBlur(tiese[i_orient-1].data,tiese[i_orient-1].data,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);


        conspic=conspic + tiese[i_orient-1].data;

      }
        divide(conspic,max(0,conspic),conspic);

        GaussianBlur(conspic,conspic,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);

        conspic2 = conspic2 + conspic;
    }

   multiply(conspic1,2,Salmap);
   Salmap= Salmap + conspic2;
   SumSalmap= sum(Salmap);
   Salmap = Salmap / SumSalmap;

   namedWindow("Salmap Display", CV_WINDOW_AUTOSIZE);
   imshow("Salmap Display", Salmap);
   waitKey(0);
   destroyWindow("Salmap Display");

   return 0;
 }

}


Mat colorDecorrelation(Mat img,int numColComp){

   Mat V,D,A,Xdecorr,img_tr,img_f;
   Scalar mu;
   SVD svd;

   if(numColComp>1){

        img.convertTo(img_f,CV_32FC3);
        img_f=img_f.reshape(1,img.rows*img.cols);

         mu=mean(img_f);
         subtract(img_f,mu,img_f);
        transpose(img_f,img_tr);
         A = img_tr * img_f;
        V = svd(A).u;
        Xdecorr = img_f*V;

  }
  else
      Xdecorr=img;

  return Xdecorr;
}

Mat FourierTrasform2D(Mat img, double Lambda_max,Mat imfft,int *padSize,int *sz2filt_r,int *sz2filt_c){

   int padding;
   Mat pad;

   *padSize = roundIt(Lambda_max/2);
   padding = *padSize;

   Mat padded(img.rows + padding,img.cols + padding,img.type());
    copyMakeBorder(img,padded,padding/2,padding/2,padding/2,padding/2,BORDER_CONSTANT);

   namedWindow("Image Display", CV_WINDOW_AUTOSIZE);
   imshow("Image Display", padded);
   waitKey(0);
   destroyWindow("Image Display");

   *sz2filt_r=padded.rows;
   *sz2filt_c=padded.cols;

   padded.convertTo(pad,CV_32FC3);
   pad=pad.reshape(1,pad.rows);

   dft(pad,imfft);

   return imfft;

}

int roundIt(double num){
   int numero;
   double diff = fabs(num - (int)num);

   if((diff >= 0.5 && num < 0) || (diff < 0.5 && num >= 0))
      return numero=(int)num;
   else if(diff >=0.5 && num >= 0)
      return numero=(int)num + 1;
   else if(diff >0.5 && num < 0)
      return numero=(int)num - 1;
}

void pre_filter_Computations(vector< vector<double> > &radius,vector< vector<double> > &theta,int cols,int rows){

  double X[rows][cols],Y[rows][cols];
  double x[cols],y[rows];
  double epsilon = 0.0001;

  for(int i=0;i<cols;i++){
      x[i]=((double)i-(cols/2))/((double)cols/2);
  }

  for(int z=0;z<rows;z++){
       y[z]=-(((double)z-(rows/2))/((double)rows/2));
   }


 for(int m=0;m<rows;m++){
  for(int n=0;n<cols;n++){
       X[m][n]=x[n];
       Y[m][n]=y[m];
  }
 }

 for(int a=0;a<rows;a++){
      for(int b=0;b<cols;b++){

             X[a][b] = pow(X[a][b],2);
             Y[a][b] = pow(Y[a][b],2);
             X[a][b] = X[a][b] + Y[a][b];
             radius[a][b] = sqrt(X[a][b]);
        }
  }
      radius[(int)floor(rows/2+1)][(int)floor(cols/2+1)]=1;

      for(int a=0;a<rows;a++){
           for(int b=0;b<cols;b++){
               radius [a][b]= radius[a][b] + epsilon;
               theta[a][b] = atan2(Y[a][b],X[a][b])*180/PI;
           }
      }
}

Mat whitening_sqr_meanDistance(Mat X){

  Mat X_f,X_tr,A,V,D,S,Z,Xwh,whMat;
  Scalar mu,mu_wh;
  SVD svd;
  double epsilon = 0.0001;
  int r,c;

  X.convertTo(X_f,CV_32FC3);
  X_f=X_f.reshape(1,X.rows*X.cols);

  mu = mean(X_f);
  subtract(X_f,mu,X_f);
  transpose(X_f,X_tr);
  A=X_tr * X_f;

  V = svd(A).u;
  D = svd(A).w;

  r= X.rows;
  c= 1;

  S= Mat::eye((int)r*epsilon,(int)c*epsilon,CV_32FC3);
  S=S*epsilon;
  Z=(D+S);
  Z=Z.inv(DECOMP_LU);
  sqrt(Z,S);
  whMat=V*S;

  Xwh=X*whMat;
  mu_wh=mean(Xwh);
  subtract(Xwh,mu_wh,Xwh);

  Z= Mat::zeros(r,c,CV_32FC3);

  sqrt(Xwh,Z);

 return Z;
}


Mat logGabor(vector< vector<double> > &filter,Mat imfft,double r_o, double theta_o,double sigma_theta,vector< vector<double> > &radius,vector< vector<double> > &theta,int cols,int rows,double sigma_r,int *padSize){

  Mat rpad;
  int k=*padSize;
  double sintheta[rows][cols],costheta[rows][cols],dalpha[rows][cols],spread[rows][cols];
  double ds[rows][cols],dc[rows][cols],divis[rows][cols],divis2[rows][cols];

  cout<<"LogGabor\n";

  for(int a=0; a<rows; a++){
      for(int b=0; b<cols; b++){

        sintheta[a][b]=sin(theta[a][b]);
        costheta[a][b]=cos(theta[a][b]);
        ds[a][b] = (sintheta[a][b] * cos(theta_o) - costheta[a][b] * sin(theta_o));
        dc[a][b] = (costheta[a][b] * cos(theta_o) + sintheta[a][b] * sin(theta_o));
        dalpha[a][b] = abs(atan2(ds[a][b],dc[a][b]));
        divis[a][b] = -(dalpha[a][b]*dalpha[a][b])/(2*(sigma_theta*sigma_theta));
        spread[a][b]= exp(divis[a][b]);
        divis2[a][b]= -(log((radius[a][b]/r_o) * (radius[a][b]/r_o))/(2*log(sigma_r*sigma_r)));
        filter[a][b]= exp(divis2[a][b]);
        filter[a][b]= spread[a][b]*(filter[a][b]);

      }
  }

  ftshifting(filter,rows,cols);

  for(int m=0;m<rows;m++){
      for(int n=0;n<cols;n++) {

          imfft =  imfft.mul(filter[m][n]);

      }
  }

  dft(imfft,rpad, DFT_INVERSE | DFT_REAL_OUTPUT);

  Rect roi(k,k,rpad.rows-(2*k),rpad.cols-(2*k));
  rpad = rpad(roi);

 return rpad;
}

void ftshifting(vector< vector<double> > &filter,int rows,int cols){

  double tmp1_3,tmp2_4;
  int r2,c2;

  r2 = (rows+1)/2;
  c2 = (cols+1)/2;

  for (int i = 0; i<rows/2; i++){
     for (int k = 0; k<cols/2; k++){

          tmp1_3 = filter[i][k];
          filter[i][k] = filter[i+r2][k+c2];
          filter[i+r2][k+c2] = tmp1_3;

          tmp2_4 = filter[i+r2][k];
          filter[i+r2][k] = filter[i][k+c2];
          filter[i][k+c2] = tmp2_4;
     }
  }
}



I copied the other function and modified it to insert again vector of vectors in another work. But when I build the project I have this error:

make:** No rule to make target 'ClasseVect.o',needed by 'prova'.Stop.

Prova is project's name and ClasseVect the cpp file
Was This Post Helpful? 0
  • +
  • -

#14 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: LogGabor function problem

Posted 09 July 2013 - 01:56 PM

First you have a mismatched brace at about line 167.

Next C++ doesn't allow Variable Length Arrays! So the following lines should fail to compile:
void pre_filter_Computations(vector< vector<double> > &radius,vector< vector<double> > &theta,int cols,int rows)
{
  double X[rows][cols],Y[rows][cols];
  double x[cols],y[rows];


In C++ array sizes must be compile time constants. The other alternative, preferred, would be to use std::vector instead of the arrays.

There are quite a few other issues but until these are fixed you won't be able to move on.

You need to insure your compiler is generating the maximum number of warnings, that you fix all warnings and stop using any compiler specific "feature", such as VLAs. Check your compiler documentation for information on how to accomplish these goals.



Jim
Was This Post Helpful? 0
  • +
  • -

#15 residentelvio  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 26-June 13

Re: LogGabor function problem

Posted 10 July 2013 - 03:32 AM

Changed it with:


vector<double>x;
vector<double>y;
vector< vector<double > >X;
vector< vector<double > >Y



Howewer when I printed the first version with array it works good. I can not compile this version because I have the same error building the function :

make:** No rule to make target 'ClasseVect.o',needed by 'prova'.Stop.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »