extractCenters.m 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. fprintf("Sigma %f\n",sigma2);
  8. [~,~,~,nd]=size(data);
  9. fcenters=zeros(nr,nd);
  10. na2=int8(0.5*(na+1));
  11. fs=zeros(nr,1);
  12. for vi=1:nr
  13. fv=v0(vi,2:4);%zero beased coordinates
  14. fi=v0(vi,1)
  15. idx0=int8(fv);
  16. idx=idx0;
  17. for i=1:na
  18. idx(1)=idx0(1)+i-na2;
  19. for j=1:na
  20. idx(2)=idx0(2)+j-na2;
  21. for k=1:na
  22. idx(3)=idx0(3)+k-na2;
  23. df=double(idx)-fv;
  24. fd=df*df';
  25. fw=exp(-0.5*fd/sigma2);
  26. fcenters(fi,:)=fcenters(fi,:)+fw*reshape(data(idx(1)+1,idx(2)+1,idx(3)+1,:),1,[]);
  27. fs(fi)=fs(fi)+fw;
  28. end
  29. end
  30. end
  31. end
  32. qS=fs*ones(size(fcenters(1,:)));
  33. fcenters=fcenters./qS;
  34. end