fix avg of complex
oops, can't avg mod2, duh
This commit is contained in:
parent
ca0437d002
commit
666a0a6f83
@ -32,6 +32,8 @@
|
||||
* - remove liboil
|
||||
* 24/8/11
|
||||
* - rewrite as a class
|
||||
* 12/9/14
|
||||
* - oops, fix complex avg
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -98,17 +100,11 @@ vips_avg_build( VipsObject *object )
|
||||
if( VIPS_OBJECT_CLASS( vips_avg_parent_class )->build( object ) )
|
||||
return( -1 );
|
||||
|
||||
/* Calculate average. For complex, we accumulate re*re +
|
||||
* im*im, so we need to sqrt.
|
||||
*/
|
||||
vals = (gint64)
|
||||
vips_image_get_width( statistic->in ) *
|
||||
vips_image_get_height( statistic->in ) *
|
||||
vips_image_get_bands( statistic->in );
|
||||
average = avg->sum / vals;
|
||||
if( vips_band_format_iscomplex(
|
||||
vips_image_get_format( statistic->in ) ) )
|
||||
average = sqrt( average );
|
||||
g_object_set( object, "out", average, NULL );
|
||||
|
||||
return( 0 );
|
||||
@ -151,12 +147,10 @@ vips_avg_stop( VipsStatistic *statistic, void *seq )
|
||||
TYPE *p = (TYPE *) in; \
|
||||
\
|
||||
for( i = 0; i < sz; i++ ) { \
|
||||
double mod; \
|
||||
\
|
||||
mod = p[0] * p[0] + p[1] * p[1]; \
|
||||
p += 2; \
|
||||
double mod = sqrt( p[0] * p[0] + p[1] * p[1] ); \
|
||||
\
|
||||
m += mod; \
|
||||
p += 2; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class TestArithmetic(unittest.TestCase):
|
||||
def add12(x):
|
||||
return x + 12
|
||||
|
||||
self.assertEqual([add12(x).avg for x in self.test_set],
|
||||
self.assertEqual([add12(x).avg() for x in self.test_set],
|
||||
[add12(x) for x in self.avgs])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -185,6 +185,8 @@ def _call_base(name, required, optional, self = None, option_string = None):
|
||||
|
||||
if len(out) == 1:
|
||||
out = out[0]
|
||||
elif len(out) == 0:
|
||||
out = None
|
||||
|
||||
# unref everything now we have refs to all outputs we want
|
||||
op2.unref_outputs()
|
||||
|
Loading…
Reference in New Issue
Block a user