/* Call im__find_lroverlap via arg vector. */ static int find_lroverlap_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_lroverlap_vec", "p" )) ) return( -1 ); result = im__find_lroverlap( argv[0], argv[1], t, bandno, xr, yr, xs, ys, halfcorrelation, halfarea, dx0, dy0, scale1, angle1, dx1, dy1 ); im_close( t ); return( result ); }
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 ); }
/* 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 ); }
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 ); }