diff --git a/ChangeLog b/ChangeLog index 27d1f6b0..b827a5a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ - add magicksave, save image with libMagick [dlemstra] - 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 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 0cdb6fd7..dfba4fb6 100644 --- a/libvips/arithmetic/hough_line.c +++ b/libvips/arithmetic/hough_line.c @@ -2,6 +2,8 @@ * * 7/3/14 * - from hist_find.c + * 1/2/18 + * - change width to 0 - 180 */ /* @@ -73,8 +75,10 @@ vips_hough_line_build( VipsObject *object ) if( !(hough_line->sin = VIPS_ARRAY( object, width, double )) ) return( -1 ); + /* Map width to 180 degrees. + */ for( i = 0; i < width; i++ ) - hough_line->sin[i] = sin( 2 * VIPS_PI * i / width ); + hough_line->sin[i] = sin( VIPS_PI * i / width ); if( VIPS_OBJECT_CLASS( vips_hough_line_parent_class )->build( object ) ) return( -1 ); @@ -107,17 +111,19 @@ 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 ); int i; - for( i = 0; i < width; i++ ) { - int i90 = (i + width / 4) % width; + for( i = 0; i < width; i++ ) { + int i90 = (i + width / 2) % width; double r = xd * hough_line->sin[i90] + yd * hough_line->sin[i]; int ri = height * r; - if( ri >= 0 && - ri < height ) - *VIPS_IMAGE_ADDR( accumulator, i, ri ) += 1; + if( ri >= 0 && + ri < height ) + data[i + ri * width] += 1; } } @@ -174,8 +180,8 @@ vips_hough_line_init( VipsHoughLine *hough_line ) * * Find the line Hough transform for @in. @in must have one band. @out has one * band, with pixels being the number of votes for that line. The X dimension - * of @out is the line angle, the Y dimension is the distance of the line from - * the origin. + * of @out is the line angle in 0 - 180 degrees, the Y dimension is the + * distance of the closest part of that line to the origin in the top-left. * * Use @width @height to set the size of the parameter space image (@out), * that is, how accurate the line determination should be.