Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 3d image surface normals
Date: Wed, 13 Feb 2008 20:49:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 39
Message-ID: <fovl3v$hti$1@fred.mathworks.com>
References: <fous72$b2o$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1202935743 18354 172.30.248.37 (13 Feb 2008 20:49:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 13 Feb 2008 20:49:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:451241


"k&#305;v&#305;lc&#305;m " <kvlcm_helhel@mathworks.com> wrote in 
message <fous72$b2o$1@fred.mathworks.com>...
>  
>    Hi everyone,
> 
> I work on 3d face images.I have  x,y,z points in raster
> form.I  need to find the surface normals of these images for
> my project. Firstly I need to apply polgonal mesh I
> think.But I can not any idea how to do this and obtain
> surface normals.Is there any one to help me???
---------
  Here is a possible answer to your question.  Suppose A is a 9 by 3 array with 
each row containing the (x,y,z) coordinates of one of nine points in your 
raster data, where these points consist of one point where you seek the 
surface normal, along with its eight neighboring points.  That is, within your 
raster form, the nine points presumably form a square when projected onto 
the x,y plane, with the central point being the one for which a normal is to be 
found.

  The normal to an orthogonal least squares best-fitting plane through these 
nine points can be regarded as a first order approximation to the surface 
normal direction at the central point.  If that is a suitable approximation for 
you, this problem can be easily solved using matlab's svd function.

 [U,S,V] = svd(A,0); % "economy" version of svd
 n = V(:,3); % Choose eigenvector with least eigenvalue
 n = sign(n(3))*n; % Choose "upwards" as plus direction

  The vector n will be a unit vector orthogonal to the best-fitting plane.  That 
is, it consists of the three direction cosines of the approximate normal 
direction.  (The adjustment in the last line is due to the ambiguity as to which 
of two opposite directions is chosen by svd.  The above ensures that n has a 
positive z-component.)

  Of course, you will need to repeat all of this for each point in the surface 
data.

Roger Stafford