Principal Component Analysis for Point Spread Function Measurement and Implementation of different scaling in each dimension
4 views (last 30 days)
Show older comments
I made 3D measurements of beads (small spheres) with a microscope for getting the point spread function (psf). This can be approximated with a 3D-Gauß. I need the 3 main axes for this ellipsoid. So principal component analysis (pca) seems right for this task. The goal is to fit three 1D Gaussians through this axes.
What I have right now: Produce Sample Data:
%%produce sample data with 3D Gauß
data=zeros(200,200,200);
a=5;
b=2;
x0=100;
sigmax=1;
y0=100;
sigmay=5;
z0=100;
sigmaz=8;
alpha=1;
beta=0;
gamma=0;
for z=1:200
for x=1:200
for y=1:200
data(x,y,z)= a*exp(-...
(...
((-(z-z0)*sin(beta)+cos(beta)*((x-x0)*cos(gamma)-(y-y0)*sin(gamma))))^2/(2*sigmax^2)+...
((cos(alpha)*((y-y0)*cos(gamma)+(x-x0)*sin(gamma))-sin(alpha)*((z-z0)*cos(beta)+sin(beta)*((x-x0)*cos(gamma)-(y-y0)*sin(gamma)))))^2/(2*sigmay^2)+...
((sin(alpha)*((y-y0)*cos(gamma)+(x-x0)*sin(gamma))+cos(alpha)*((z-z0)*cos(beta)+sin(beta)*((x-x0)*cos(gamma)-(y-y0)*sin(gamma)))))^2/(2*sigmaz^2)...
))+b;
end
end
end
meanBead=data;
This produces a 3D-Gaussian which is rotated a bit. The pixel size in each direction can be different so we have to take the scaling into account.
metadata.scale.x=1;
metadata.scale.y=1;
metadata.scale.z=1;
Prepare the data for pca:
%get threshold of meanBead
[out, meanThr]=threshold(meanBead,'triangle');
%preallocate memory
PCAData=zeros(size(meanBead,1)*size(meanBead,2)*size(meanBead,3),4);
[xind, yind, zind]= ind2sub(size(data),1:numel(data));
PCAData(:,1:3) = cat(1,xind,yind,zind)';
PCAData(:,4) = meanBead(:);
%Delete rows with NaN in it
PCAData(isnan(PCAData(:,4)), :) = [];
%weigth the xyz values by intensity and scaling
PCADataWeights=PCAData(:,4);
PCAData=[PCAData(:,1)*metadata.scale.x, PCAData(:,2)*metadata.scale.y, PCAData(:,3)*metadata.scale.z];
%substract meanvalue of coordinates
PCAData = bsxfun(@minus,PCAData,mean(PCAData,1));
%calculate covariance matrix
[U,~,PCAVar]=pca(PCAData,'Weights',PCADataWeights);
The three columns of U are the directions with the most variance. They are orthogonal and normed. This script works totally fine, until the scaling changes slightly. If we change one value from 1 to 0.99 the vectors of U will get the normal axis (0,0,1) (0,1,0).. and so on.
The question now is, how do I need to take the scaling into account and implement it the right way here?
Thank you very much
3 Comments
Answers (0)
See Also
Categories
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!