0001 function CellsortPlotPCspectrum(fn, CovEvals, pcuse)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 if nargin<3
0017 pcuse = [];
0018 end
0019
0020 [pixw,pixh] = size(imread(fn,1));
0021 npix = pixw*pixh;
0022 nt = tiff_frames(fn);
0023
0024
0025 p1 = npix;
0026 q1 = nt;
0027 q = max(p1,q1);
0028 p = min(p1,q1);
0029 sigma = 1;
0030 lmax = sigma*sqrt(p+q + 2*sqrt(p*q));
0031 lmin = sigma*sqrt(p+q - 2*sqrt(p*q));
0032 lambda = [lmin: (lmax-lmin)/100.0123423421: lmax];
0033 rho = (1./(pi*lambda*(sigma^2))).*sqrt((lmax^2-lambda.^2).*(lambda.^2-lmin^2));
0034 rho(isnan(rho)) = 0;
0035 rhocdf = cumsum(rho)/sum(rho);
0036 noiseigs = interp1(rhocdf, lambda, [p:-1:1]'/p, 'linear', 'extrap').^2 ;
0037
0038
0039 normrank = min(nt-1,length(CovEvals));
0040 pca_norm = CovEvals*noiseigs(normrank) / (CovEvals(normrank)*noiseigs(1));
0041
0042 clf
0043 plot(pca_norm, 'o-', 'Color', [1,1,1]*0.3, 'MarkerFaceColor', [1,1,1]*0.3, 'LineWidth',2)
0044 hold on
0045 plot(noiseigs / noiseigs(1), 'b-', 'LineWidth',2)
0046 plot(2*noiseigs / noiseigs(1), 'b--', 'LineWidth',2)
0047 if ~isempty(pcuse)
0048 plot(pcuse, pca_norm(pcuse), 'rs', 'LineWidth',2)
0049 end
0050 hold off
0051 formataxes
0052 set(gca,'XScale','log','YScale','log', 'Color','none')
0053 xlabel('PC rank')
0054 ylabel('Normalized variance')
0055 axis tight
0056 if isempty(pcuse)
0057 legend('Data variance','Noise floor','2 x Noise floor')
0058 else
0059 legend('Data variance','Noise floor','2 x Noise floor','Retained PCs')
0060 end
0061
0062 fntitle = fn;
0063 fntitle(fn=='_') = ' ';
0064 title(fntitle)
0065
0066 function formataxes
0067
0068 set(gca,'FontSize',12,'FontWeight','bold','FontName','Helvetica','LineWidth',2,'TickLength',[1,1]*.02,'tickdir','out')
0069 set(gcf,'Color','w','PaperPositionMode','auto')
0070
0071
0072
0073 function j = tiff_frames(fn)
0074
0075
0076
0077
0078
0079
0080
0081 j = length(imfinfo(fn));
0082 end