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

slcalcpadsize

PURPOSE ^

SLCALCPADSIZE Calculates the size of padding

SYNOPSIS ^

function [paddedsiz, roi, bmg] = slcalcpadsize(varargin)

DESCRIPTION ^

SLCALCPADSIZE Calculates the size of padding

 $ Syntax $
   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, bmg0)
   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, roi0, bmg0)

 $ Arguments $
   - imgsize:      The whole size of the image
   - roi0:         The rectangle of the target region 
                   in the form of [t, b, l, m]
   - bmg0:         The required boundary margins for the target region
                   in the form [tm, bm, lm, rm]
   - paddedsize:   The size of the padded image
   - roi:          The rectangle of the target region in the padded image
   - bmg:          The boundary margins for padding on the whole image

 $ Description $
   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, bmg0) calculates
     the padding size when the target region is the whole image.

   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, roi0, bmg0) calculates
     the padding size with the target region explicitly specified.

 $ History $
   - Created by Dahua Lin, on Sep 1st, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • sltakeval SLTAKEVAL Extracts the values in an array/cell array to output
This function is called by:
  • slpixneighbors SLPIXNEIGHBORS Extracts the neighborhood of pixels from an image

SOURCE CODE ^

0001 function [paddedsiz, roi, bmg] = slcalcpadsize(varargin)
0002 %SLCALCPADSIZE Calculates the size of padding
0003 %
0004 % $ Syntax $
0005 %   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, bmg0)
0006 %   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, roi0, bmg0)
0007 %
0008 % $ Arguments $
0009 %   - imgsize:      The whole size of the image
0010 %   - roi0:         The rectangle of the target region
0011 %                   in the form of [t, b, l, m]
0012 %   - bmg0:         The required boundary margins for the target region
0013 %                   in the form [tm, bm, lm, rm]
0014 %   - paddedsize:   The size of the padded image
0015 %   - roi:          The rectangle of the target region in the padded image
0016 %   - bmg:          The boundary margins for padding on the whole image
0017 %
0018 % $ Description $
0019 %   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, bmg0) calculates
0020 %     the padding size when the target region is the whole image.
0021 %
0022 %   - [paddedsiz, roi, bmg] = slcalcpadsize(imgsize, roi0, bmg0) calculates
0023 %     the padding size with the target region explicitly specified.
0024 %
0025 % $ History $
0026 %   - Created by Dahua Lin, on Sep 1st, 2006
0027 %
0028 
0029 %% parse and verify input arguments
0030 
0031 if nargin < 2
0032     raise_lackinput('slcalcpadsize', 2);
0033 end
0034 
0035 imgsize = varargin{1};
0036 h0 = imgsize(1); w0 = imgsize(2);
0037 if nargin == 2 
0038     roi0 = [1, h0, 1, w0];
0039     bmg0 = varargin{2};
0040 else 
0041     if isempty(varargin{2})
0042         roi0 = [1, h0, 1, w0];
0043     else
0044         roi0 = varargin{2};
0045     end
0046     bmg0 = varargin{3};
0047 end
0048 
0049 %% compute padding boundary
0050 
0051 [t0, b0, l0, r0] = sltakeval(roi0);
0052 inner_mgs = [t0 - 1, h0 - b0, l0 - 1, w0 - r0];
0053 
0054 bmg = max(bmg0 - inner_mgs, 0);
0055 
0056 %% compute padded size
0057 
0058 ph = h0 + bmg(1) + bmg(2);
0059 pw = w0 + bmg(3) + bmg(4);
0060 paddedsiz = [ph, pw];
0061 
0062 %% compute roi in padded image
0063 
0064 roi = [bmg(1) + t0, bmg(1) + b0, bmg(3) + l0, bmg(3) + r0];
0065

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

Contact us at files@mathworks.com