diff --git a/libvips/conversion/Makefile.am b/libvips/conversion/Makefile.am index 326bf188..badf0377 100644 --- a/libvips/conversion/Makefile.am +++ b/libvips/conversion/Makefile.am @@ -34,6 +34,7 @@ libconversion_la_SOURCES = \ im_system.c \ im_tbjoin.c \ im_text.c \ + im_gaussnoise.c \ im_vips2mask.c \ im_wrap.c \ im_zoom.c diff --git a/libvips/conversion/conver_dispatch.c b/libvips/conversion/conver_dispatch.c index 82798050..ad5a91ee 100644 --- a/libvips/conversion/conver_dispatch.c +++ b/libvips/conversion/conver_dispatch.c @@ -48,28 +48,15 @@ * @include: vips/vips.h * * These operations convert an image in some way. They can be split into a two - * main groups: + * main groups. * - * - * - * - * Format conversion + * The first set of operations change an image's format in some way. You + * can change the band format (for example, cast to 32-bit unsigned + * int), form complex images from real images, convert images to + * matrices and back, change header fields, and a few others. * - * The first set of operations change an image's format in some way. You - * can change the band format (for example, cast to 32-bit unsigned - * int), form complex images from real images, convert images to - * matrices and back, change header fields, and a few others. - * - * - * - * - * Lossless image manipulations - * - * The second group move pixels about in some way. You can flip, rotate, - * extract, insert and join pairs of iamges in various ways. - * - * - * + * The second group move pixels about in some way. You can flip, rotate, + * extract, insert and join pairs of iamges in various ways. * */ @@ -131,6 +118,72 @@ static im_function subsample_desc = { subsample_args /* Arg list */ }; +/* Args for im_gaussnoise. + */ +static im_arg_desc gaussnoise_args[] = { + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_INT( "xsize" ), + IM_INPUT_INT( "ysize" ), + IM_INPUT_DOUBLE( "mean" ), + IM_INPUT_DOUBLE( "sigma" ) +}; + +/* Call im_gaussnoise via arg vector. + */ +static int +gaussnoise_vec( im_object *argv ) +{ + int xsize = *((int *) argv[1]); + int ysize = *((int *) argv[2]); + double mean = *((double *) argv[3]); + double sigma = *((double *) argv[4]); + + if( im_gaussnoise( argv[0], xsize, ysize, mean, sigma ) ) + return( -1 ); + + return( 0 ); +} + +/* Description of im_gaussnoise. + */ +static im_function gaussnoise_desc = { + "im_gaussnoise", /* Name */ + "generate image of gaussian noise with specified statistics", + IM_FN_PIO, /* Flags */ + gaussnoise_vec, /* Dispatch function */ + IM_NUMBER( gaussnoise_args ), /* Size of arg list */ + gaussnoise_args /* Arg list */ +}; + +/* Args to im_addgnoise. + */ +static im_arg_desc addgnoise_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_DOUBLE( "sigma" ) +}; + +/* Call im_addgnoise via arg vector. + */ +static int +addgnoise_vec( im_object *argv ) +{ + double sigma = *((double *) argv[2]); + + return( im_addgnoise( argv[0], argv[1], sigma ) ); +} + +/* Description of im_addgnoise. + */ +static im_function addgnoise_desc = { + "im_addgnoise", /* Name */ + "add gaussian noise with mean 0 and std. dev. sigma", + IM_FN_PIO, /* Flags */ + addgnoise_vec, /* Dispatch function */ + IM_NUMBER( addgnoise_args ), /* Size of arg list */ + addgnoise_args /* Arg list */ +}; + /* Args to im_extract. */ static im_arg_desc extract_args[] = { @@ -1295,6 +1348,8 @@ static im_function embed_desc = { /* Package up all these functions. */ static im_function *conv_list[] = { + &addgnoise_desc, + &gaussnoise_desc, &bandjoin_desc, &black_desc, &c2amph_desc, diff --git a/libvips/convolution/im_gaussnoise.c b/libvips/conversion/im_gaussnoise.c similarity index 100% rename from libvips/convolution/im_gaussnoise.c rename to libvips/conversion/im_gaussnoise.c diff --git a/libvips/convolution/Makefile.am b/libvips/convolution/Makefile.am index 8b9b47e4..c458173a 100644 --- a/libvips/convolution/Makefile.am +++ b/libvips/convolution/Makefile.am @@ -8,10 +8,8 @@ libconvolution_la_SOURCES = \ im_convf.c \ im_convsep.c \ im_convsepf.c \ - im_convsub.c \ im_contrast_surface.c \ im_fastcor.c \ - im_gaussnoise.c \ im_gradcor.c \ im_sharpen.c \ im_spcor.c diff --git a/libvips/convolution/convol_dispatch.c b/libvips/convolution/convol_dispatch.c index bcb847a9..ff9cff2b 100644 --- a/libvips/convolution/convol_dispatch.c +++ b/libvips/convolution/convol_dispatch.c @@ -42,6 +42,17 @@ #include #endif /*WITH_DMALLOC*/ +/** + * SECTION: convolution + * @short_description: convolve and correlate images + * @stability: Stable + * @include: vips/vips.h + * + * These operations convolve an image in some way, or are operations based on + * simple convolution, or are useful with convolution. + * + */ + /* One image in, one out. */ static im_arg_desc one_in_one_out[] = { @@ -160,35 +171,6 @@ static im_function sharpen_desc = { sharpen_args /* Arg list */ }; -/* Args to im_addgnoise. - */ -static im_arg_desc addgnoise_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), - IM_INPUT_DOUBLE( "sigma" ) -}; - -/* Call im_addgnoise via arg vector. - */ -static int -addgnoise_vec( im_object *argv ) -{ - double sigma = *((double *) argv[2]); - - return( im_addgnoise( argv[0], argv[1], sigma ) ); -} - -/* Description of im_addgnoise. - */ -static im_function addgnoise_desc = { - "im_addgnoise", /* Name */ - "add gaussian noise with mean 0 and std. dev. sigma", - IM_FN_PIO, /* Flags */ - addgnoise_vec, /* Dispatch function */ - IM_NUMBER( addgnoise_args ), /* Size of arg list */ - addgnoise_args /* Arg list */ -}; - /* Args for convolver with imask. */ static im_arg_desc conv_imask[] = { @@ -394,39 +376,6 @@ static im_function convsepf_raw_desc = { conv_dmask /* Arg list */ }; -/* Args for im_convsub. - */ -static im_arg_desc convsub_args[] = { - IM_INPUT_IMAGE( "in" ), - IM_OUTPUT_IMAGE( "out" ), - IM_INPUT_IMASK( "matrix" ), - IM_INPUT_INT( "xskip" ), - IM_INPUT_INT( "yskip" ) -}; - -/* Call im_convsub via arg vector. - */ -static int -convsub_vec( im_object *argv ) -{ - im_mask_object *mo = argv[2]; - int xskip = *((int *) argv[3]); - int yskip = *((int *) argv[4]); - - return( im_convsub( argv[0], argv[1], mo->mask, xskip, yskip ) ); -} - -/* Description of im_convsub. - */ -static im_function convsub_desc = { - "im_convsub", /* Name */ - "convolve uchar to uchar, sub-sampling by xskip, yskip", - IM_FN_TRANSFORM, /* Flags */ - convsub_vec, /* Dispatch function */ - IM_NUMBER( convsub_args ), /* Size of arg list */ - convsub_args /* Arg list */ -}; - /* Call im_fastcor via arg vector. */ static int @@ -465,43 +414,6 @@ static im_function fastcor_raw_desc = { two_in_one_out /* Arg list */ }; -/* Args for im_gaussnoise. - */ -static im_arg_desc gaussnoise_args[] = { - IM_OUTPUT_IMAGE( "out" ), - IM_INPUT_INT( "xsize" ), - IM_INPUT_INT( "ysize" ), - IM_INPUT_DOUBLE( "mean" ), - IM_INPUT_DOUBLE( "sigma" ) -}; - -/* Call im_gaussnoise via arg vector. - */ -static int -gaussnoise_vec( im_object *argv ) -{ - int xsize = *((int *) argv[1]); - int ysize = *((int *) argv[2]); - double mean = *((double *) argv[3]); - double sigma = *((double *) argv[4]); - - if( im_gaussnoise( argv[0], xsize, ysize, mean, sigma ) ) - return( -1 ); - - return( 0 ); -} - -/* Description of im_gaussnoise. - */ -static im_function gaussnoise_desc = { - "im_gaussnoise", /* Name */ - "generate image of gaussian noise with specified statistics", - IM_FN_PIO, /* Flags */ - gaussnoise_vec, /* Dispatch function */ - IM_NUMBER( gaussnoise_args ), /* Size of arg list */ - gaussnoise_args /* Arg list */ -}; - /* Call im_grad_x via arg vector. */ static int @@ -661,7 +573,6 @@ static im_function spcor_raw_desc = { /* Package up all these functions. */ static im_function *convol_list[] = { - &addgnoise_desc, &compass_desc, &contrast_surface_desc, &contrast_surface_raw_desc, @@ -673,10 +584,8 @@ static im_function *convol_list[] = { &convsepf_desc, &convsepf_raw_desc, &convsep_raw_desc, - &convsub_desc, &fastcor_desc, &fastcor_raw_desc, - &gaussnoise_desc, &gradcor_desc, &gradcor_raw_desc, &gradient_desc, diff --git a/libvips/deprecated/Makefile.am b/libvips/deprecated/Makefile.am index 7446b1bb..982ec80e 100644 --- a/libvips/deprecated/Makefile.am +++ b/libvips/deprecated/Makefile.am @@ -7,6 +7,7 @@ libdeprecated_la_SOURCES = \ im_gaddim.c \ im_cmulnorm.c \ im_printlines.c \ + im_convsub.c \ im_debugim.c \ im_gfadd.c \ im_setbox.c \ diff --git a/libvips/deprecated/deprecated_dispatch.c b/libvips/deprecated/deprecated_dispatch.c index 20e192b2..f5306467 100644 --- a/libvips/deprecated/deprecated_dispatch.c +++ b/libvips/deprecated/deprecated_dispatch.c @@ -619,6 +619,39 @@ static im_function slice_desc = { slice_args /* Arg list */ }; +/* Args for im_convsub. + */ +static im_arg_desc convsub_args[] = { + IM_INPUT_IMAGE( "in" ), + IM_OUTPUT_IMAGE( "out" ), + IM_INPUT_IMASK( "matrix" ), + IM_INPUT_INT( "xskip" ), + IM_INPUT_INT( "yskip" ) +}; + +/* Call im_convsub via arg vector. + */ +static int +convsub_vec( im_object *argv ) +{ + im_mask_object *mo = argv[2]; + int xskip = *((int *) argv[3]); + int yskip = *((int *) argv[4]); + + return( im_convsub( argv[0], argv[1], mo->mask, xskip, yskip ) ); +} + +/* Description of im_convsub. + */ +static im_function convsub_desc = { + "im_convsub", /* Name */ + "convolve uchar to uchar, sub-sampling by xskip, yskip", + IM_FN_TRANSFORM, /* Flags */ + convsub_vec, /* Dispatch function */ + IM_NUMBER( convsub_args ), /* Size of arg list */ + convsub_args /* Arg list */ +}; + /* Args to im_bernd. */ static im_arg_desc bernd_args[] = { @@ -670,6 +703,7 @@ static im_function *deprecated_list[] = { &clip2dcm_desc, &clip2f_desc, &clip2i_desc, + &convsub_desc, &clip2s_desc, &clip2ui_desc, &clip2us_desc, diff --git a/libvips/convolution/im_convsub.c b/libvips/deprecated/im_convsub.c similarity index 100% rename from libvips/convolution/im_convsub.c rename to libvips/deprecated/im_convsub.c diff --git a/libvips/include/vips/conversion.h b/libvips/include/vips/conversion.h index 2e389eff..79273eed 100644 --- a/libvips/include/vips/conversion.h +++ b/libvips/include/vips/conversion.h @@ -76,8 +76,10 @@ int im_c2ps( IMAGE *in, IMAGE *out ); int im_scaleps( IMAGE *in, IMAGE *out ); int im_falsecolour( IMAGE *in, IMAGE *out ); +int im_addgnoise( IMAGE *, IMAGE *, double ); +int im_gaussnoise( IMAGE *, int, int, double, double ); -int im_black( IMAGE *out, int, int, int ); +int im_black( IMAGE *out, int width, int height, int bands ); int im_text( IMAGE *out, const char *text, const char *font, int width, int alignment, int dpi ); @@ -88,10 +90,10 @@ int im_extract_areabands( IMAGE *in, IMAGE *out, int left, int top, int width, int height, int band, int nbands ); int im_embed( IMAGE *in, IMAGE *out, int type, int left, int top, int width, int height ); -int im_bandjoin( IMAGE *in, IMAGE *out, IMAGE * ); -int im_gbandjoin( IMAGE **in, IMAGE *out, int ); -int im_insert( IMAGE *in, IMAGE *out, IMAGE *, int x, int y ); -int im_insert_noexpand( IMAGE *in, IMAGE *out, IMAGE *, int x, int y ); +int im_bandjoin( IMAGE *in1, IMAGE *in2, IMAGE *out ); +int im_gbandjoin( IMAGE **in, IMAGE *out, int n ); +int im_insert( IMAGE *main, IMAGE *sub, IMAGE *out, int x, int y ); +int im_insert_noexpand( IMAGE *main, IMAGE *sub, IMAGE *out, int x, int y ); int im_lrjoin( IMAGE *in1, IMAGE *in2, IMAGE *out ); int im_tbjoin( IMAGE *in1, IMAGE *in2, IMAGE *out ); int im_replicate( IMAGE *in, IMAGE *out, int across, int down ); diff --git a/libvips/include/vips/convolution.h b/libvips/include/vips/convolution.h index e9e81fb1..483c9211 100644 --- a/libvips/include/vips/convolution.h +++ b/libvips/include/vips/convolution.h @@ -37,35 +37,37 @@ extern "C" { #endif /*__cplusplus*/ -int im_sharpen( IMAGE *, IMAGE *, int, double, double, double, double, double ); -int im_addgnoise( IMAGE *, IMAGE *, double ); -int im_gaussnoise( IMAGE *, int, int, double, double ); +int im_conv( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_conv_raw( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_convf( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_convf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_convsep( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_convsep_raw( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_convsepf( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); +int im_convsepf_raw( IMAGE *in, IMAGE *out, DOUBLEMASK *mask ); -int im_compass( IMAGE *, IMAGE *, INTMASK * ); -int im_gradient( IMAGE *, IMAGE *, INTMASK * ); -int im_lindetect( IMAGE *, IMAGE *, INTMASK * ); -int im_conv( IMAGE *, IMAGE *, INTMASK * ); -int im_conv_raw( IMAGE *, IMAGE *, INTMASK * ); -int im_convf( IMAGE *, IMAGE *, DOUBLEMASK * ); -int im_convf_raw( IMAGE *, IMAGE *, DOUBLEMASK * ); -int im_convsep( IMAGE *, IMAGE *, INTMASK * ); -int im_convsep_raw( IMAGE *, IMAGE *, INTMASK * ); -int im_convsepf( IMAGE *, IMAGE *, DOUBLEMASK * ); -int im_convsepf_raw( IMAGE *, IMAGE *, DOUBLEMASK * ); -int im_convsub( IMAGE *, IMAGE *, INTMASK *, int, int ); +int im_compass( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_gradient( IMAGE *in, IMAGE *out, INTMASK *mask ); +int im_lindetect( IMAGE *in, IMAGE *out, INTMASK *mask ); + +int im_sharpen( IMAGE *in, IMAGE *out, + int mask_size, + double x1, double y2, double y3, + double m1, double m2 ); int im_grad_x( IMAGE *in, IMAGE *out ); int im_grad_y( IMAGE *in, IMAGE *out ); -int im_phasecor_fft( IMAGE *in1, IMAGE *in2, IMAGE *out ); -int im_fastcor( IMAGE *, IMAGE *, IMAGE * ); -int im_fastcor_raw( IMAGE *, IMAGE *, IMAGE * ); -int im_spcor( IMAGE *, IMAGE *, IMAGE * ); -int im_spcor_raw( IMAGE *, IMAGE *, IMAGE * ); -int im_gradcor( IMAGE *, IMAGE *, IMAGE * ); -int im_gradcor_raw( IMAGE *, IMAGE *, IMAGE * ); -int im_contrast_surface( IMAGE *, IMAGE *, int, int ); -int im_contrast_surface_raw( IMAGE *, IMAGE *, int, int ); +int im_fastcor( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_fastcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_spcor( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_spcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_gradcor( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_gradcor_raw( IMAGE *in, IMAGE *ref, IMAGE *out ); +int im_contrast_surface( IMAGE *in, IMAGE *out, + int half_win_size, int spacing ); +int im_contrast_surface_raw( IMAGE *in, IMAGE *out, + int half_win_size, int spacing ); #ifdef __cplusplus } diff --git a/libvips/include/vips/deprecated.h b/libvips/include/vips/deprecated.h index a3cfd093..bf1b4e37 100644 --- a/libvips/include/vips/deprecated.h +++ b/libvips/include/vips/deprecated.h @@ -343,6 +343,8 @@ int im_thresh( IMAGE *in, IMAGE *out, double ); int im_print( const char *message ); +int im_convsub( IMAGE *in, IMAGE *out, INTMASK *mask, int xskip, int yskip ); + #ifdef __cplusplus } #endif /*__cplusplus*/ diff --git a/libvips/include/vips/freq_filt.h b/libvips/include/vips/freq_filt.h index 5ca5257f..609dbf40 100644 --- a/libvips/include/vips/freq_filt.h +++ b/libvips/include/vips/freq_filt.h @@ -44,6 +44,7 @@ int im_rotquad( IMAGE *, IMAGE * ); int im_fwfft( IMAGE *, IMAGE * ); int im_invfft( IMAGE *, IMAGE * ); int im_invfftr( IMAGE *, IMAGE * ); +int im_phasecor_fft( IMAGE *in1, IMAGE *in2, IMAGE *out ); #ifdef __cplusplus }