Ask Your Question
0

Apply a function to every Mat element

asked 2013-04-09 13:15:27 -0600

rhuang gravatar image

Hello, I am looking for a method to apply a function to every single element of an input matrix. I've looked at remap() and transform(), but they both take a transformation matrix. What I am looking for is the equivalent of the map() function in Python.

PS I understand I can iterate through and apply the function to each of the the elements in my input matrix, but I am hoping CV has something built in because that might have been optimized.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-04-09 13:41:27 -0600

Basically, the looping is the only thing that can be applied to access each element seperately and perform a function to it. This is because the Mat element is actually a pointer that is shifted through your memory.

So use the following iterator

general : matrix.at<elementType>(i,j);
example : test.at<double>(4,3);

However if you would like to perform some mathematical functions to the elements like elementwise multiplying, that is possible using the mul() operator.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-09 13:15:27 -0600

Seen: 533 times

Last updated: Apr 09 '13