Beispiel #1
0
static int
vips_statistic_scan( VipsRegion *region, 
	void *seq, void *a, void *b, gboolean *stop )
{
	VipsStatistic *statistic = VIPS_STATISTIC( a );
	VipsStatisticClass *class = VIPS_STATISTIC_GET_CLASS( statistic );

	VipsRect *r = &region->valid;
	int lsk = IM_REGION_LSKIP( region );

	int y;
	PEL *p;

	VIPS_DEBUG_MSG( "vips_statistic_scan: %d x %d @ %d x %d\n",
		r->width, r->height, r->left, r->top );

	p = (PEL *) IM_REGION_ADDR( region, r->left, r->top ); 
	for( y = 0; y < r->height; y++ ) { 
		if( class->scan( statistic, 
			seq, r->left, r->top + y, p, r->width ) ) 
			return( -1 );
		p += lsk;
	} 

	/* If we've requested stop, pass the message on.
	 */
	if( statistic->stop )
		*stop = TRUE;

	return( 0 );
}
Beispiel #2
0
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 );
}
Beispiel #3
0
static int
vips_min_build( VipsObject *object )
{
	VipsStatistic *statistic = VIPS_STATISTIC( object ); 
	VipsMin *min = (VipsMin *) object;

	if( VIPS_OBJECT_CLASS( vips_min_parent_class )->build( object ) )
		return( -1 );

	/* Don't set if there's no value (eg. if every pixel is NaN). This
	 * will trigger an error later.
	 */
	if( min->set ) {
		double m;

		/* For speed we accumulate min^2 for complex.
		 */
		m = min->min;
		if( vips_bandfmt_iscomplex( 
			vips_image_get_format( statistic->in ) ) )
			m = sqrt( m );

		/* We have to set the props via g_object_set() to stop vips
		 * complaining they are unset.
		 */
		g_object_set( min, 
			"out", m,
			"x", min->x,
			"y", min->y,
			NULL );
	}

	return( 0 );
}
Beispiel #4
0
static int
vips_min_build( VipsObject *object )
{
	VipsStatistic *statistic = VIPS_STATISTIC( object ); 
	VipsMin *min = (VipsMin *) object;

	double m;

	if( VIPS_OBJECT_CLASS( vips_min_parent_class )->build( object ) )
		return( -1 );

	/* For speed we accumulate min^2 for complex.
	 */
	m = min->min;
	if( vips_bandfmt_iscomplex( vips_image_get_format( statistic->in ) ) )
		m = sqrt( m );

	/* We have to set the props via g_object_set() to stop vips
	 * complaining they are unset.
	 */
	g_object_set( min, 
		"out", m,
		"x", min->x,
		"y", min->y,
		NULL );

	return( 0 );
}
Beispiel #5
0
static int
vips_statistic_scan_stop( void *seq, void *a, void *b )
{
	VipsStatistic *statistic = VIPS_STATISTIC( a );
	VipsStatisticClass *class = VIPS_STATISTIC_GET_CLASS( statistic );

	return( class->stop( statistic, seq ) );
}
Beispiel #6
0
static void *
vips_statistic_scan_start( VipsImage *in, void *a, void *b )
{
	VipsStatistic *statistic = VIPS_STATISTIC( a );
	VipsStatisticClass *class = VIPS_STATISTIC_GET_CLASS( statistic );

	return( class->start( statistic ) );
}
Beispiel #7
0
static int
vips_avg_build( VipsObject *object )
{
	VipsStatistic *statistic = VIPS_STATISTIC( object ); 
	VipsAvg *avg = (VipsAvg *) object;

	gint64 vals;
	double average;

	if( VIPS_OBJECT_CLASS( vips_avg_parent_class )->build( object ) )
		return( -1 );

	vals = (gint64) 
		vips_image_get_width( statistic->in ) * 
		vips_image_get_height( statistic->in ) * 
		vips_image_get_bands( statistic->in );
	average = avg->sum / vals;
	g_object_set( object, "out", average, NULL );

	return( 0 );
}
Beispiel #8
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 );
}
Beispiel #9
0
#include <vips/intl.h>

#include <string.h>

#include <vips/vips.h>

#include "statistic.h"
#include "hough.h"

G_DEFINE_ABSTRACT_TYPE( VipsHough, vips_hough, VIPS_TYPE_STATISTIC );

static VipsImage *
vips_hough_new_accumulator( VipsHough *hough )
{
	VipsHoughClass *class = VIPS_HOUGH_GET_CLASS( hough );
	VipsStatistic *statistic = VIPS_STATISTIC( hough ); 

	VipsImage *accumulator; 

	accumulator = vips_image_new_memory(); 

	vips_image_pipelinev( accumulator,
		VIPS_DEMAND_STYLE_ANY, statistic->ready, NULL );

	if( class->init_accumulator( hough, accumulator ) ||
		vips_image_write_prepare( accumulator ) ) {
		g_object_unref( accumulator );
		return( NULL );
	}

	/* vips does not guarantee image mem is zeroed.