Roberts Gradient Edge Detection



 
 

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

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipRobertsGradienteEdgeDetection
 *
 *  Description : Computes the Roberts Gradient of the edges
 *                The difference between the output (dest) size and
 *                input (src) size must be 0 or +/- 2
 *
 *  Parameters  : src - input image object
 *                rsz - row size of the output image
 *                csz - column size of the output image
 *
 *  Returns     : Roberts gradient image
 *
 *  Note        : The byte version gives overflow
 *
 ****************************************************************************/
$generic

   $VsipRobertsGradienteEdgeDetection = 'VsipRobertsGradienteEdgeDetectionBit',
        $InType = 'uint1',  $OutType = 'uint8', $CompType = 'int12',
        $SqrtFunc = 'sq_root32', $Per = 'AuxPerimeterBit';
   $VsipRobertsGradienteEdgeDetection = 'VsipRobertsGradienteEdgeDetectionByte',
        $InType = 'uint8',  $OutType = 'uint8', $CompType = 'int25',
        $SqrtFunc = 'sq_root32', $Per = 'AuxPerimeterByte';
   $VsipRobertsGradienteEdgeDetection = 'VsipRobertsGradienteEdgeDetectionInt',
        $InType = 'int32',  $OutType = 'int32', $CompType = 'int32',
        $SqrtFunc = 'sq_root32', $Per = 'AuxPerimeterInt';
   $VsipRobertsGradienteEdgeDetection = 'VsipRobertsGradienteEdgeDetectionFloat',
        $InType = 'float',  $OutType = 'float', $CompType = 'float',
        $SqrtFunc = 'sqrt', $Per = 'AuxPerimeterFloat';

$in

$OutType[:,:] $VsipRobertsGradienteEdgeDetection($InType src[:,:],
                                               VsipIndexesType rsz,
                                               VsipIndexesType csz)
{

  // ***** recover the src size *****
  VsipIndexesType rs, VsipIndexesType cs = extents(src);

  // ***** test the size of the image and dest (see header)  *****
  assert(((rs > 1) && (cs > 1)),
         "ERROR: Image must be at least 2x2. (",rs,"x",cs,")\n");
  assert((((rsz == rs) && (csz == cs)) ||
          ((rsz == rs - 1) && (csz == cs - 1)) ||
          ((rsz == rs + 1) && (csz == cs + 1))),
         "ERROR: Invalid destination size (",rsz,",",csz,").\n");

  // ***** defines the Roberts' masks *****
  int3 mask1[2,2] = {{-1,0}, {0,1}};
  int3 mask2[2,2] = {{0,-1}, {1,0}};

  // ***** creates the necessary perimeter around src *****
  $OutType persrc[:,:] =
       if (rsz == rs - 1)
          return(src)
       elif (rsz == rs)
          return($Per(src, 1, 0, 1, 0, 0))
       else
          return($Per(src, 1, 1, 1, 1, 0));
 

  // ***** computes the gradient for the modified src  *****
  $OutType result[:,:] =
       forwindow win[2,2] in persrc
            { // ***** computes the edge for both masks  and returns *****
              // ***** the sqr root of the sum of their squares      *****
              $CompType edg1 =
                 for elem1 in win dot elem2 in mask1
                 return(sum(($CompType)elem1*elem2 ));
              $CompType edg2 =
                 for elem3 in win dot elem4 in mask2
                 return(sum(($CompType)elem3*elem4));
            }
       return(array($SqrtFunc(edg1*edg1+edg2*edg2)));

} return (result);

$end_generic