Home > polypedal > video > newFrameSourceCorrectedCam.m

newFrameSourceCorrectedCam

PURPOSE ^

NEWFRAMESOURCECORRECTEDCAM frame source that applies camera aberration

SYNOPSIS ^

function src = newFrameSourceCorrectedCam( src, cam, scl, gsz )

DESCRIPTION ^

NEWFRAMESOURCECORRECTEDCAM frame source that applies camera aberration
 correction specified in the cam object (from extendCamModel). 
       src = newFrameSourceCorrectedCam( src, cam, scl, gsz )
 scl provides a scale value such that each 1x1 grid box in the reference 
 grid gets scl x scl pixels in the output. 
 gsz (optional) is size of grid to allocate output for
 $Revision: 1.2 $
 By Shai Revzen, Berkeley 2008

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function src = newFrameSourceCorrectedCam( src, cam, scl, gsz )
0002 %NEWFRAMESOURCECORRECTEDCAM frame source that applies camera aberration
0003 % correction specified in the cam object (from extendCamModel).
0004 %       src = newFrameSourceCorrectedCam( src, cam, scl, gsz )
0005 % scl provides a scale value such that each 1x1 grid box in the reference
0006 % grid gets scl x scl pixels in the output.
0007 % gsz (optional) is size of grid to allocate output for
0008 % $Revision: 1.2 $
0009 % By Shai Revzen, Berkeley 2008
0010   if nargin<4, gsz = [0 0]; end
0011   % Build the image transformation from the cam object
0012   ini.xfm = maketform('custom',2,2,cam.rvs,cam.fwd,cam.par);
0013   % Store scaling
0014   ini.scl = scl;
0015   % Cooridnate range to map
0016   xmin = min(floor(real(cam.zref)-0.1));
0017   xmax = max(ceil(real(cam.zref)+0.1));
0018   ymin = min(floor(imag(cam.zref)-0.1));
0019   ymax = max(ceil(imag(cam.zref)+0.1));
0020   % Bounding box
0021   ini.bbox = [xmin ymin; max([xmax+1 ymax; gsz])] * scl;
0022   ini.bbox([1,3]) = max([1 1; ini.bbox([1,3])]);
0023   % Image size
0024   ini.sz = ini.bbox([4 2]);
0025   src = corrCamFromIni( src, ini );
0026 return
0027 
0028 function src = corrCamFromIni( src, ini )
0029   src.ini = ini;
0030   src.sz = ini.sz;
0031   src.op = @getCorrectCam;
0032   src.xfmargs = @notImp;
0033   src.rxfmargs = @notImp;
0034   
0035   % Scaling transformation from ref grid to pixels
0036   scld = maketform('affine', ...
0037       [0,0; 1,0; 0,1],...
0038       [ini.scl,0; ini.scl*2,0; ini.scl,ini.scl] );
0039   % Composite transformation including scaling
0040   src.cfg.xfm = maketform('composite', [scld,ini.xfm] );
0041   src.cfg.bbox = src.ini.bbox;
0042   src.cfg.pad = zeros(src.sz);
0043   src.roi = @corrCamROI;
0044 return
0045 
0046 function src = corrCamROI( src, obox );
0047   obox = reshape(obox,2,2);
0048   obox = [max([floor(obox(1,:)); src.ini.bbox(1,:)]); ...
0049           min([ceil(obox(2,:)); src.ini.bbox(2,:)]) ];
0050   src.cfg.bbox = obox;
0051 return
0052 
0053 function notImp( varargin )
0054   error('correctedCam:notimpl','argument transformations not implemeted');
0055 return
0056 
0057 function fr = getCorrectCam( src, fr )
0058     if ~isempty(fr)
0059         sz = src.cfg.bbox([4 2])-src.cfg.bbox([3 1]);
0060         if all(sz>1)
0061             img = imtransform( fr.img, src.cfg.xfm,...
0062                 'xdata', src.cfg.bbox(:,1).',...
0063                 'ydata', src.cfg.bbox(:,2).',...
0064                 'size', sz );
0065             src.cfg.pad(...
0066                 src.cfg.bbox(1,2):src.cfg.bbox(2,2)-1,...
0067                 src.cfg.bbox(1,1):src.cfg.bbox(2,1)-1 ) = img;
0068             fr.img = src.cfg.pad;
0069         end
0070     end
0071 return
0072

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