上述代码输出的边界点有很多重复点,我需要再次优化代码使得输出完整的表面点且无重复点
时间: 2024-03-24 18:40:03 浏览: 54
不重复编码
在输出表面点之前,可以先使用unique函数去除重复点。具体的优化代码如下:
```
clear; clc;
matric = readmatrix("F:\NIM\worksheet\Lab\1号屏srgb+rgb16预热10分钟切换0.5s.csv");
matric = matric(2:end,1:end-1);
x = matric(:,8);
y = matric(:,9);
z = matric(:,10);
xyz = [x,y,z];
xyz = xyz./max(xyz(:,2));
r = matric(:,2)/255;
g = matric(:,3)/255;
b = matric(:,4)/255;
rgb = [r(:), g(:), b(:)];
cform_XYZ2Lab = makecform('xyz2lab');
lab = applycform(xyz, cform_XYZ2Lab);
a = lab(:,2);
b = lab(:,3);
L = lab(:,1);
Lab = [a,b,L];
TR = delaunayTriangulation(a,b,L);
[T,Xb] = freeBoundary(TR);
dt = triangulation(T,Xb);
tnorm = faceNormal(dt);
pidx = dt.Points;
isboundary = false(size(pidx,1),1);
for i = 1:size(tnorm,1)
n = tnorm(i,:);
v1 = pidx(dt.ConnectivityList(i,1),:);
v2 = pidx(dt.ConnectivityList(i,2),:);
v3 = pidx(dt.ConnectivityList(i,3),:);
d1 = dot(n,v1);
d2 = dot(n,v2);
d3 = dot(n,v3);
if any(sign(d1-d2) ~= sign(d1-d3))
isboundary(dt.ConnectivityList(i,:)) = true;
end
end
% 获取完整的边界点
K = boundary(dt.Points(isboundary,1),dt.Points(isboundary,2),dt.Points(isboundary,3));
surface_points = Lab(isboundary,:);
boundary_points = surface_points(K,:);
boundary_points = unique(boundary_points,'rows'); % 去除重复点
scatter3(boundary_points(:,1),boundary_points(:,2),boundary_points(:,3),10,"filled")
scatter3(a,b,L,10,rgb,"filled")
```
其中,unique函数用于去除重复点,输入参数为矩阵,'rows'表示按行去重。最后,使用scatter3函数将去除重复点后的完整的表面点绘制出来。
阅读全文