필터 지우기
필터 지우기

How do 3D coordinates map to a 3D matrix?

조회 수: 9 (최근 30일)
ting
ting 2013년 11월 21일
댓글: Bruno Pop-Stefanov 2013년 11월 22일
The project is about point cloud. Given a large number of 3-D coordinates (x-y-z) with all intensities are the same, say 1 or 255.
The range of x, y and z shown as follows.
* -113<x<158;
* -136<y<135 and
* -771<z<-500.
# If i create a 272 by 272 by 272 matrix, how can i map those 3-D coordinates to the matrix?
A = zeros(272, 272, 272);
# I know the matrix index starts from 1 in MAT-LAB. Should I create a 3-D grid to do mapping?
  댓글 수: 3
ting
ting 2013년 11월 21일
I am given a number of 3d data (x y, and z coordinates) ranging from -113<x<158 -136<y<135 -771<z<-500.
Example: (29 -76 -614) (30 -76 -614) (32 -76 -614) (32 -76 -614) (36 -76 -614) (36 -76 -614) I find the max and min values of x y z, i decide to build 272 by 272 by 272 matrix. You can ignore the intensity value, they are the same. Just consider as 3D data. I want to put them into a matrix according to their 3D coordinates and make 8*8*8 small block finally. I am not a good programmer, please also provide some functions or code.
ting
ting 2013년 11월 21일
BTW,I consider the matrix as 272*272*272 block, i should mention that if that coordinate exists put 1 or 255 in the matrix. Otherwise put 0. Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2013년 11월 21일
I assume in the following piece of code that your 3D points are listed in an N-by-3 vector named 'points'.
% Min and max values
xmin = -113;
xmax = 158;
ymin = -136;
ymax = 135;
zmin = -771;
zmax = -500;
% Initialize output matrix in which a non-zero entry indicates a 3D point exists in the input set
mat = zeros(xmax-xmin+1, ymax-ymin+1, zmax-zmin+1);
% For all 3D points
for p=1:size(points, 1)
if ( points(p,1)>xmax || points(p,1)<xmin || points(p,2)>ymax || points(p,2)<ymin || points(p,3)>zmax || points(p,3)<zmin )
fprintf('Error: point %d is out of bounds.\n', p);
else
i = points(p,1) - xmin + 1;
j = points(p,2) - ymin + 1;
k = points(p,3) - zmin + 1;
mat(i, j, k) = mat(i, j, k) + 1;
end
end
The output matrix 'mat' contains non-zero entries when a 3D point exists, but you'll have to convert into indices. For example, if the first point in 'points' is [29 -76 -614], then
mat(29-xmin, -76-ymin, -614-zmin) ~= 0
  댓글 수: 2
ting
ting 2013년 11월 22일
i have a question. so after finishing the loop, is mat a matrix of 272*272*272 with entries 1 or 0.
Also, if point data is (-133, -136, -771), all are min. Does it mean (-113, -136 -771) maps to martix(1, 1, 1) Thank you
Bruno Pop-Stefanov
Bruno Pop-Stefanov 2013년 11월 22일
If all your data points in your input vector are unique, then, yes, the matrix will only have 0's and 1's. Coordinate (i,j,k) in the output matrix is the number of points in the input vector that have corresponding coordinates (x,y,z). If you only want 0's and 1's, you can change line
mat(i, j, k) = mat(i, j, k) + 1;
to
mat(i, j, k) = 1;
Yes, (xmin, ymin, zmin) maps to (1, 1, 1).

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by