Pad by Extension



 
 

Color Convention
 Blue  Comments 
 Red  Generic Terms
 Yelow  Reserved  words and Commands 
 Brown  Defines
  Link  Link to other functions

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipPadImageByExtension
 *
 *  Description : Pads the image by extension.
 *                the size of the kernel indicates the size of the perimeter
 *
 *  Parameters  : src - input image object
 *                kernel - kernel object
 *                rsz - row size of the output image
 *                csz - column size of the output image
 *
 *  Returns     : padded image
 *
 *
 ****************************************************************************/
$generic

  $VsipPadImageByExtension = 'VsipPadImageByExtensionBit',    $IOType = 'uint1',
      $Pad = 'AuxPerimeterBit';
  $VsipPadImageByExtension = 'VsipPadImageByExtensionByte',   $IOType = 'uint8',
      $Pad = 'AuxPerimeterByte';
  $VsipPadImageByExtension = 'VsipPadImageByExtensionInt',    $IOType = 'int32',
      $Pad = 'AuxPerimeterInt';
  $VsipPadImageByExtension = 'VsipPadImageByExtensionFloat',  $IOType = 'float',
      $Pad = 'AuxPerimeterFloat';

$in

$IOType[:,:] $VsipPadImageByExtension($IOType src[:,:], $IOType kernel[:,:],
                              VsipIndexesType rsz, VsipIndexesType csz)
{

  // ***** recover the src and kernel sizes *****
  VsipIndexesType rs, VsipIndexesType cs = extents(src);
  VsipIndexesType rk, VsipIndexesType ck = extents(kernel);

  // ***** test the sizes of the arrays  *****
  assert(((rs > 0) && (cs > 0)),
         "ERROR: Image can not have zero dimention. (",rs,"x",cs,")\n");
  assert(((rk > 0) && (ck > 0)),
         "ERROR: Kernel can not have zero dimention. (",rk,"x",ck,")\n");

  // ***** computes the borders *****
  VsipIndexesAuxType top = rk / 2;
  VsipIndexesAuxType bottom = (rk - 1) / 2;
  VsipIndexesAuxType left = ck / 2;
  VsipIndexesAuxType right = (ck - 1) / 2;
  VsipIndexesAuxType vert = rs+top+bottom;
  VsipIndexesAuxType horz = cs+left+right;

  // ***** test the sizes of the kernel and dest (see header)  *****
  assert(((rsz == rs + top + bottom) && (csz == cs + left + right)),
         "ERROR: Invalid destination size (",rsz,",",csz,").\n");

  // ***** modifies the perimeter by expanding the border *****
  $IOType result[:,:] =
       forVsipIndexesType i, VsipIndexesType j in [vert,horz]
            { VsipIndexesType srci =
                  if (i < top)
                       return(0)
                  elif (i >= top + rs)
                       return(rs - 1)
                  else
                       return(i - top);
             VsipIndexesType srcj =
                  if (j < left)
                       return(0)
                  elif (j >= left + cs)
                       return(cs - 1)
                  else
                       return(j - left);
            }
       return(array(src[srci,srcj]));

} return (result);

$end_generic
 
 

/****************************************************************************
 *
 *  Function    : VsipPadImageByExtensionCx
 *
 *  Description : Pads the image by extension.
 *                the size of the kernel indicates the size of the perimeter
 *
 *  Parameters  : src - input image object
 *                kernel - kernel object
 *                rsz - row size of the output image
 *                csz - column size of the output image
 *
 *  Returns     : padded image
 *
 *
 ****************************************************************************/
$generic

  $VsipPadImageByExtensionCx = 'VsipPadImageByExtensionCxInt',
      $IOType = 'complex int32', $Pad = 'AuxPerimeterCxInt';
  $VsipPadImageByExtensionCx = 'VsipPadImageByExtensionCxFloat',
      $IOType = 'complex float', $Pad = 'AuxPerimeterCxFloat';

$in

$IOType[:,:] $VsipPadImageByExtensionCx($IOType src[:,:], $IOType kernel[:,:],
                              VsipIndexesType rsz, VsipIndexesType csz)
{

  // ***** recover the src and kernel sizes *****
  VsipIndexesType rs, VsipIndexesType cs = extents(src);
  VsipIndexesType rk, VsipIndexesType ck = extents(kernel);

  // ***** test the sizes of the arrays  *****
  assert(((rs > 0) && (cs > 0)),
         "ERROR: Image can not have zero dimention. (",rs,"x",cs,")\n");
  assert(((rk > 0) && (ck > 0)),
         "ERROR: Kernel can not have zero dimention. (",rk,"x",ck,")\n");

  // ***** computes the borders *****
  VsipIndexesAuxType top = rk / 2;
  VsipIndexesAuxType bottom = (rk - 1) / 2;
  VsipIndexesAuxType left = ck / 2;
  VsipIndexesAuxType right = (ck - 1) / 2;
  VsipIndexesAuxType vert = rs+top+bottom;
  VsipIndexesAuxType horz = cs+left+right;

  // ***** modifies the perimeter by expanding the border *****
  $IOType result[:,:] =
       forVsipIndexesType i, VsipIndexesType j in [vert,horz]
            { VsipIndexesType srci =
                  if (i < top)
                       return(0)
                  elif (i >= top + rs)
                       return(rs - 1)
                  else
                       return(i - top);
             VsipIndexesType srcj =
                  if (j < left)
                       return(0)
                  elif (j >= left + cs)
                       return(cs - 1)
                  else
                       return(j - left);
            }
       return(array(src[srci,srcj]));

} return (result);

$end_generic