How to avoid filling in certain geometries in a 3D plot

4 views (last 30 days)
Hello there, I'm currently creating a script that takes in binarised 2D .png slices and creates 3D models from the slices. I used bwboundaries to draw the plots for each image slice with 'holes':
[B] = bwboundaries(binaryImage_new,'holes');
I then used fill3 to draw the plots in 3D and cover the empty white spaces with a cyan colour and the whole process loops again with a new slice. Unfortunately, I have run into an issue where the fill3 property covers over the 'holes' of the plots.
As shown above, the base of my 3D benchy model has letters that should be indented but aren't, as the fill3 properties covers everything. I want to fill in the parts outside the letters in cyan and leave parts inside the letters empty.
Another example are the two holes above benchy, which should be hollow but are covered up by the fill3 property. I want to fill the outer geometry but leave the 'holes' empty.
Here's the main line of code for the plotting:
fill3(boundary(:,1), boundary(:,2), z, 'c', 'EdgeColor', [0 0.4470 0.7410], 'EdgeAlpha', 0.15, 'LineWidth', 0.25/resolution) %fill3 generates 3D plots and also fills in enclosed geometry with color
Is it possible to fill in certain parts?
  1 Comment
Suleman Sial
Suleman Sial on 13 Sep 2021
Okay, so I managed to get it to work, *slightly*. I decided to concatencate cell array B entirely (made by bwboundaries), thus removing the nested for loop (shown below):
for k = 1:length(B) %for every cell in B...
boundary = B{k};
z = repmat(i*(0.25/resolution),(height(boundary)),1); %z coordinates is an array of repeated numbers that is iterated by 1 every loop
...the size of the array changes depending on the size of the chosen cell array of B
fill3(boundary(:,1), boundary(:,2), z, 'c', 'EdgeColor', [0 0.4470 0.7410], 'EdgeAlpha', 0.15, 'LineWidth', 0.25/resolution)
...%fill3 generates 3D plots and also fills in enclosed geometry with color
end
replacing it instead with:
boundary = cell2mat(B);
boundary(:,3) = (0.25*i);
fill3(boundary(:,1), boundary(:,2), boundary(:,3), 'c', 'EdgeColor', [0 0.4470 0.7410], 'EdgeAlpha', 0.15, 'LineWidth', 0.25/resolution)
...%fill3 generates 3D plots and also fills in enclosed geometry with color
Unfortunately, this has caused another issue:
It appears that concatencating all of the points into a single 2d matrix means that boundaries are being connected with a single line, shown below:
Is there a way to remove these unwanted lines that are disrupting the fill3 tool? Adding NaN inbetween boundaries results in the fill3 tool not filling the region, due to the NaN values in the 2d matrix.
Any help would be greatly appreciated!

Sign in to comment.

Accepted Answer

Suleman Sial
Suleman Sial on 14 Sep 2021
Edited: Suleman Sial on 14 Sep 2021
It appears I've answered my own question. When dealing with image slices, utilising matlab's Volume Viewer app and volshow() is the best tool for this scenario, not bwboundaries or fill3 or any other plotting methods.
It created the holes and boundaries AND runs 8 times faster, since parfor can be utilised in the 'for loop' for stacking the images in an array.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!