function findcentroids(image) tic n=16; x=zeros(1,n); y=zeros(1,n); rotateimage=image'; for q=1:n fitcos(sum(image((2048/n)*(q-1)+1:(2048/n)*q,:))); fitcos(sum(rotateimage((2048/n)*(q-1)+1:(2048/n)*q,:))); end toc end function minn=fitcos(imageSum) x=[0:2047]; bestfit=zeros(1,15); for z=0:14 coscurve=mean(imageSum)*2*cosd(x*23.3789-z*23.3789)+mean(imageSum)*2; bestfit(1,z+1)=sum(abs(imageSum-coscurve)); % figure(1) % plot(coscurve(1:500), 'DisplayName', 'test2', 'YDataSource', 'test2'); hold all; plot(imageSum(1:500), 'DisplayName', 'test', 'YDataSource', 'test'); hold off; figure(gcf) % figure(2) % plot(bestfit(1,1:z+1)) end [junk,minn]=min(bestfit); %minn end