Prev: Rename File
Next: simple dot plot
From: mohan on 15 Jun 2010 09:57 Hi I am having difficulties with smoothing a curve ,, heres my code M =[]; for Num=1:31 load('Dnew22.rgb') LineNum = Dnew22(Num,1:end) ; %LineNum = LineNum(Num, 1:end) ; [r,c] = size(LineNum); LineNumt = LineNum' ; LineNumcorr = reshape(LineNum,6,90); LineNumcut = LineNumcorr(1:3,:); LineNumproper = LineNumcut' ; x = LineNumproper(:,1); y = LineNumproper(:,2); z = LineNumproper(:,3); Sj = decimdouglaspeuckerupdate(x,y,z,0.1); A(Num,:) = [x' y' z']; R = [x(Sj) y(Sj) z(Sj)]; M = [M;R]; %disp('sj ') end tri = delaunay(M(:,2), M(:,3)); %hold on ; trisurf(tri, M(:,2), M(:,3), M(:,1)) %hold off; %hidden off I have used doulas pluucker algorithm for decimation . function Sj = decimdouglaspeucker(x,y,z,epsilon); % Douglas-Peucker algorithm for polygonal line simplification x = reshape(x,length(x),1); y = reshape(y,length(y),1); z = reshape(z,length(z),1); n = length(x); L = [1 n]; LL = L; added = true; Dmax = 0; while added, added = false; jLL = 0; for j = 1:length(L)-1, jLL = jLL + 1; a = L(j); b = L(j+1); aa = [x(a); y(a); z(a)]; bb = [x(b); y(b); z(b)]; D = []; for k = (a+1):(b-1), xx = [x(k); y(k); z(k)]; nn = (bb-aa)/norm(bb-aa); D = [D; abs(norm((nn*nn' - eye(3))*(xx - aa)))]; end if ~isempty(D), [ii,jj] = max(D); if ii > epsilon, LL = [LL(1:jLL), jj+a, LL(jLL+1:end)]; jLL = jLL + 1; added = true; elseif ii > Dmax, Dmax = ii; end end end L = LL; end Sj = L; disp(Dmax); %figure, hold on %subplot(2,1,1), plot3(x,y,z,'b','Marker','none'); view(2), v = axis; %subplot(2,1,2), plot3(x(Sj),y(Sj),z(Sj),'r','Marker','.'); view(2), axis(v); ----------------------------------------------------------------------------------------------------------- everything works fine but with the surface generated , there are few lines joining together in between ,, please suggest me what to do
|
Pages: 1 Prev: Rename File Next: simple dot plot |