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 slapplyfilterband
Home > sltoolbox > imgproc > slapplyfilterband.m

slapplyfilterband

PURPOSE ^

SLAPPLYFILTERBAND Applies filter band to filter images in batch

SYNOPSIS ^

function fimgs = slapplyfilterband(imgs, filterband, filtersize, varargin)

DESCRIPTION ^

SLAPPLYFILTERBAND Applies filter band to filter images in batch

 $ Syntax $
   - fimgs = slapplyfilterband(imgs, filterband, filtersize, ...)

 $ Arguments $
   - imgs:         The images to be filtered
   - filterband:   The set of filter band
   - filtersize:   The spec of filter size
   - fimgs:        The filtered images

 $ Description $
   - fimgs = slapplyfilterband(imgs, filterband, filtersize, ...) applies 
     a set of filterbands to images in batch. Suppose there are k filters, 
     imgs is an array of size h0 x w0 x n1 x n2 x ... x nm, then fimgs is
     an array of size h x w x n1 x n2 x ... x nm x k, here h and w are
     respectively the height and width of the filtered image.
     You can further specify the following properties:
       - 'roi':    The ROI in original image (default = 'full')
                   'full'|'confined'|[t, b, l, r]
                   Please refer to slpixneighbors for details on ROI.
       - 'fbform': The form of filterband (default = 'normal')
                   - 'normal':  normal form
                   - 'vec':     vectorized form
     
 $ History $
   - Created by Dahua Lin, on Sep 2nd, 2006

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function fimgs = slapplyfilterband(imgs, filterband, filtersize, varargin)
0002 %SLAPPLYFILTERBAND Applies filter band to filter images in batch
0003 %
0004 % $ Syntax $
0005 %   - fimgs = slapplyfilterband(imgs, filterband, filtersize, ...)
0006 %
0007 % $ Arguments $
0008 %   - imgs:         The images to be filtered
0009 %   - filterband:   The set of filter band
0010 %   - filtersize:   The spec of filter size
0011 %   - fimgs:        The filtered images
0012 %
0013 % $ Description $
0014 %   - fimgs = slapplyfilterband(imgs, filterband, filtersize, ...) applies
0015 %     a set of filterbands to images in batch. Suppose there are k filters,
0016 %     imgs is an array of size h0 x w0 x n1 x n2 x ... x nm, then fimgs is
0017 %     an array of size h x w x n1 x n2 x ... x nm x k, here h and w are
0018 %     respectively the height and width of the filtered image.
0019 %     You can further specify the following properties:
0020 %       - 'roi':    The ROI in original image (default = 'full')
0021 %                   'full'|'confined'|[t, b, l, r]
0022 %                   Please refer to slpixneighbors for details on ROI.
0023 %       - 'fbform': The form of filterband (default = 'normal')
0024 %                   - 'normal':  normal form
0025 %                   - 'vec':     vectorized form
0026 %
0027 % $ History $
0028 %   - Created by Dahua Lin, on Sep 2nd, 2006
0029 %
0030 
0031 %% parse and verify input
0032 
0033 if nargin < 2
0034     raise_lackinput('slapplyfilterband', 2);
0035 end
0036 
0037 imgsiz = size(imgs);
0038 
0039 if ndims(imgs) == 2
0040     n = 1;
0041 else
0042     n = prod(imgsiz(3:end));
0043 end
0044 
0045 [filtsiz, bmg] = slfiltersize(filtersize);
0046 fh = filtsiz(1);
0047 fw = filtsiz(2);
0048 
0049 
0050 opts.roi = 'full';
0051 opts.fbform = 'normal';
0052 opts = slparseprops(opts, varargin{:});
0053 
0054 if ischar(opts.roi)
0055     switch opts.roi
0056         case 'full'
0057             h = imgsiz(1); w = imgsiz(2);
0058         case 'confined'
0059             h = imgsiz(1) - bmg(1) - bmg(2);
0060             w = imgsiz(2) - bmg(3) - bmg(4);
0061         otherwise
0062             error('sltoolbox:invalidarg', ...
0063                 'Invalid ROI option: %s', opts.roi);
0064     end
0065 elseif isnumeric(opts.roi)
0066     h = opts.roi(2) - opts.roi(1) + 1;
0067     w = opts.roi(4) - opts.roi(3) + 1;
0068 else
0069     error('sltoolbox:invalidarg', 'Invalid ROI parameter');
0070 end
0071 
0072 fimgs = [];
0073 if h <= 0 || w <= 0
0074     return;
0075 end
0076 
0077 if ~ismember(opts.fbform, {'normal', 'vec'})
0078     error('sltoolbox:invalidarg', 'Invalid fbform: %s', opts.fbform);
0079 end
0080 
0081 %% Main
0082 
0083 % prepare vectorized filterband
0084 
0085 switch opts.fbform
0086     case 'normal'
0087         if size(filterband, 1) ~= fh || size(filterband, 2) ~= fw
0088             error('sltoolbox:sizmismatch', ...
0089                 'The size of filterband is not consistent.');
0090         end
0091         vfb = slvecfilters(filterband);
0092     case 'vec'
0093         vfb = filterband;
0094 end
0095 k = size(vfb, 1);
0096 
0097 % do filtering
0098 
0099 if n == 1
0100     fimgs = filter_oneimg(imgs, opts.roi, vfb, filtersize, h, w, k);
0101 else
0102     fsiz = [h, w, imgsiz(3:end), k];
0103     chsiz = [h, w, 1, k]; 
0104     fimgs = zeros(h, w, n, k);
0105     for i = 1 : n
0106         curimg = imgs(:,:,i);
0107         curf = filter_oneimg(curimg, opts.roi, vfb, filtersize, h, w, k);        
0108         fimgs(:,:,i,:) = reshape(curf, chsiz);
0109     end
0110     fimgs = reshape(fimgs, fsiz);
0111 end
0112 
0113 
0114 
0115 %% Core function
0116 
0117 function fimg = filter_oneimg(img, roi, vfb, filtersize, h, w, k)
0118     
0119 NBs = slpixneighbors(img, filtersize, 'roi', roi, 'output', 'cols');
0120 fimg = vfb * NBs;  % k x npix
0121 fimg = fimg';     % npix x k
0122 fimg = reshape(fimg, [h, w, k]);
0123 
0124 
0125 
0126             
0127 
0128 
0129 
0130 
0131 
0132 
0133 
0134

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

Contact us at files@mathworks.com