Ask Your Question
0

From Matlab to C

asked 2013-06-04 09:37:02 -0500

residentelvio gravatar image

i have to translate this line from Matlab to C

for i_orient=1:chrOrient

       stack = cat(3,resp{i_orient,:});
       inComp=reshape(stack,r*c,chrScales);
       Tsquared=whitening_sqr_meanDistance(inComp);

what I did is this, but I have to translate the cat function and I don t know why. resp is a MAt object in C

  for(int i_orient=1;i_orient<=achrOrient;i_orient++){
      //stack = cat(3,rpad{i_orient,:});
      inCompImg = stack.reshape(numColComp,rows*cols*achrScales);
      Tsquared=whitening_sqr_meanDistance(inCompImg);
      conspic = Tsquared.reshape(numColComp,rows*cols);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-06-04 09:54:40 -0500

cat isn't a standard function in C or C++ like it is in Matlab, you will have to implement the functionality yourself to match your needs. However, it is already weird that you only have two arguments for your matlab function, since documentation clearly states that min 3 arguments are needed.

I will explain the basics.

MATLAB

Cat function takes in account the number of dimensions and the matrices that need to be concatenated. 3 means you will use several 2D matrices into a 3D matrix structure.

C/C++ - OpenCV

Easiest way to do this is to create a 3D Mat structure, which can be done by using vectors. You can then copy each Mat that needs to be concatenated into the specified vector.

Example code:

Mat matrix_1;
Mat matrix_2;
vector<Mat> result;
result.push_back(matrix_1);
result.push_back(matrix_2);

If you want it for an arbitrary number of matrices, create a for loop structure.

edit flag offensive delete link more

Comments

Thanks to explain. Maybe as I don t know a lot about Matlab I didn t explain that resp become from this line

resp{i_orient,i_scale}=abs(logGabor(imfft,sz2filt,r_o,theta_o,sigma_theta,radius,theta,sigma_r,padSize));

Maybe is important to explain the line of before. I searched something about {} and I did not understand what it do well

residentelvio gravatar imageresidentelvio ( 2013-06-04 10:28:26 -0500 )edit
1

My advice, before translating matlab code to C/C++ using OpenCV, is to understand the actual matlab algorithm. Else there is litteraly no beginning. Also, problems about Matlab code shouldn't be adressed at this forum... read the FAQ to know why.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-06-05 01:56:30 -0500 )edit

Ok I understand what is a Cell. In my case I think I can use the vector Mat in a loop to obtain what I need

residentelvio gravatar imageresidentelvio ( 2013-06-05 15:13:02 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-06-04 09:37:02 -0500

Seen: 285 times

Last updated: Jun 04 '13