Ask Your Question
0

Matlab sub2ind / ind2sub in OpenCV /c++

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

tobyd gravatar image

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

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
1

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

medasani gravatar image

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

You can write them yourself like illustrated in this link: http://stackoverflow.com/questions/21709743/matlab-sub2ind-ind2sub-in-opencv-c

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)
{
   row=sub/cols;
   col=sub%cols;
}
edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit

Question Tools

Stats

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

Seen: 1,667 times

Last updated: Mar 25 '14