From acf5f5169a8f3a81a89f388bca5eeb7ef9b6daad Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 6 Mar 2016 18:02:59 +0000 Subject: [PATCH] fix hist_entropy there was a copy-paste error in the call to vips_log(), thanks Lovell see https://github.com/lovell/sharp/issues/295 --- ChangeLog | 1 + libvips/histogram/hist_entropy.c | 4 +++- test/test_histogram.py | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4db0aebc..b78391b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 27/1/16 started 8.2.3 - fix a crash with SPARC byte-order labq vips images - fix parsing of filenames containing brackets, thanks shilpi230 +- fix hist_entropy (lovell) 12/1/16 started 8.2.2 - changes to ease compiling C++ binding with MSVC [Lovell Fuller] diff --git a/libvips/histogram/hist_entropy.c b/libvips/histogram/hist_entropy.c index e6120ffd..740dfa10 100644 --- a/libvips/histogram/hist_entropy.c +++ b/libvips/histogram/hist_entropy.c @@ -3,6 +3,8 @@ * Author: John Cupitt * 11/8/15 * - from hist_ismonotonic.c + * 6/3/16 + * - vips_log() call was mangled, thanks Lovell */ /* @@ -80,7 +82,7 @@ vips_hist_entropy_build( VipsObject *object ) return( -1 ); sum = avg * VIPS_IMAGE_N_PELS( entropy->in ) * entropy->in->Bands; if( vips_linear1( entropy->in, &t[0], 1.0 / sum, 0, NULL ) || - vips_log( t[0], &t[1], 1.0 / sum, 0, NULL ) || + vips_log( t[0], &t[1], NULL ) || vips_linear1( t[1], &t[2], 1.0 / log( 2.0 ), 0, NULL ) || vips_multiply( t[0], t[2], &t[3], NULL ) || vips_avg( t[3], &avg, NULL ) ) diff --git a/test/test_histogram.py b/test/test_histogram.py index ae6bbe32..20716e65 100755 --- a/test/test_histogram.py +++ b/test/test_histogram.py @@ -101,7 +101,7 @@ class TestHistogram(unittest.TestCase): self.assertEqual((im - im2).abs().max(), 0.0) - def test_hist_map(self): + def test_percent(self): im = Vips.Image.new_from_file("images/IMG_4618.jpg").extract_band(1) pc = im.percent(90) @@ -112,6 +112,13 @@ class TestHistogram(unittest.TestCase): self.assertAlmostEqual(pc_set, 90, places = 0) + def test_hist_entropy(self): + im = Vips.Image.new_from_file("images/IMG_4618.jpg").extract_band(1) + + ent = im.hist_find().hist_entropy() + + self.assertAlmostEqual(ent, 4.367, places = 3) + def test_stdif(self): im = Vips.Image.new_from_file("images/IMG_4618.jpg")