0001 function nSrc = newFrameSourceFindPts( src, thresh, varargin )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 if nargin<2
0013 thresh=[];
0014 end
0015 if isstruct(thresh)
0016 nSrc.ini = thresh;
0017 else
0018 switch length(thresh)
0019 case 0;
0020 thresh = [0.95,1,100];
0021 case 1;
0022 thresh = [thresh,1,100];
0023 case 2;
0024 thresh = [thresh,thresh(2)*1.1];
0025 case 3;
0026 otherwise
0027 error 'Threshold must be [luma], [luma,area] or [luma,minArea,maxArea]'
0028 end
0029 nSrc.ini.thresh = thresh;
0030 nSrc.ini.spec = varargin;
0031 nSrc.ini.new = @newFromIni;
0032 end
0033 nSrc.cfg = nSrc.ini;
0034 nSrc.op = @doOp;
0035 if ~isempty(src)
0036 sdcr = srcGetDcr(src);
0037 if sdcr.sz(3)>1
0038 error 'Only grayscale images supported'
0039 end
0040 end
0041 return
0042
0043 function src = newFromIni( ini )
0044 src = newFrameSourceFindPts( [],ini.thresh, ini.spec{:} );
0045
0046 function fr = doOp( src, fr )
0047 if ~isempty(fr)
0048 lbl = bwlabel( fr.img > src.ini.thresh(1) );
0049 reg = regionprops( lbl, 'Centroid', 'Area', src.ini.spec{:} );
0050 if ~isempty(reg)
0051 a = [ reg.Area ];
0052 good = (a>=src.ini.thresh(2)) & (a<=src.ini.thresh(3));
0053 reg = reg(good);
0054 if ~isempty(reg)
0055 fr.args.trkPos = vertcat( reg.Centroid ) * [1;i];
0056 fr.args.trkProp = reg;
0057 end
0058 end
0059 if isempty(reg)
0060 fr.args.trkPos = [];
0061 fr.args.trkProp = [];
0062 end
0063 end
0064 return