Binary mask for .stl file of large size

2 views (last 30 days)
Toshini
Toshini on 19 Mar 2025
Answered: Ronit on 25 Mar 2025
I'm trying to create binary mask for .stl files of segemented organs. With fat and muscle data of size (3116232x3 double) and (1521380x3 double) respectively, the inpolyhedron function doesn't work and shows an error saying it goes beyond 15 GB. So, I try to reduce their size. Which works fine, but on doing so a large amount of data is cropped out. Your suggestions would be valuable.
vertices = triangulationData.Points;
faces = triangulationData.ConnectivityList;
if size(vertices, 1) > 1e6 || size(faces, 1) > 1e6
[reducedFaces, reducedVertices] = reducepatch(struct('faces', faces, 'vertices', vertices), 5);
points = reducedVertices;
faces = reducedFaces;
else
points = vertices;
faces = faces;
end

Accepted Answer

Ronit
Ronit on 25 Mar 2025
Hello Toshini,
To address the issue of creating binary masks for large ".stl" files, I recommend using a chunk-based approach. This method allows processing large datasets in smaller sections, reducing memory usage and avoiding significant data loss from mesh reduction. This approach maintains the original detail and quality of the mesh, ensuring that important features are not lost.
Here is an example on how to implement a chunk-based approach:
vertices = triangulationData.Points;
faces = triangulationData.ConnectivityList;
chunkSize = 1e6; % Adjust based on available memory
binaryMask = zeros(size(vertices, 1), 1);
% Process in chunks
numChunks = ceil(size(vertices, 1) / chunkSize);
for i = 1:numChunks
% Determine the range for the current chunk and extract the vertices
startIdx = (i - 1) * chunkSize + 1;
endIdx = min(i * chunkSize, size(vertices, 1));
chunkVertices = vertices(startIdx:endIdx, :);
insideMask = inpolyhedron(faces, vertices, chunkVertices);
binaryMask(startIdx:endIdx) = insideMask;
end
Note: Adjust the above code according to the dataset and specific requirements of your application, as different datasets may require modifications to chunk size, memory allocation, or processing logic.
I hope this helps you!

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!