image processing - surfnorm function more efficient way Matlab -
after constructing point cloud want normal of each point , used built-in matlab function surfnorm takes lot of processing time. if assist me better , more efficient way.
i wonder if following code you. there 3 steps here.
- create 500 randomly spaced points (x,y), , compute corresponding value z (the height of surface) chose
sinc
function - resample random points using
triscatteredinterp
function - permits me obtain points on evenly sampled grid "roughly correspond" initial surface - compute normal "some points" on grid (since there 480x640 points, computing normal @ every point create impossibly dense "forest of vectors"; sampling "every 10th point" can see doing
the code used follows:
randomx = rand(1,500); randomy = rand(1,500); r = 5*sqrt(randomx.^2 + randomy.^2); randomz = sin(r) ./ r; % resample data: [xx yy] = meshgrid(linspace(0,1,640), linspace(0,1,480)); f = triscatteredinterp(randomx(:), randomy(:), randomz(:)); zz = f(xx, yy); %% @ each point, normal cross product of vectors neighbors xyz=reshape([xx yy zz],[size(xx) 3]); xv = 10:30:479; yv = 10:30:639; % points @ compute normals dx = xyz(xv, yv+1, :) - xyz(xv, yv, :); dy = xyz(xv+1, yv, :) - xyz(xv, yv, :); normvecs = cross(dx, dy); % here compute normals. normvecs = normvecs ./ repmat(sqrt(sum(normvecs.^2, 3)), [1 1 3]); figure; quiver3(xx(xv, yv), yy(xv, yv), zz(xv, yv), ... normvecs(:,:,1), normvecs(:,:,2), normvecs(:,:,3)); axis equal view([56 22]);
and resulting plot:
Comments
Post a Comment