Below is a basic function for finding centre of mass, I can not recall where I stole it from. Try to find the centre of mass in a small region of interest around the peak (instead of using the whole array). Just remember to convert back to whole array co-ordinates to give the final displacement.
function [a,b] = find_com(x,y,A)
% Finds centre of mass of matrix A in x, y index notation
if nargin == 1 A = x; [Ar Ac] = size(A); x = 1:Ac; y = (1:Ar)'; else y = y(:); x = (x(:))'; end
sumA = sum(A(:)); if sumA == 0 a = 0; b = 0; else [row col] = size(A); % Find centroid across columns: temp = A.*(ones(row,1)*x); a = sum(temp(:))/sumA; % Across rows: temp = A.*(y*ones(1,col)); b = sum(temp(:))/sumA; end
"Darren g" wrote in message <email@example.com>... > Hi Phillip, > > Many thanks. Yes. My code is now working after adopting your suggestion for finding the column and row in which the maximum peak intensity is found. For finding the centre of mass of the image to measure the angle of rotation smaller than one degree I am trying the regionprobs but not yet found a way on how to integrate this within my code. Is this the one you mentioned for finding to centre of mass or any other easy way of doing? Your help for this is much appreciated. > > Darren