forked from aludnam/MATLAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifyW_localmin.m~
45 lines (40 loc) · 1.74 KB
/
classifyW_localmin.m~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function [onesource,twosources,edgedist,nlocmax]=classifyW_localmin(w,nx,ny,psf,threshold,displayimage)
% [onesource,twosources,edgedist,nlocmax]=classifyW_localmin(w,nx,ny,psf,threshold,displayimage)
% Classify the the estimated sources w (nx*ny X ncomp matrix).
%
% Input:
% w - (nx*ny X ncomp) matrix of NMF estimated sources
% nx,ny -> dimensions of the 2D image of the sources
% threshold -> fraction of the global maximum of each w_k above which the
% local miminum must be to be considered for evaluation (default: threshold=.5)
% psf -> image of the point spread function OR struct containing field psf.NA,psf.lambda,psf.pixelisze
% displayimage -> display the image of classified sources.
%
% Output:
% onesource -> binary vector indicating 1 source
% twosources -> binary vector indicating 2 sources
% edgedist -> distance of the local maximum from the edge
% nlocmax -> numbe of local maxima in each
%
% Example:
% [onesource,twosources,edgedist,nlocmax]=classifyW_localmin(res.w(:,1:end-1),peval.nx,peval.ny,p,0.5,1)
if isstruct(psf)
psf = PSFGEN('lambda', psf.lambda, 'na', psf.NA, 'pixelsize', psf.pixelsize, 'sizevec', [nx ny], 'method', 'airy', 'nphot',1, 'verbose',0);
fprintf('Generating PSF...\n')
end
if ~exist('threshold','var')
threshold = 0.5;
end
if ~exist('threshold','var')
threshold = 0.5;
end
[mwcn,wpixc,globmax,edgedist]=localminW(w,nx,ny,psf);
nlocmax = sum(mwcn>threshold); % number of local maxima, thresholed by 50% of the global maximum
onesource=nlocmax==1;
twosources=nlocmax==2;
if displayimage
framecolvec=(edgedist'<2)+(2*onesource);
framecolvec(framecolvec==1)=0;
framecolvec=framecolvec+twosources;
figure; imstiled(reshape(w,nx,ny,size(w,2)),[],'gray',[1:size(w,2)],[],[],framecolvec)
end