Home > polypedal > video > newFrameSourceFindPts.m

newFrameSourceFindPts

PURPOSE ^

NEWFRAMESOURCEFINDPTS annotate frames with auto-located point tracks

SYNOPSIS ^

function nSrc = newFrameSourceFindPts( src, thresh, varargin )

DESCRIPTION ^

NEWFRAMESOURCEFINDPTS annotate frames with auto-located point tracks
     nSrc = newFrameSourceFindPts( src, thresh, varargin )
   Automatically locates markers that are bright enough, and in the right
   range of sizes as specified by thresh
 INPUT:
   thresh -- 3x1 -- [luma threshold, lower area limit, upper area limit]
   varargs -- list of regionprops attributes to record for the markers

 $Revision: 1.4 $
 By Shai Revzen, Berkeley 2006

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function nSrc = newFrameSourceFindPts( src, thresh, varargin )
0002 %NEWFRAMESOURCEFINDPTS annotate frames with auto-located point tracks
0003 %     nSrc = newFrameSourceFindPts( src, thresh, varargin )
0004 %   Automatically locates markers that are bright enough, and in the right
0005 %   range of sizes as specified by thresh
0006 % INPUT:
0007 %   thresh -- 3x1 -- [luma threshold, lower area limit, upper area limit]
0008 %   varargs -- list of regionprops attributes to record for the markers
0009 %
0010 % $Revision: 1.4 $
0011 % By Shai Revzen, Berkeley 2006
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

Generated on Mon 02-Aug-2010 16:44:38 by m2html © 2003