From ce1f236c4df3755215cf2c4a19ced6f8c55e4b3c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 2 Feb 2018 09:12:31 +0000 Subject: [PATCH] another 2x faster on hough_line --- ChangeLog | 3 ++- libvips/arithmetic/hough_line.c | 13 ++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index b827a5a9..16d3d97e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ - remove jpeg thumbnail from EXIF if "jpeg-thumbnail-data" has been removed by user - hough_line scales width to 0 - 180, not 0 - 360 -- hough_line is 2x faster +- hough_line is 4x faster +- hough_circle is 2x faster 5/1/18 started 8.6.2 - vips_sink_screen() keeps a ref to the input image ... stops a rare race diff --git a/libvips/arithmetic/hough_line.c b/libvips/arithmetic/hough_line.c index dfba4fb6..9aa8d0b0 100644 --- a/libvips/arithmetic/hough_line.c +++ b/libvips/arithmetic/hough_line.c @@ -72,13 +72,13 @@ vips_hough_line_build( VipsObject *object ) int i; - if( !(hough_line->sin = VIPS_ARRAY( object, width, double )) ) + if( !(hough_line->sin = VIPS_ARRAY( object, 2 * width, double )) ) return( -1 ); - /* Map width to 180 degrees. + /* Map width to 180 degrees, width * 2 to 360. */ - for( i = 0; i < width; i++ ) - hough_line->sin[i] = sin( VIPS_PI * i / width ); + for( i = 0; i < 2 * width; i++ ) + hough_line->sin[i] = sin( 2 * VIPS_PI * i / (2 * width) ); if( VIPS_OBJECT_CLASS( vips_hough_line_parent_class )->build( object ) ) return( -1 ); @@ -111,13 +111,12 @@ vips_hough_line_vote( VipsHough *hough, VipsImage *accumulator, int x, int y ) double yd = (double) y / statistic->ready->Ysize; int width = hough_line->width; int height = hough_line->height; - unsigned int *data = - (unsigned int *) VIPS_IMAGE_ADDR( accumulator, 0, 0 ); + guint *data = (guint *) accumulator->data; int i; for( i = 0; i < width; i++ ) { - int i90 = (i + width / 2) % width; + int i90 = i + width / 2; double r = xd * hough_line->sin[i90] + yd * hough_line->sin[i]; int ri = height * r;