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 slgetinterpkernel
Home > sltoolbox > interp > slgetinterpkernel.m

slgetinterpkernel

PURPOSE ^

SLGETINTERPKERNEL Gets the interpolation kernel function

SYNOPSIS ^

function [f, r] = slgetinterpkernel(kername)

DESCRIPTION ^

SLGETINTERPKERNEL Gets the interpolation kernel function

 $ Syntax $
   - [f, r] = slgetinterpkernel(kername)
   
 $ Arguments $
   - kername:      The name of the interpolation kernel
   - f:            The function handle to the kernel
   - r:            The effective radius of the kernel

 $ Description $
   - [f, r] = slgetinterpkernel(kername) gets the function handle to 
     an interpolation kernel and the corresponding effective radius. 
     The supported kernel include:
       - 'nearest':         The nearest neighbor interpolation
       - 'linear':          The linear interpolation
       - 'cubic':           The cubic interpolation
     For generality, the kername can also be a cell array as
     {f, r}. Then the function directly extracts them to output.
     Here are the formulas for the kernels:
       - 'nearest':        f(x) = 1, when |x| <= 0.5
                                  0, when |x| > 0.5 
       - 'linear':         f(x) = 1 - |x|, when |x| <= 1
                                  0,       when |x| > 1
       - 'cubic':          f(x) = 1 - 2|x|^2 + |x|^3,        when |x| <= 1
                                  4 - 8|x| + 5|x|^2 - |x|^3, when 1 < |x| <= 2
                                  0,                         when |x| > 2

 $ Remarks $
   - All the kernel functions are vectorized, so they all support
     both scalar input and array input of any dimension.
   - The kernel functions are legal only within the effective radius,
     in the outside region, the produced values are undefined (not
     necessary zero). Such a design is for efficiency, so it is the
     invoker's responsibility to guarantee the input is in valid 
     range.

 $ History $
   - Created by Dahua Lin, on Sep 2nd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • slimginterp SLIMGINTERP Performs image based interpolation

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [f, r] = slgetinterpkernel(kername)
0002 %SLGETINTERPKERNEL Gets the interpolation kernel function
0003 %
0004 % $ Syntax $
0005 %   - [f, r] = slgetinterpkernel(kername)
0006 %
0007 % $ Arguments $
0008 %   - kername:      The name of the interpolation kernel
0009 %   - f:            The function handle to the kernel
0010 %   - r:            The effective radius of the kernel
0011 %
0012 % $ Description $
0013 %   - [f, r] = slgetinterpkernel(kername) gets the function handle to
0014 %     an interpolation kernel and the corresponding effective radius.
0015 %     The supported kernel include:
0016 %       - 'nearest':         The nearest neighbor interpolation
0017 %       - 'linear':          The linear interpolation
0018 %       - 'cubic':           The cubic interpolation
0019 %     For generality, the kername can also be a cell array as
0020 %     {f, r}. Then the function directly extracts them to output.
0021 %     Here are the formulas for the kernels:
0022 %       - 'nearest':        f(x) = 1, when |x| <= 0.5
0023 %                                  0, when |x| > 0.5
0024 %       - 'linear':         f(x) = 1 - |x|, when |x| <= 1
0025 %                                  0,       when |x| > 1
0026 %       - 'cubic':          f(x) = 1 - 2|x|^2 + |x|^3,        when |x| <= 1
0027 %                                  4 - 8|x| + 5|x|^2 - |x|^3, when 1 < |x| <= 2
0028 %                                  0,                         when |x| > 2
0029 %
0030 % $ Remarks $
0031 %   - All the kernel functions are vectorized, so they all support
0032 %     both scalar input and array input of any dimension.
0033 %   - The kernel functions are legal only within the effective radius,
0034 %     in the outside region, the produced values are undefined (not
0035 %     necessary zero). Such a design is for efficiency, so it is the
0036 %     invoker's responsibility to guarantee the input is in valid
0037 %     range.
0038 %
0039 % $ History $
0040 %   - Created by Dahua Lin, on Sep 2nd, 2006
0041 %
0042 
0043 %% Main skeleton
0044 
0045 if ischar(kername)
0046     switch kername
0047         case 'nearest'
0048             f = @(x) 1;
0049             r = 0.5;
0050         case 'linear'
0051             f = @(x) 1 - abs(x);
0052             r = 1;
0053         case 'cubic'
0054             f = @cubic_interpolant;
0055             r = 2;
0056         otherwise
0057             error('sltoolbox:invalidarg', ...
0058                 'The interpolation kernel name is unsupported: %s', kername);
0059     end
0060 elseif iscell(kername)
0061     f = kername{1};
0062     r = kername{2};
0063     if ~isa(f, 'funtion_handle')
0064         error('sltoolbox:invalidarg', ...
0065             'The interpolation kernel is invalid');
0066     end
0067 else
0068     error('sltoolbox:invalidarg', ...
0069             'The interpolation kernel is invalid');
0070 end
0071         
0072 
0073 
0074 %% Core functions
0075 
0076 function y = cubic_interpolant(x)
0077 
0078 x = abs(x);
0079 p1 = 1 - x .* x .* (2 - x);
0080 p2 = 4 + x .* (-8 + x .* (5 - x));
0081 b1 = x < 1;
0082 b2 = true - b1;
0083 y = p1 .* b1 + p2 .* b2;
0084 
0085 
0086         
0087         
0088         
0089         
0090

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

Contact us at files@mathworks.com