Grayscale Morphological Closing



 
 

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

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipGrayscaleMorphologicalClosing
 *
 *  Description : Computes the Gray Scale morphological Closing
 *                The kernel (nxn) size must be odd and greater than one
 *                The difference between the output (dest) size and
 *                input (src) size must be 0 or -(n - 1)
 *
 *  Parameters  : src - input image object
 *                kernel - nxn kernel object
 *                rsz - row size of the output image
 *                csz - column size of the output image
 *
 *  Returns     : output image
 *
 ****************************************************************************/
$generic

   $VsipGrayscaleMorphologicalClosing = 'VsipGrayscaleMorphologicalClosingByte',
         $IOType = 'uint8', $ErosionFunc = 'VsipGrayscaleMorphologicalErosionByte',
         $DilationFunc = 'VsipGrayscaleMorphologicalDilationByte';
   $VsipGrayscaleMorphologicalClosing = 'VsipGrayscaleMorphologicalClosingInt',
         $IOType = 'int32', $ErosionFunc = 'VsipGrayscaleMorphologicalErosionInt',
         $DilationFunc = 'VsipGrayscaleMorphologicalDilationInt';
   $VsipGrayscaleMorphologicalClosing = 'VsipGrayscaleMorphologicalClosingFloat',
         $IOType = 'float', $ErosionFunc = 'VsipGrayscaleMorphologicalErosionFloat',
         $DilationFunc = 'VsipGrayscaleMorphologicalDilationFloat';
   $VsipGrayscaleMorphologicalClosing = 'VsipGrayscaleMorphologicalClosingDouble',
         $IOType = 'double', $ErosionFunc = 'VsipGrayscaleMorphologicalErosionDouble',
         $DilationFunc = 'VsipGrayscaleMorphologicalDilationDouble';

$in

$IOType[:,:] $VsipGrayscaleMorphologicalClosing($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 image, kernel and dest sizes (see header) *****
  assert(((rs > 0) && (cs > 0)),
         "ERROR: Image can not have zero dimension. (",rs,"x",cs,")\n");
  assert((rk == ck),
         "ERROR: Kernel must be square matrix. (",rk,"x",ck,").\n");
  assert(((rk > 1) && ((rk % 2) != 0)),
         "ERROR: N must be odd and greater than 1 (",rk,").\n");
  assert((((rsz == rs) && (csz == cs)) ||
          ((rsz == rs - (rk - 1)) && (csz == cs - (ck - 1)))),
         "ERROR: Invalid destination size (",rsz,",",csz,").\n");
 

  // ***** computes the closing  *****
  $IOType result0[:,:] = $DilationFunc(src,kernel,rsz,csz);
  $IOType result[:,:] = $ErosionFunc(result0,kernel,rsz,csz);

} return (result);

$end_generic