Shrink



 
 

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

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipShrink
 *
 *  Description : Shrink the image by using one of the following methods
 *                (max,min,avg,median) and a 3x3 window
 *
 *  Parameters  : src - input image object
 *                method - method to be used in the shrinking
 *                0- min
 *                1- max
 *                2- mean
 *                3- median
 *
 *  Returns     : Shrank image
 *
 *
 ****************************************************************************/
$generic

   $VsipShrink = 'VsipShrinkBit',    $IOType = 'uint1', $Cast = '(uint5[:,:])';
   $VsipShrink = 'VsipShrinkByte',   $IOType = 'uint8', $Cast = '(uint12[:,:])';
   $VsipShrink = 'VsipShrinkInt',    $IOType = 'int32', $Cast = '';
   $VsipShrink = 'VsipShrinkFloat',  $IOType = 'float', $Cast = '';
   $VsipShrink = 'VsipShrinkDouble', $IOType = 'double',$Cast = '';

$in

$IOType[:,:] $VsipShrink($IOType src[:,:], uint2 method)
{

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

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

  // ***** Tests the requested method *****
  assert(((method >= 0) && (method <= 3)),
         "ERROR: Method unknown.\n");

  // ***** computes the method for an 3x3 window and returns the result *****

  $IOType result[:,:] =
       switch (method)
           { case 0: { $IOType result0[:,:] =
                            for window win[3,3] in src step (3,3)
                           return(array(array_min(win)));
                     } return (result0)
             case 1: { $IOType result0[:,:] =
                            for window win[3,3] in src step (3,3)
                            return(array(array_max(win)));
                     } return (result0)
             case 2: { $IOType result0[:,:] =
                            for window win[3,3] in src step (3,3)
                             return(array(array_mean($Cast win)));
                     } return (result0)
             case 3: { $IOType result0[:,:] =
                           for window win[3,3] in src step (3,3)
                           return(array(array_median(win)));
                     } return (result0)
             default: return(src)
            };

} return (result);

$end_generic