nbsrujan
nbsrujan

Reputation: 1189

equivalent function of sub2ind in opencv

Iam facing problem in understanding and converting a matlab code into opencv. I want to know is there any equivalent function of sub2ind as in matlab in opencv. Or how to implement in opencv this particular function.

link for sub2ind function is

http://www.mathworks.in/help/techdoc/ref/sub2ind.html

Upvotes: 0

Views: 944

Answers (1)

Amro
Amro

Reputation: 124563

A quick example to illustrate. Consider:

>> v = (1:4*3)
v =
     1     2     3     4     5     6     7     8     9    10    11    12
>> M = reshape(v,[4 3])
M =
     1     5     9
     2     6    10
     3     7    11
     4     8    12

Now all the following are equivalent:

sz = size(M);

i = 3; j = 2;
M(i,j)
v( sub2ind(sz,i,j) )
v( sz(1)*(j-1)+i )

Just keep in mind that MATLAB uses a column-major order, while C is row-major order

Upvotes: 1

Related Questions