From 24ff40e9be99aeeb9b2d4633c8c96573610b3715 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 15 Sep 2014 13:25:04 +0100 Subject: [PATCH] find_indexed wasn't banning complex images --- libvips/arithmetic/hist_find_indexed.c | 12 +++++++---- python/test_arithmetic.py | 28 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libvips/arithmetic/hist_find_indexed.c b/libvips/arithmetic/hist_find_indexed.c index 17612e83..3322e550 100644 --- a/libvips/arithmetic/hist_find_indexed.c +++ b/libvips/arithmetic/hist_find_indexed.c @@ -157,6 +157,10 @@ vips_hist_find_indexed_build( VipsObject *object ) indexed->index_ready = t[0]; } + if( statistic->in ) + if( vips_check_noncomplex( class->nickname, statistic->in ) ) + return( -1 ); + if( VIPS_OBJECT_CLASS( vips_hist_find_indexed_parent_class )-> build( object ) ) return( -1 ); @@ -407,13 +411,13 @@ vips_hist_find_indexed_init( VipsHistFindIndexed *hist_find ) * words, element zero in @out contains the sum of all the pixels in @in * whose corresponding pixel in @index is zero. * - * @index must have just one band and be u8 or u16. @value must be - * non-complex. @out always has the same size and format as @value. + * @index must have just one band and be u8 or u16. @in must be + * non-complex. @out always has the same size and format as @in. * - * This operation is useful in conjunction with im_label_regions(). You can + * This operation is useful in conjunction with vips_labelregions(). You can * use it to find the centre of gravity of blobs in an image, for example. * - * See also: vips_hist_find(), im_label_regions(). + * See also: vips_hist_find(), vips_labelregions(). * * Returns: 0 on success, -1 on error */ diff --git a/python/test_arithmetic.py b/python/test_arithmetic.py index 108325b7..f79ebb37 100755 --- a/python/test_arithmetic.py +++ b/python/test_arithmetic.py @@ -307,26 +307,40 @@ class TestArithmetic(unittest.TestCase): def test_histfind(self): im = Vips.Image.black(50, 100) - test = im.insert(im + 100, 50, 0, expand = True) + test = im.insert(im + 10, 50, 0, expand = True) for fmt in all_formats: hist = test.cast(fmt).hist_find() self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(100,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(12,0), [0]) + self.assertAlmostEqualObjects(hist.getpoint(10,0), [5000]) + self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) test = test * [1, 2, 3] for fmt in all_formats: hist = test.cast(fmt).hist_find(band = 0) self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(100,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(12,0), [0]) + self.assertAlmostEqualObjects(hist.getpoint(10,0), [5000]) + self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) hist = test.cast(fmt).hist_find(band = 1) self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(200,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(12,0), [0]) + self.assertAlmostEqualObjects(hist.getpoint(20,0), [5000]) + self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) + + def test_histfind_indexed(self): + im = Vips.Image.black(50, 100) + test = im.insert(im + 10, 50, 0, expand = True) + index = test / 10 + + for x in noncomplex_formats: + for y in [Vips.BandFormat.UCHAR, Vips.BandFormat.USHORT]: + a = test.cast(x) + b = index.cast(y) + hist = a.hist_find_indexed(b) + + self.assertAlmostEqualObjects(hist.getpoint(0,0), [0]) + self.assertAlmostEqualObjects(hist.getpoint(1,0), [50000]) if __name__ == '__main__': unittest.main()