extractCenters.m 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. function fcenters=extractCenters(data,v0,sigma2,na)
  2. %extract response by segment centered around point v0, taking weights of surrounding pixels as gaussian with sigma2
  3. %nd is number of time samples
  4. %v0 is nr by 3 matrix of centers
  5. %na is the neighborhood size (in pixels, should work great for odd na)
  6. nr=size(v0,1);
  7. [~,~,~,nd]=size(data);
  8. fcenters=zeros(nr,nd);
  9. na2=int8(0.5*(na+1));
  10. for fi=1:nr
  11. fs=0;
  12. fv=v0(fi,:);%zero beased coordinates
  13. idx0=int8(fv);
  14. idx=idx0;
  15. for i=1:na
  16. idx(1)=idx0(1)+i-na2;
  17. for j=1:na
  18. idx(2)=idx0(2)+j-na2;
  19. for k=1:na
  20. idx(3)=idx0(3)+k-na2;
  21. df=double(idx)-fv;
  22. fd=df*df';
  23. fw=exp(-0.5*fd/sigma2);
  24. fcenters(fi,:)=fcenters(fi,:)+fw*reshape(data(idx(1)+1,idx(2)+1,idx(3)+1,:),1,[]);
  25. fs=fs+fw;
  26. end
  27. end
  28. end
  29. fcenters(fi,:)=fcenters(fi,:)/fs;
  30. end
  31. end