POINTSETSAVERAGE Compute the average of several point sets. AVERAGESET = pointSetsAverage(POINTSETS) POINTSETS is a cell array containing several liste of points with the same number of points. The function compute the average coordinate of each vertex, and return the resulting average point set. Example pointSetsAverage See also ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-04-01, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function average = pointSetsAverage(pointSets, varargin) 0002 %POINTSETSAVERAGE Compute the average of several point sets. 0003 % 0004 % AVERAGESET = pointSetsAverage(POINTSETS) 0005 % POINTSETS is a cell array containing several liste of points with the 0006 % same number of points. The function compute the average coordinate of 0007 % each vertex, and return the resulting average point set. 0008 % 0009 % Example 0010 % pointSetsAverage 0011 % 0012 % See also 0013 % 0014 % 0015 % ------ 0016 % Author: David Legland 0017 % e-mail: david.legland@grignon.inra.fr 0018 % Created: 2011-04-01, using Matlab 7.9.0.529 (R2009b) 0019 % Copyright 2011 INRA - Cepia Software Platform. 0020 0021 % check input 0022 if ~iscell(pointSets) 0023 error('First argument must be a cell array'); 0024 end 0025 0026 % number of sets 0027 nSets = length(pointSets); 0028 0029 % get reference size of coordinates array 0030 set1 = pointSets{1}; 0031 refSize = size(set1); 0032 0033 % allocate memory for result 0034 average = zeros(refSize); 0035 0036 % iterate on point sets 0037 for i = 1:nSets 0038 % get current point set, and check its size 0039 set = pointSets{i}; 0040 if sum(size(set) ~= refSize) > 0 0041 error('All point sets must have the same size'); 0042 end 0043 0044 % cumulative sum of coordinates 0045 average = average + set; 0046 end 0047 0048 % normalize by the number of sets 0049 average = average / nSets;