Blue | Comments |
Red | Generic Terms |
Yelow | Reserved words and Commands |
Brown | Defines |
Link | Link to other functions |
#include "VsipTypes.h"
/****************************************************************************
*
* Function
: VsipCumulativeDensityEqualizationInt
*
* Description :
Computes the cumulative density equalization of an image
*
* Parameters
: src - input image object
*
cdf_src - cumulative density function of the histogram
*
denominator - Value to divide the cumulative density function
*
in order to obtain the probabilities
*
* Returns
: Equalized image
*
* Note
: Range used is max -min +1 instead of max - min as stated in
*
the manual
*
****************************************************************************/
$generic
$VsipCumulativeDensityEqualizationInt
=
'VsipCumulativeDensityEqualizationInt24',
$IOType = 'int32',
$HistType = 'uint24';
$VsipCumulativeDensityEqualizationInt
=
'VsipCumulativeDensityEqualizationInt32',
$IOType = 'int32',
$HistType = 'uint32';
$in
$IOType[:,:]
$VsipCumulativeDensityEqualizationInt ($IOType
src[:,:],
$HistType cdf_src[:],
$HistType
denominator)
{
// ***** recover the
src and cdf_src sizes *****
VsipIndexesType
rs,
VsipIndexesType cs = extents(src);
VsipIndexesType
length = extents(cdf_src);
// ***** test the sizes
of the image and cdf *****
assert(((rs >
0) && (cs > 0)),
"ERROR: Image can not have zero dimension. (",rs,"x",cs,")\n");
assert((length
> 0),
"ERROR: Cdf can not have zero dimension.\n");
assert((denominator
!= 0),
"ERROR: Cdf can not have zero denominator.\n");
// ***** Computes the
max, min and range values of the src *****
$IOType
maxval = array_max(src);
$IOType
minval
= array_min(src);
$IOType
range = maxval - minval +1 ;
// ***** Computes the
equalization using the cumulative density histogram *****
$IOType dest[:,:]
=
for
elem in src
{ // ***** finds the position of the elem in the
cumulative hist *****
VsipIndexesType p = (elem - minval) * length
/ range;
assert(p < length,"ERROR: Index out of
bounds. (",p,")\n");
}
return(array((cdf_src[p]
* range + minval * denominator) / denominator));
} return(dest);
$end_generic
/****************************************************************************
*
* Function
: VsipCumulativeDensityEqualizationFloat
*
* Description :
Computes the cumulative density equalization of an image
*
* Parameters
: src - input image object
*
cdf_src - cumulative density function of the histogram
*
denominator - Value to divide the cumulative density function
*
n order to obtain the probabilities
*
* Returns
: Equalized image
*
****************************************************************************/
$generic
$VsipCumulativeDensityEqualizationFloat='VsipCumulativeDensityEqualizationFloat24',
$IOType = 'float',
$HistType = 'uint24';
$VsipCumulativeDensityEqualizationFloat='VsipCumulativeDensityEqualizationFloat32',
$IOType = 'float',
$HistType = 'uint32';
$in
$IOType[:,:] $VsipCumulativeDensityEqualizationFloat
($IOType src[:,:],
$HistType cdf_src[:], $HistType
denominator)
{
// ***** recover the
src and cdf_src sizes *****
VsipIndexesType
rs,
VsipIndexesType cs = extents(src);
VsipIndexesType
length = extents(cdf_src);
// ***** test the sizes
of the image and cdf *****
assert(((rs >
0) && (cs > 0)),
"ERROR: Image can not have zero dimension. (",rs,"x",cs,")\n");
assert((length
> 0),
"ERROR: Cdf can not have zero dimension.\n");
assert((denominator
!= 0),
"ERROR: Cdf can not have zero denominator.\n");
// ***** Computes the max, min and range
values of the src *****
$IOType maxval
=
array_max(src);
$IOType minval
=
array_min(src);
$IOType range
= AuxMax(1, maxval - minval);
// ***** Computes the
equalization using the cumulative density histogram *****
$IOType dest[:,:]
=
for
elem in src
{ // ***** finds the position of the elem in the
cumulative hist *****
VsipIndexesType p = (elem - minval) * length
/ range;
assert(p < length,"ERROR: Index out of
bounds. (",p,")\n");
}
return(array((cdf_src[p]
* range + minval * denominator) / denominator));
} return(dest);
$end_generic