From 10aecae374b51ff511a099453f9b1b18de3c88e4 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 26 May 2011 13:20:15 +0100 Subject: [PATCH] added im_gauss_dmask_sep() --- ChangeLog | 1 + libvips/include/vips/mask.h | 2 ++ libvips/mask/im_gaussmasks.c | 40 ++++++++++++++++++++++++++++++++++++ libvips/mask/mask_dispatch.c | 28 +++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/ChangeLog b/ChangeLog index 13a1426f..37b8355c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -61,6 +61,7 @@ - vips7 binops all do sizealike too, also gbandjoin and ifthenelse - new API is now functional - vips.c generates GOption flags for vips8 operations +- added im_gauss_dmask_sep() 30/11/10 started 7.24.0 - bump for new stable diff --git a/libvips/include/vips/mask.h b/libvips/include/vips/mask.h index 244a3967..db422c7e 100644 --- a/libvips/include/vips/mask.h +++ b/libvips/include/vips/mask.h @@ -82,6 +82,8 @@ INTMASK *im_gauss_imask_sep( const char *filename, double sigma, double min_ampl ); DOUBLEMASK *im_gauss_dmask( const char *filename, double sigma, double min_ampl ); +DOUBLEMASK *im_gauss_dmask_sep( const char *filename, + double sigma, double min_ampl ); INTMASK *im_dup_imask( INTMASK *in, const char *filename ); DOUBLEMASK *im_dup_dmask( DOUBLEMASK *in, const char *filename ); diff --git a/libvips/mask/im_gaussmasks.c b/libvips/mask/im_gaussmasks.c index d21754c0..36ad02fd 100644 --- a/libvips/mask/im_gaussmasks.c +++ b/libvips/mask/im_gaussmasks.c @@ -171,6 +171,46 @@ im_gauss_dmask( const char *filename, double sigma, double min_ampl ) return( m ); } +/** + * im_gauss_dmask_sep: + * @filename: the returned mask has this set as the filename + * @sigma: standard deviation of mask + * @min_ampl: minimum amplitude + * + * im_gauss_dmask_sep() works exactly as im_gauss_dmask(), but returns only + * the central line of the mask. This is useful with im_convsepf(). + * + * See also: im_gauss_dmask(), im_convsepf(). + * + * Returns: the calculated mask on success, or NULL on error. + */ +DOUBLEMASK * +im_gauss_dmask_sep( const char *filename, double sigma, double min_ampl ) +{ + DOUBLEMASK *im; + DOUBLEMASK *im2; + int i; + double sum; + + if( !(im = im_gauss_dmask( filename, sigma, min_ampl )) ) + return( NULL ); + if( !(im2 = im_create_dmask( filename, im->xsize, 1 )) ) { + im_free_dmask( im ); + return( NULL ); + } + + sum = 0; + for( i = 0; i < im->xsize; i++ ) { + im2->coeff[i] = im->coeff[i + im->xsize * (im->ysize / 2)]; + sum += im2->coeff[i]; + } + im2->scale = sum; + + im_free_dmask( im ); + + return( im2 ); +} + /** * im_gauss_imask: * @filename: the returned mask has this set as the filename diff --git a/libvips/mask/mask_dispatch.c b/libvips/mask/mask_dispatch.c index ea011e7a..d7c4e298 100644 --- a/libvips/mask/mask_dispatch.c +++ b/libvips/mask/mask_dispatch.c @@ -229,6 +229,33 @@ static im_function gauss_dmask_desc = { gauss_dmask_args /* Arg list */ }; +/* Call im_gauss_dmask_sep via arg vector. + */ +static int +gauss_dmask_sep_vec( im_object *argv ) +{ + im_mask_object *mo = argv[0]; + double sigma = *((double *) argv[1]); + double min_amp = *((double *) argv[2]); + + if( !(mo->mask = + im_gauss_dmask_sep( mo->name, sigma, min_amp )) ) + return( -1 ); + + return( 0 ); +} + +/* Description of im_gauss_dmask_sep. + */ +static im_function gauss_dmask_sep_desc = { + "im_gauss_dmask_sep", /* Name */ + "generate separable gaussian DOUBLEMASK", + 0, /* Flags */ + gauss_dmask_sep_vec, /* Dispatch function */ + IM_NUMBER( gauss_dmask_args ), /* Size of arg list */ + gauss_dmask_args /* Arg list */ +}; + /* Args for im_gauss_imask. */ static im_arg_desc gauss_imask_args[] = { @@ -549,6 +576,7 @@ static im_function dmask_ysize_desc = { */ static im_function *mask_list[] = { &gauss_dmask_desc, + &gauss_dmask_sep_desc, &log_dmask_desc, &log_imask_desc, &gauss_imask_desc,