Ask Your Question
4

Create a mask for NaN cells

asked 2012-09-11 08:18:55 -0500

Tom Anderson gravatar image

updated 2012-09-11 08:21:04 -0500

I have a cv::Mat (type CV_32FC1) that contains some entries that are NaN. Basically I want to center all NaN in a matrix to a known value that dependent on which cell it is. So if both matrix and replacements are of equal dimensions, I'd like a function like:

cv::patchNaNs(matrix, replacements);

This method would replace any NaN in cell i,j from matrix with the corresponding value in cell i,j from replacements.

So I'm thinking I could do this with masks. How can I go about creating a mask that identifies those NaN entries? I tried threshold but none of the comparisons seem to be helpful for this purpose. Is there some simple thing that I'm overlooking?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2012-09-11 08:28:36 -0500

AlexanderShishkov gravatar image

Please try the following expression:

cv::Mat mask = cv::Mat(matrix != matrix);

where matrix is cv::Mat that contains NaN values.

edit flag offensive delete link more

Comments

Looks good. Then I just need to use:

replacements.copyTo(matrix, mask);

Tom Anderson gravatar imageTom Anderson ( 2012-09-11 08:57:23 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2012-09-11 08:18:55 -0500

Seen: 3,865 times

Last updated: Sep 11 '12