File Exchange

## SurfaceSmooth

version 1.2.0.0 (5.78 KB) by Marc Lalancette

### Marc Lalancette (view profile)

Restricted smoothing of a triangulated surface

Updated 20 Oct 2018

Transforms a closed triangulated surface by displacing the vertices in the direction normal to the surface, up to a limit specified by the user as a "voxel size". This is meant to smooth out the blocky appearance of a segmented volume without over smoothing and aims to maintain the enclosed volume. As such even an unrestricted smoothing operation would not tend to shrink, but would rather gradually converge to a sphere of near identical volume. The function can also be used to make a triangulation more uniform (in terms of triangle size and shape), as tangential motion can be left unrestricted during the smoothing process. Normal and tangential motion can be allowed independently and it is indeed more accurate to process a surface separately for these 2 operations (smoothing and making it more uniform). More details in the function help.

Note that this function is quite new and there may be bugs, but it was successfully used on a surface obtained from a skull segmentation with isosurface, with over 100000 vertices.

The aim of this function was accuracy over speed, but it can be quite fast on small surfaces or if the voxel size is made slightly larger. A few iterations only may be required.

### Cite As

Marc Lalancette (2019). SurfaceSmooth (https://www.mathworks.com/matlabcentral/fileexchange/45416-surfacesmooth), MATLAB Central File Exchange. Retrieved .

Marc Lalancette

### Marc Lalancette (view profile)

Thanks for commenting. I finally fixed the sparse error issue with some surfaces.

Chong WU

### Chong WU (view profile)

t = sort(Faces,2);

edge = [t(:),[t(:,2);t(:,3);t(:,1)]];
uniedge = unique(edge,'rows','stable');
abe = [];
for i = 1:length(uniedge)
e = uniedge(i,:);
[x1,~] = find(edge == e(1));
[x2,~] = find(edge == e(2));
x3 = intersect(x2,x1);
if length(x3) == 2
edge(x3(2),:) = [edge(x3(2),2),edge(x3(2),1)];
end
end

C = sparse(edge(:,1), edge(:,2), true);
////////////
add this code segment before sparse command will also help you to solve the sparse error problem

Chong WU

### Chong WU (view profile)

Sparse error problem can be solved without using sparse command but it will cause computational performance loss to some extent.

Aya Eid

### Aya Eid (view profile)

I had the sparse error problem too. I found the Matlab function: smooth3 to work well for me.

Marc Lalancette

### Marc Lalancette (view profile)

I believe the sparse error is due to repeated faces in the triangulation. I did not expect that. Maybe you can simplify your face array removing redundant faces...

parpar39

### parpar39 (view profile)

Running into the error using sparse as well.

Dampf Hans

Gianni Schena

### Gianni Schena (view profile)

Error using sparse
Repeated indices are not supported for sparse logical matrices.

Error in SurfaceSmooth (line 146)
C = sparse(Faces(:), [Faces(:, 2); Faces(:, 3); Faces(:, 1)], true);

Error in mytest (line 56)
V = SurfaceSmooth(FV.vertices,FV.faces,0.5,0.01,300);

Thomas-Glyn Cox

### Thomas-Glyn Cox (view profile)

Nevermind, I figured it out. So far looks great!