Median



 
 

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

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipMedianFilter
 *
 *  Description : Computes the Median Filter of an image
 *                Filter sizes (nxn) 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
 *                n - filter sizes
 *                rsz - row size of the output image
 *                csz - column size of the output image
 *
 *  Returns     : Filtered image
 *
  *
 ****************************************************************************/
$generic

   $VsipMedianFilter = 'VsipMedianFilterBit', $IOType = 'uint1',
        $Per = 'AuxPerimeterBit';
   $VsipMedianFilter = 'VsipMedianFilterByte', $IOType = 'uint8',
        $Per = 'AuxPerimeterByte';
   $VsipMedianFilter = 'VsipMedianFilterInt',  $IOType = 'int32',
        $Per = 'AuxPerimeterInt';
   $VsipMedianFilter = 'VsipMedianFilterFloat',$IOType = 'float',
        $Per = 'AuxPerimeterFloat';

$in

$IOType [:,:] $VsipMedianFilter ($IOType src[:,:], VsipIndexesAuxType n,
                              VsipIndexesType rsz, VsipIndexesType csz)
{

  // ***** Tests the size of the filter (see header) *****
  assert(((n > 1) && ((n % 2) != 0)),
         "ERROR: N must be odd and greater than 1 (",n,").\n");

  // ***** recover the src size *****
  VsipIndexesType r, VsipIndexesType c = extents(src);

  // ***** test the dest image and size (see header) *****
  assert(((r > 0) && (c > 0)),
         "ERROR: Image can not have zero dimension. (",r,"x",c,")\n");
  assert((((rsz == r) && (csz == c)) ||
          ((rsz == r - (n - 1)) && (csz == c - (n - 1))) ||
          ((rsz == r + (n - 1)) && (csz == c + (n - 1)))),
         "ERROR: Invalid destination size (",rsz,",",csz,").\n");

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

  // ***** computes the median filter for each of the dest sizes *****
  $IOType result[:,:] =
       forwindow win[n,n] in persrc
       return (array(array_median(win)));
 

} return(result);

$end_generic