How can I create a logical mask from 3D data points?
Show older comments
I have an array of data points (size ~2000x3) compiled of points from several segmented CT slices. The end problem I'm trying to solve is to create an .stl file from the data, but a key step I'm struggling with is an efficient way of creating a 3D logical mask from the data.
What I'm trying to accomplish is an efficient way of creating a mask while keeping data precision on the order of 10E-4. I've tried scaling all the data points up (so they become integers), but that leaves the matrices WAY to large to be functional.
For example, one typical data point will be (before and after scaling):
PO_1 =
-1.6550 1.1250 0.0625
>> PO_1 = 10000.*PO_1 + 16551
PO_1 =
1 27801 17176
These could be used as locations in the mask, but you can see how large the matrix will end up.
Are there any hints or steps that I seem to be missing?
Thanks
3 Comments
Roger Stafford
on 17 Jan 2013
I see no reason why you should rescale your data or round them to integers just to obtain a logical mask. The two endeavors are totally unrelated in my opinion. Perhaps you could explain your reasoning in this. A logical entity asks a question which is either yes or no concerning data and it can be asked just as easily and accurately with data in one range as it can if you have rescaled it.
By the way, rescaling is ordinarily understood to be a multiplication process, not one of addition. By adding the large constant you have used, there is danger of increasing round-off errors. Rounding to integer will further degrade the data.
As Roger, I don't understand why you need what seems to be 3D coordinates to become positive integer indices.
If you want to "flag" points that correspond to a region of space, you can work directly with the original coordinates. For example, using a fake dataset of 5 points:
PO =
0.6000 -1.0000 0.2000
0.9000 0.8000 -1.2000
-1.0000 0.2000 -1.1000
-0.5000 1.3000 0.7000
0.6000 0.8000 -1.9000
For flagging points in the cube x,y in [0.5,1] and z in ]-2,-1], you would just do
>> selection = PO(:,1)>=.5 & PO(:,1)<=1 & ...
PO(:,2)>=.5 & PO(:,2)<=1 & ...
PO(:,3)>-2 & PO(:,3)<=-1
selection =
0
1
0
0
1
Then you could extract these points coordinates or any data with matching indices, using selection and logical indexing:
>> PO(selection,:)
ans =
0.9000 0.8000 -1.2000
0.6000 0.8000 -1.9000
Steve
on 18 Jan 2013
Answers (1)
Sean de Wolski
on 18 Jan 2013
0 votes
Adam A has a bunch of files for *.stl meshes and similar. I'd recommend giving his submissions a try.
Categories
Find more on Point Cloud Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!