Histogram



 
 

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

 

#include "VsipTypes.h"

/****************************************************************************
 *
 *  Function    : VsipImageHistogram
 *
 *  Description : Computes the Histogram of an image
 *
 *  Parameters  : src - input image object
 *                lower - lower bound for the histogram
 *                upper - upper bound for the histogram
 *                size - number of buckets of the histogram
 *
 *  Returns     : Image histogram
 *
 *  Note        : Lower bound is inclusive and upper bound is exclusive
 *
 ****************************************************************************/
$generic

   $VsipImageHistogram = 'VsipImageHistogramByte24',   $InType = 'uint8',
        $OutType = 'uint24', $NbucketsType = 'uint9', $AdjType = 'int10';
   $VsipImageHistogram = 'VsipImageHistogramByte32',   $InType = 'uint8',
        $OutType = 'uint32', $NbucketsType = 'uint9',  $AdjType = 'int10';
   $VsipImageHistogram = 'VsipImageHistogramInt24',    $InType = 'int32',
        $OutType = 'uint24', $NbucketsType = 'uint16', $AdjType = 'int32';
   $VsipImageHistogram = 'VsipImageHistogramInt32',    $InType = 'int32',
        $OutType = 'uint32', $NbucketsType = 'uint16', $AdjType = 'int32';
   $VsipImageHistogram = 'VsipImageHistogramFloat24',  $InType = 'float',
        $OutType = 'uint24', $NbucketsType = 'uint16', $AdjType = 'int32';
   $VsipImageHistogram = 'VsipImageHistogramFloat32',  $InType = 'float',
        $OutType = 'uint32', $NbucketsType = 'uint16', $AdjType = 'int32';

$in

$OutType[:] $VsipImageHistogram ($InType src[:,:], $InType lower, $InType upper,
                               $NbucketsType size)
{

  // ***** 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 dimension. (",rs,"x",cs,")\n");

  // ***** Computes the histogram range *****
  $InType range = upper - lower;

  // ***** test the histogram range *****
  assert(((int32)range > 0),
         "ERROR: Range must be grater than zero.\n");

  // ***** Adjust the values of the src for the size and limits desired *****
  $AdjType adjusted_src[:,:] =
       for elem in src
            { $AdjType dif1 = ($AdjType)elem - lower;
             $AdjType dif2 = (dif1 < 0 ? dif1 : (float) dif1 * size / range);
            }
       return(array(dif2));

  // ***** compute the histogram eliminating values below or upper the limits *****
  $OutType hist[:] =
       for elem in adjusted_src dot elem1 in src
            { bool b = (elem < 0 || elem >= size ? false : true);
            }
       return(histogram(elem, size, b));

} return(hist);

$end_generic