Blue | Comments |
Red | Generic Terms |
Yelow | Reserved words and Commands |
Brown | Defines |
Link | Link to other functions |
#include "VsipTypes.h"
/****************************************************************************
*
* Function
: VsipImageStatistics
*
* Description :
Compute the specified statisticss for the image
*
The statistics are specified by a 12 bit variable
*
each bit turns on (1) or off (0) the correspondent
*
Statistics. The statistics defined,in order, are:
*
00 - Mean
*
01 - Variance
*
02 - Root Mean Square
*
03 - Skewness
*
04 - Kurtosis
*
05 - Integral (sum of the intensities)
*
06 - Positive Integral (sum of positive intensities)
*
07 - Negative Integral (sum of negative intensities)
*
08 - Minimun
*
09 - Maximum
*
10 - Median Value
*
11 - Number of Zeros
*
* Parameters
: src - input image object
*
statistics - binary specification of the desired statistics
*
* Returns
: vector of the result of the statistics
*
****************************************************************************/
$generic
$VsipImageStatistics
= 'VsipImageStatisticsBit', $InType
= 'uint1',
$OutType
= 'float', $CastArray
= '(uint32[:,:])', $CastVal
= '(uint32)';
$VsipImageStatistics
= 'VsipImageStatisticsByte', $InType
= 'uint8',
$OutType
= 'float', $CastArray
= '(uint32[:,:])', $CastVal
= '(uint32)';
$VsipImageStatistics
= 'VsipImageStatisticsInt', $InType
= 'int32',
$OutType
= 'float', $CastArray
= '', $CastVal = '';
$VsipImageStatistics
= 'VsipImageStatisticsFloat', $InType
= 'float',
$OutType
= 'float', $CastArray
= '', $CastVal = '';
$in
$OutType [:] $VsipImageStatistics($InType
src[:,:], uint12 statistics)
{
// ***** recover the
src size *****
VsipIndexesType
r, VsipIndexesType c = extents(src);
// ***** test the size
of the image *****
assert(((r >
0) && (c > 0)),
"ERROR: Image can not have zero dimention. (",r,"x",c,")\n");
// ***** convert the
binary variable in an array of booleans *****
bits12 bitmask
= (bits12)1 << 11;
bits12 stat =
statistics;
bool mask[:]
=
for
uint4 i in [12]
{ bool b = ((stat & bitmask) == (bits12)0?
false : true);
next bitmask = bitmask >> 1;
} return (array(b));
// ***** Compute the
specified statistics and return an array of them. *****
// ***** Statistics
not requested are returned as zero.
*****
// ***** Some statistics
are computed even if not requested because *****
// ***** they are used
by others, nevertheless they are returned as 0. *****
$OutType result[:]
=
if
(true)
{ $OutType
auxmean =
if (mask[0] || mask[3] || mask[4])
return(array_mean($CastArray
src))
else
return(0);
$OutType
meanval =
if (mask[0])
return(auxmean)
else
return(0);
$OutType
auxstd =
if (mask[1] || mask[3] || mask[4])
return(array_st_dev($CastArray
src))
else
return(0);
$OutType
varval =
if (mask[1])
return(auxstd*auxstd)
else
return(0);
$OutType
auxmeansquare =
if (mask[2])
return(for elem
in src
return(sum($CastVal
elem*elem)))
else
return(0);
$OutType
rootmeansquareval =
if (mask[2])
return(sqrt(auxmeansquare/(r*c)))
else
return(0);
$OutType
auxskew1 =
if ((mask[3]) && (auxstd != 0))
return(for elem
in src
{ $OutType val = (elem - auxmean)/auxstd;
}
return(sum(val*val*val)))
else
return(0);
$OutType
skewval =
if (mask[3])
return(auxskew1/(r*c))
else
return(0);
$OutType
auxskew2 =
if ((mask[4]) && (auxstd != 0))
return(for elem
in src
{ $OutType val = (elem - auxmean)/auxstd;
} return(sum(val*val*val*val)))
else
return(0);
$OutType
kurtval =
if (mask[4])
return(auxskew2/(r*c) - 3)
else
return(0);
$OutType
intval =
if (mask[5])
return(array_sum($CastArray
src))
else
return(0);
$OutType
posintval =
if (mask[6])
return(for elem
in src
{ bool b = (elem > 0 ? true
: false);
}
return(sum( $CastVal
elem,b)))
else
return(0);
$OutType
negintval =
if (mask[7])
return(for elem
in src
{ bool b = (elem < 0 ? true
: false);
}
return(sum($CastVal
elem,b)))
else
return(0);
$OutType
minval =
if (mask[8])
return(array_min(src))
else
return(0);
$OutType
maxval =
if (mask[9])
return(array_max(src))
else
return(0);
$OutType
medval =
if (mask[10])
return(array_median(src))
else
return(0);
$OutType
zerosval =
if (mask[11])
return(for elem
in src
{ uint32 n = (elem == 0 ? 1 : 0);
}
return(sum(n)))
else
return(0);
$OutType
result1[12] = { meanval, varval, rootmeansquareval, skewval,
kurtval, intval, posintval, negintval, minval,
maxval, medval, zerosval};
} return(result1)
else
{ $OutType
result1[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
} return(result1);
} return (result);
$end_generic