Remove Inf and NaN values โ€‹โ€‹in point cloud in fastest way

I am new to MATLAB and have just started working on Stereo Vision. After 3D Stereo Reconstruction of the scene, from the point cloud that I get, I want to ignore all coordinates with NaN or Inf values.

To do this, I follow this procedure:

For a 40 X 40 image, the point cloud is a 40 X 40 X 3 matrix (3 because of the 3D coordinates, X, Y and Z).

From a cloud of 3D points (40 X 40 X 3) I rehsape get a matrix of dimensions 1600 X 3. Each of the three columns corresponds to the X, Y and Z coordinates

At this point I am trying to delete the entire row if I find any Inf or NaN element.

For example, after the concatenation step, if I have a matrix A

A = [1, 11, 21; NaN, 12, 22; 3, 13, Inf; NaN, 14, NaN; 5, Inf, NaN; 6, 16, 26];

I want to delete all rows that have either Inf or NaN elements.

Thus, the expected result would be: [1, 11, 21; 6, 16, 26];

Since I will be working with 4000 X 3000 images, I want a very fast and efficient way to do this.

I do this in order to fit a plane (best fit) in the point cloud I get. The function corresponding to the plane does not take on the values โ€‹โ€‹Inf and NaN. Therefore, even if one NaN value is found, all corresponding X, Y, and Z coordinates must be eliminated.

If there is a better way to do this apart from what I am currently doing, please let us know.

Thank you =)

+3


source to share


3 answers


For sizing 1600 x 3

with dimensions, A

you can use this -

A(~any(isinf(A) | isnan(A),2),:)

      



If the number of lines to be deleted is a small number, you can delete them instead for better performance -

A(any(isinf(A) | isnan(A),2),:) = [];

      

+5


source


I think the easiest way to do this is to use the isnan (A) and isinf (A) functions to find NaNs and Infs. This solution works well with large matrices (I personally use such solutions for matrices that are larger than yours). Try:

rowstoremove = (sum(isnan(A),2) ~= 0) | (sum(isinf(A),2) ~= 0);
A(rowstoremove,:) = [];

      



This should do the trick.

+1


source


removeInvalidPoints

funtion is also available in Matlab, which removes points with Inf or NaN coordinates. You can check here: http://www.mathworks.com/help/vision/ref/pointcloud.removeinvalidpoints.html

Since these points are looking at noise in a point cloud, the best way is noise reduction. Because you can remove outliers from your data in addition to the NaN and Inf coordinates. pcdenoise

can be used for this. But you have to convert your data to matlab pointCloud object (this can be done with a function pointCloud

). Check out more information here: http://www.mathworks.com/help/vision/ref/pcdenoise.html

0


source







All Articles