From Matlab to C

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++){
inCompImg = stack.reshape(numColComp,rows*cols*achrScales);
Tsquared=whitening_sqr_meanDistance(inCompImg);
conspic = Tsquared.reshape(numColComp,rows*cols);
edit retag close merge delete

Sort by » oldest newest most voted

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.

more

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

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

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.

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

Stats

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

Seen: 298 times

Last updated: Jun 04 '13