/* A colour difference operation. */ int im__colour_difference( const char *domain, IMAGE *in1, IMAGE *in2, IMAGE *out, im_wrapmany_fn buffer_fn, void *a, void *b ) { IMAGE *t[3]; if( im_check_uncoded( domain, in1 ) || im_check_uncoded( domain, in2 ) || im_check_bands( domain, in1, 3 ) || im_check_bands( domain, in2, 3 ) || im_check_size_same( domain, in1, in2 ) || im_open_local_array( out, t, 2, domain, "p" ) || im_clip2fmt( in1, t[0], IM_BANDFMT_FLOAT ) || im_clip2fmt( in2, t[1], IM_BANDFMT_FLOAT ) ) return( -1 ); if( im_cp_descv( out, t[0], t[1], NULL ) ) return( -1 ); out->Bands = 1; out->Type = IM_TYPE_B_W; t[2] = NULL; if( im_wrapmany( t, out, buffer_fn, a, b ) ) return( -1 ); return( 0 ); }
/** * 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 ); }