static int vips_statistic_build( VipsObject *object ) { VipsStatistic *statistic = VIPS_STATISTIC( object ); VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object ); const char *domain = class->nickname; #ifdef DEBUG printf( "vips_statistic_build: " ); vips_object_print_name( object ); printf( "\n" ); #endif /*DEBUG*/ if( VIPS_OBJECT_CLASS( vips_statistic_parent_class )->build( object ) ) return( -1 ); if( vips_image_pio_input( statistic->in ) || vips_check_uncoded( domain, statistic->in ) ) return( -1 ); if( vips_sink( statistic->in, vips_statistic_scan_start, vips_statistic_scan, vips_statistic_scan_stop, statistic, NULL ) ) return( -1 ); return( 0 ); }
int im_iterate( IMAGE *im, im_start_fn start, im_generate_fn generate, im_stop_fn stop, void *b, void *c ) { return( vips_sink( im, start, (VipsGenerateFn) generate, stop, b, c ) ); }
/** * im_hist_indexed: * @index: input image * @value: input image * @out: output image * * Make a histogram of @value, but use image @index to pick the bins. In other * words, element zero in @out contains the sum of all the pixels in @value * 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. * * This operation is useful in conjunction with im_label_regions(). You can * use it to find the centre of gravity of blobs in an image, for example. * * See also: im_histgr(), im_label_regions(). * * Returns: 0 on success, -1 on error */ int im_hist_indexed( IMAGE *index, IMAGE *value, IMAGE *out ) { int size; /* Length of hist */ Histogram *mhist; VipsGenerateFn scanfn; /* Check images. PIO from in, WIO to out. */ if( im_pincheck( index ) || im_pincheck( value ) || im_outcheck( out ) || im_check_uncoded( "im_hist_indexed", index ) || im_check_uncoded( "im_hist_indexed", value ) || im_check_noncomplex( "im_hist_indexed", value ) || im_check_size_same( "im_hist_indexed", index, value ) || im_check_u8or16( "im_hist_indexed", index ) || im_check_mono( "im_hist_indexed", index ) ) return( -1 ); /* Find the range of pixel values we must handle. */ if( index->BandFmt == IM_BANDFMT_UCHAR ) { size = 256; scanfn = hist_scan_uchar; } else { size = 65536; scanfn = hist_scan_ushort; } /* Build main hist we accumulate data in. */ if( !(mhist = hist_build( index, value, out, value->Bands, size )) ) return( -1 ); /* Accumulate data. */ if( vips_sink( index, hist_start, scanfn, hist_stop, mhist, NULL ) || hist_write( out, mhist ) ) { hist_free( mhist ); return( -1 ); } hist_free( mhist ); return( 0 ); }
/** * im_maxpos_avg: * @im: image to scan * @xpos: returned X position * @ypos: returned Y position * @out: returned value * * Function to find the maximum of an image. Returns coords and value at * double precision. In the event of a draw, returns average of all * drawing coords. * * See also: im_maxpos(), im_min(), im_stats(). * * Returns: 0 on success, -1 on error */ int im_maxpos_avg( IMAGE *in, double *xpos, double *ypos, double *out ) { Maxposavg *global_maxposavg; if( im_pincheck( in ) || im_check_uncoded( "im_maxpos_avg", in ) ) return( -1 ); if( !(global_maxposavg = IM_NEW( in, Maxposavg )) ) return( -1 ); if( im__value( in, &global_maxposavg->max ) ) return( -1 ); global_maxposavg->xpos = 0; global_maxposavg->ypos = 0; global_maxposavg->occurences = 1; /* We use square mod for scanning, for speed. */ if( vips_band_format_iscomplex( in->BandFmt ) ) global_maxposavg->max *= global_maxposavg->max; if( vips_sink( in, maxposavg_start, maxposavg_scan, maxposavg_stop, in, global_maxposavg ) ) return( -1 ); /* Back to modulus. */ if( vips_band_format_iscomplex( in->BandFmt ) ) global_maxposavg->max = sqrt( global_maxposavg->max ); if( xpos ) *xpos = (double) global_maxposavg->xpos / global_maxposavg->occurences; if( ypos ) *ypos = (double) global_maxposavg->ypos / global_maxposavg->occurences; if( out ) *out = global_maxposavg->max; return( 0 ); }
static int vips_statistic_build( VipsObject *object ) { VipsStatistic *statistic = VIPS_STATISTIC( object ); VipsStatisticClass *sclass = VIPS_STATISTIC_GET_CLASS( statistic ); VipsImage **t = (VipsImage **) vips_object_local_array( object, 2 ); #ifdef DEBUG printf( "vips_statistic_build: " ); vips_object_print_name( object ); printf( "\n" ); #endif /*DEBUG*/ if( VIPS_OBJECT_CLASS( vips_statistic_parent_class )->build( object ) ) return( -1 ); statistic->ready = statistic->in; if( vips_image_decode( statistic->ready, &t[0] ) ) return( -1 ); statistic->ready = t[0]; /* If there's a format table, cast the input. */ if( sclass->format_table ) { if( vips_cast( statistic->ready, &t[1], sclass->format_table[statistic->in->BandFmt], NULL ) ) return( -1 ); statistic->ready = t[1]; } if( vips_sink( statistic->ready, vips_statistic_scan_start, vips_statistic_scan, vips_statistic_scan_stop, statistic, NULL ) ) return( -1 ); return( 0 ); }