I am new to MATLAB and just started working on Stereo Vision. After 3D Stereo Reconstruction of a scene, from the point cloud I obtain, I want to ignore all the co-ordinates with values NaN or Inf.
To do so, I am following this procedure:
For an image of dimensions 40 X 40, the point cloud is a matrix of 40 X 40 X 3. (3 because of 3D; X, Y and Z co-ordinates).
From the 3D point cloud (40 X 40 X 3), I rehsape to get a matrix of dimensions 1600 X 3. Each of the 3 columns corresponds to the X, Y and Z co-ordinates
At this step, I am trying to remove 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 eliminate all rows which have either Inf or NaN elements.
So the expected result would be : [1, 11, 21; 6, 16, 26];
Since I will be working with images of dimensions 4000 X 3000, I want a very fast and efficient way of doing this.
I'm doing this in order to fit a plane (best fit) in the point cloud I obtain. The function to fit plane does not take Inf and NaN values. So even if one NaN value is found, all the corresponding X, Y and Z co-ordinates have to be eliminated.
If there is a better method to do this apart from what I'm doing at present, please inform.
Thank you =)
For the
1600 x 3
sized reshapedA
, you can use this -If the number of rows to be removed is a small number, you can directly remove them instead for a better performance -