static int vips_merge_build( VipsObject *object ) { VipsMerge *merge = (VipsMerge *) object; g_object_set( merge, "out", vips_image_new(), NULL ); if( VIPS_OBJECT_CLASS( vips_merge_parent_class )->build( object ) ) return( -1 ); switch( merge->direction ) { case VIPS_DIRECTION_HORIZONTAL: if( im_lrmerge( merge->ref, merge->sec, merge->out, merge->dx, merge->dy, merge->mblend ) ) return( -1 ); break; case VIPS_DIRECTION_VERTICAL: if( im_tbmerge( merge->ref, merge->sec, merge->out, merge->dx, merge->dy, merge->mblend ) ) return( -1 ); break; default: g_assert( 0 ); } return( 0 ); }
int im_lrmosaic( 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_lroverlap( 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 left right. */ if( im_lrmerge( ref, sec, out, dx0, dy0, mwidth ) ) return( -1 ); return( 0 ); }
/* Call im_lrmerge via arg vector. */ static int lrmerge_vec( im_object *argv ) { int dx = *((int *) argv[3]); int dy = *((int *) argv[4]); int mwidth = *((int *) argv[5]); return( im_lrmerge( argv[0], argv[1], argv[2], dx, dy, mwidth ) ); }
/* 1st order mosaic using im__find_lroverlap() ... does not work too well :( * Look at im__find_lroverlap() for problem? */ static int old_lrmosaic1( IMAGE *ref, IMAGE *sec, IMAGE *out, int bandno, int xr1, int yr1, int xs1, int ys1, int xr2, int yr2, int xs2, int ys2, int halfcorrelation, int halfarea, int balancetype, int mwidth ) { Transformation trn1, trn2; int dx0, dy0; double a, b, dx, dy; double a1, b1, dx1, dy1; double af, bf, dxf, dyf; int xpos, ypos; int xpos1, ypos1; /* Temps. */ IMAGE *t1 = im_open_local( out, "im_lrmosaic1:1", "p" ); IMAGE *t2 = im_open_local( out, "im_lrmosaic1:2", "p" ); IMAGE *dummy; if( !t1 || !t2 ) return( -1 ); /* Solve to get scale + rot + disp. */ if( im__coeff( xr1, yr1, xs1, ys1, xr2, yr2, xs2, ys2, &a, &b, &dx, &dy ) || apply_similarity( &trn1, sec, t1, a, b, dx, dy ) ) return( -1 ); /* Correct tie-points. 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_lroverlap( ref, t1, dummy, bandno, -trn1.area.left, -trn1.area.top, 0, 0, halfcorrelation, halfarea, &dx0, &dy0, &a1, &b1, &dx1, &dy1 ) ) { im_close( dummy ); return( -1 ); } im_close( dummy ); /* Now combine the two transformations to get a corrected transform. */ af = a1 * a - b1 * b; bf = a1 * b + b1 * a; dxf = a1 * dx - b1 * dy + dx1; dyf = b1 * dx + a1 * dy + dy1; printf( "transform was: a = %g, b = %g, dx = %g, dy = %g\n", a, b, dx, dy ); printf( "correction: a = %g, b = %g, dx = %g, dy = %g\n", a1, b1, dx1, dy1 ); printf( "final: a = %g, b = %g, dx = %g, dy = %g\n", af, bf, dxf, dyf ); /* Scale and rotate final. */ if( apply_similarity( &trn2, sec, t2, af, bf, dxf, dyf ) ) return( -1 ); printf( "disp: trn1 left = %d, top = %d\n", trn1.area.left, trn1.area.top ); printf( "disp: trn2 left = %d, top = %d\n", trn2.area.left, trn2.area.top ); /* And join to ref. */ if( im_lrmerge( ref, t2, out, -trn2.area.left, -trn2.area.top, mwidth ) ) return( -1 ); return( 0 ); }