Ask Your Question

Matlab sub2ind / ind2sub in OpenCV /c++

asked 2014-02-11 12:39:22 -0500

tobyd gravatar image

updated 2014-02-11 12:44:54 -0500

berak gravatar image

Are there any functions in OpenCV which are equal to Matlab's sub2ind and ind2sub functions? I need both fuctions for my C++ app. If OpenCV lacks of these functions, are there any C++ libs which provide equivalent functionality?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-03-24 07:09:10 -0500

medasani gravatar image

updated 2014-03-25 08:04:46 -0500

You can write them yourself like illustrated in this link:

int sub2ind(const int row,const int col,const int cols,const int rows)
   return row*cols+col;

void ind2sub(const int sub,const int cols,const int rows,int &row,int &col)
edit flag offensive delete link more


This is a good answer if the input is 2D and doesn't have padding on each row.

xaffeine gravatar imagexaffeine ( 2014-03-25 12:40:07 -0500 )edit

I do not see the author mentioning that he hasn't got 2D input? But you got a point there!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-03-26 02:48:53 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-02-11 12:39:22 -0500

Seen: 920 times

Last updated: Mar 25 '14