Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sl2dpca_apply
Home > sltoolbox > subspace_ex > sl2dpca_apply.m

sl2dpca_apply

PURPOSE ^

SL2DPCA_APPLY Applies 2D PCA onto a set of matrices to extract features

SYNOPSIS ^

function Y = sl2dpca_apply(Mm, PL, PR, data, matsiz, n)

DESCRIPTION ^

SL2DPCA_APPLY Applies 2D PCA onto a set of matrices to extract features

 $ Syntax $
   - Y = sl2dpca_apply(Mm, PL, PR, data, matsiz, n)

 $ Description $
   - Mm:           the mean matrix
   - PL:           the left projection matrix
   - PR:           the right projection matrix
   - data:         the matrix samples or the cell array of filenames
   - matsiz:       the original matrix size
   - n:            the number of samples
   - Y:            the extracted 2D features

 $ Description $
   - Y = sl2dpca_apply(data, Mm, PL, PR) extracts 2D features for 
     the matrices given in data, in either a 3D array or a set of
     array filenames. Suppose the original matrix size is d1 x d2,
     PL be d1 x k1, PR be d2 x k2, then the feature matrix would be
     of size k1 x k2. Y is a k1 x k2 x n array.

 $ History $
   - Created by Dahua Lin, on Jul 31st, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • slreadarray SLREADARRAY Reads an array from an array file
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function Y = sl2dpca_apply(Mm, PL, PR, data, matsiz, n)
0002 %SL2DPCA_APPLY Applies 2D PCA onto a set of matrices to extract features
0003 %
0004 % $ Syntax $
0005 %   - Y = sl2dpca_apply(Mm, PL, PR, data, matsiz, n)
0006 %
0007 % $ Description $
0008 %   - Mm:           the mean matrix
0009 %   - PL:           the left projection matrix
0010 %   - PR:           the right projection matrix
0011 %   - data:         the matrix samples or the cell array of filenames
0012 %   - matsiz:       the original matrix size
0013 %   - n:            the number of samples
0014 %   - Y:            the extracted 2D features
0015 %
0016 % $ Description $
0017 %   - Y = sl2dpca_apply(data, Mm, PL, PR) extracts 2D features for
0018 %     the matrices given in data, in either a 3D array or a set of
0019 %     array filenames. Suppose the original matrix size is d1 x d2,
0020 %     PL be d1 x k1, PR be d2 x k2, then the feature matrix would be
0021 %     of size k1 x k2. Y is a k1 x k2 x n array.
0022 %
0023 % $ History $
0024 %   - Created by Dahua Lin, on Jul 31st, 2006
0025 %
0026 
0027 %% Parse and verify input arguments
0028 
0029 if nargin < 6
0030     raise_lackinput('sl2dpca_apply', 6);
0031 end
0032 
0033 matsiz = matsiz(:)';
0034 if length(matsiz) ~= 2
0035     error('sltoolbox:invalidarg', ...
0036         'matsiz should be a 2-elem vector');
0037 end
0038 
0039 if ~isequal(size(Mm), matsiz)
0040     error('sltoolbox:sizmismatch', ...
0041         'the sample size does not match the model');
0042 end
0043 d1 = matsiz(1);
0044 d2 = matsiz(2);
0045 
0046 if size(PL, 1) ~= d1 || size(PR, 1) ~= d2
0047     error('sltoolbox:sizmismatch', ...
0048         'the size of projection matrices are illegal');
0049 end
0050 
0051 %% Compute
0052 
0053 if isnumeric(data)
0054     
0055     if size(data, 3) ~= n
0056         error('sltoolbox:sizmismatch', ...
0057             'The number of samples is not as specified');
0058     end
0059     
0060     Y = computeY(data, Mm, PL, PR);
0061     
0062 elseif iscell(data)
0063     
0064     Y = zeros(size(PL, 2), size(PR, 2), n);
0065     
0066     nfiles = length(data);
0067     cf = 0;
0068     for i = 1 : nfiles
0069         curdata = slreadarray(data{i});
0070         curn = size(curdata, 3);
0071         Y(:,:,cf+1:cf+curn) = computeY(curdata, Mm, PL, PR);
0072         cf = cf + curn;
0073     end
0074     
0075 else
0076     error('sltoolbox:invalidarg', ...
0077         'data should be a numeric array or a cell array of filenames');    
0078  
0079 end
0080 
0081 
0082 %% Core compute function
0083 
0084 function Y = computeY(X, Mm, PL, PR)
0085 
0086 n = size(X, 3);
0087 Y = zeros(size(PL, 2), size(PR, 2), n);
0088 PLT = PL';
0089 
0090 for i = 1 : n
0091     Y(:,:,i) = PLT * (X(:,:,i) - Mm) * PR;
0092 end
0093 
0094 
0095 
0096 
0097 
0098     
0099 
0100 
0101 
0102

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com