/* Call im__find_tboverlap via arg vector.
 */
static int
find_tboverlap_vec( im_object *argv )
{
	int bandno = *((int *) argv[2]);
	int xr = *((int *) argv[3]);
	int yr = *((int *) argv[4]);
	int xs = *((int *) argv[5]);
	int ys = *((int *) argv[6]);
	int halfcorrelation = *((int *) argv[7]);
	int halfarea = *((int *) argv[8]);
	int *dx0 = (int *) argv[9];
	int *dy0 = (int *) argv[10];
	double *scale1 = (double *) argv[11];
	double *angle1 = (double *) argv[12];
	double *dx1 = (double *) argv[13];
	double *dy1 = (double *) argv[14];

	IMAGE *t;
	int result;

	if( !(t = im_open( "find_tboverlap_vec", "p" )) )
		return( -1 );
	result = im__find_tboverlap( argv[0], argv[1], t, 
		bandno, 
		xr, yr, xs, ys, 
		halfcorrelation, halfarea,
		dx0, dy0, scale1, angle1, dx1, dy1 );
	im_close( t );

	return( result );
}
Exemple #2
0
/**
 * im_tbmosaic:
 * @ref: reference image
 * @sec: secondary image
 * @out: output image
 * @bandno: band to search for features
 * @xref: position in reference image
 * @yref: position in reference image
 * @xsec: position in secondary image
 * @ysec: position in secondary image
 * @hwindowsize: half window size
 * @hsearchsize: half search size 
 * @balancetype: no longer used
 * @mwidth: maximum blend width
 *
 * This operation joins two images top-bottom (with @ref on the top) 
 * given an approximate overlap.
 *
 * @sec is positioned so that the pixel (@xsec, @ysec) lies on top of the
 * pixel in @ref at (@xref, @yref). The overlap area is divided into three
 * sections, 20 high-contrast points in band @bandno of image @ref are found 
 * in each, and each high-contrast point is searched for in @sec using
 * @hwindowsize and @hsearchsize (see im_correl()). 
 *
 * A linear model is fitted to the 60 tie-points, points a long way from the
 * fit are discarded, and the model refitted until either too few points
 * remain or the model reaches good agreement. 
 *
 * The detected displacement is used with im_tbmerge() to join the two images
 * together. 
 *
 * @mwidth limits  the  maximum height of the
 * blend area.  A value of "-1" means "unlimited". The two images are blended 
 * with a raised cosine. 
 *
 * Pixels with all bands equal to zero are "transparent", that
 * is, zero pixels in the overlap area do not  contribute  to  the  merge.
 * This makes it possible to join non-rectangular images.
 *
 * If the number of bands differs, one of the images 
 * must have one band. In this case, an n-band image is formed from the 
 * one-band image by joining n copies of the one-band image together, and then
 * the two n-band images are operated upon.
 *
 * The two input images are cast up to the smallest common type (see table 
 * Smallest common format in 
 * <link linkend="VIPS-arithmetic">arithmetic</link>).
 *
 * See also: im_tbmerge(), im_lrmosaic(), im_insert(), im_global_balance().
 *
 * Returns: 0 on success, -1 on error
 */
int 
im_tbmosaic( IMAGE *ref, IMAGE *sec, IMAGE *out, 
	int bandno,
	int xref, int yref, int xsec, int ysec, 
	int hwindowsize, int hsearchsize,
	int balancetype,
	int mwidth )
{
	int dx0, dy0;
	double scale1, angle1, dx1, dy1;
	IMAGE *dummy;

	/* Correct overlap. dummy is just a placeholder used to ensure that
	 * memory used by the analysis phase is freed as soon as possible.
	 */
	if( !(dummy = im_open( "placeholder:1", "p" )) )
		return( -1 );
	if( im__find_tboverlap( ref, sec, dummy,
		bandno, 
		xref, yref, xsec, ysec,
		hwindowsize, hsearchsize,
		&dx0, &dy0,
		&scale1, &angle1, &dx1, &dy1 ) ) {
		im_close( dummy );
		return( -1 );
	}
	im_close( dummy );

	/* Merge top-bottom.
	 */
        if( im_tbmerge( ref, sec, out, dx0, dy0, mwidth ) )
		return( -1 ); 

	return( 0 );
}
Exemple #3
0
static int
vips_mosaic_build( VipsObject *object )
{
	VipsMosaic *mosaic = (VipsMosaic *) object;

	VipsImage *x;
	int dx0;
	int dy0;
	double scale1;
	double angle1;
	double dx1;
	double dy1;

	g_object_set( mosaic, "out", vips_image_new(), NULL ); 

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

	/* A placeholder used to ensure that memory used by the analysis 
	 * phase is freed as soon as possible.
	 */
	x = vips_image_new(); 

	switch( mosaic->direction ) { 
	case VIPS_DIRECTION_HORIZONTAL:
		if( im__find_lroverlap( mosaic->ref, mosaic->sec, x,
			mosaic->bandno, 
			mosaic->xref, mosaic->yref, mosaic->xsec, mosaic->ysec,
			mosaic->hwindow, mosaic->harea, 
			&dx0, &dy0,
			&scale1, &angle1, 
			&dx1, &dy1 ) ) {
			g_object_unref( x );
			return( -1 );
		}
		g_object_unref( x );
		break;

	case VIPS_DIRECTION_VERTICAL:
		if( im__find_tboverlap( mosaic->ref, mosaic->sec, x,
			mosaic->bandno, 
			mosaic->xref, mosaic->yref, mosaic->xsec, mosaic->ysec,
			mosaic->hwindow, mosaic->harea, 
			&dx0, &dy0,
			&scale1, &angle1, 
			&dx1, &dy1 ) ) {
			g_object_unref( x );
			return( -1 );
		}
		g_object_unref( x );
		break;

	default:
		g_assert_not_reached();

		/* Compiler warnings.
		 */
		dx0 = 0;
		dy0 = 0;
		scale1 = 1;
		angle1 = 1;
		dx1 = 0;
		dy1 = 0;
	}

	g_object_set( mosaic, 
		"dx0", dx0, 
		"dy0", dy0,
		"scale1", scale1, 
		"angle1", angle1, 
		"dx1", dx1, 
		"dy1", dy1,
		NULL ); 

	if( vips_merge( mosaic->ref, mosaic->sec, &x, 
		mosaic->direction, mosaic->dx0, mosaic->dy0, 
		"mblend", mosaic->mblend,
		NULL ) )
		return( -1 );
	if( vips_image_write( x, mosaic->out ) ) {
		g_object_unref( x ); 
		return( -1 ); 
	}
	g_object_unref( x ); 

	return( 0 );
}