int im_match_linear_search( IMAGE *ref, IMAGE *sec, IMAGE *out, int xr1, int yr1, int xs1, int ys1, int xr2, int yr2, int xs2, int ys2, int hwindowsize, int hsearchsize ) { int xs3, ys3; int xs4, ys4; double cor1, cor2; /* Search for new tie-points. */ if( im_correl( ref, sec, xr1, yr1, xs1, ys1, hwindowsize, hsearchsize, &cor1, &xs3, &ys3 ) ) return( -1 ); if( im_correl( ref, sec, xr2, yr2, xs2, ys2, hwindowsize, hsearchsize, &cor2, &xs4, &ys4 ) ) return( -1 ); /* ... and match_linear. */ if( im_match_linear( ref, sec, out, xr1, yr1, xs3, ys3, xr2, yr2, xs4, ys4 ) ) return( -1 ); return( 0 ); }
int im__chkpair( IMAGE *ref, IMAGE *sec, TIE_POINTS *points ) { int i; int x, y; double correlation; const int hcor = points->halfcorsize; const int harea = points->halfareasize; /* Check images. */ if( im_incheck( ref ) || im_incheck( sec ) ) return( -1 ); if( ref->Bands != sec->Bands || ref->BandFmt != sec->BandFmt || ref->Coding != sec->Coding ) { im_error( "im_chkpair", "%s", _( "inputs incompatible" ) ); return( -1 ); } if( ref->Bands != 1 || ref->BandFmt != IM_BANDFMT_UCHAR ) { im_error( "im_chkpair", "%s", _( "help!" ) ); return( -1 ); } for( i = 0; i < points->nopoints; i++ ) { /* Find correlation point. */ if( im_correl( ref, sec, points->x_reference[i], points->y_reference[i], points->x_reference[i], points->y_reference[i], hcor, harea, &correlation, &x, &y ) ) return( -1 ); /* And note in x_secondary. */ points->x_secondary[i] = x; points->y_secondary[i] = y; points->correlation[i] = correlation; /* Note each dx, dy too. */ points->dx[i] = points->x_secondary[i] - points->x_reference[i]; points->dy[i] = points->y_secondary[i] - points->y_reference[i]; } return( 0 ); }
/* Call im_correl via arg vector. */ static int correl_vec( im_object *argv ) { int xref = *((int *) argv[2]); int yref = *((int *) argv[3]); int xsec = *((int *) argv[4]); int ysec = *((int *) argv[5]); int cor = *((int *) argv[6]); int area = *((int *) argv[7]); int *x = (int *) argv[8]; int *y = (int *) argv[9]; double *correlation = (double *) argv[10]; return( im_correl( argv[0], argv[1], xref, yref, xsec, ysec, cor, area, correlation, x, y ) ); }
/* Like rotjoin, but do a search to refine the tie-points. */ static int rotjoin_search( IMAGE *ref, IMAGE *sec, IMAGE *out, joinfn jfn, 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 trn; double cor1, cor2; double a, b, dx, dy; double xs3, ys3; double xs4, ys4; int xs5, ys5; int xs6, ys6; double xs7, ys7; double xs8, ys8; /* Temps. */ IMAGE *t[3]; if( im_open_local_array( out, t, 3, "rotjoin_search", "p" ) ) return( -1 ); /* Unpack LABQ to LABS for correlation. */ if( ref->Coding == IM_CODING_LABQ ) { if( im_LabQ2LabS( ref, t[0] ) ) return( -1 ); } else t[0] = ref; if( sec->Coding == IM_CODING_LABQ ) { if( im_LabQ2LabS( sec, t[1] ) ) return( -1 ); } else t[1] = sec; /* Solve to get scale + rot + disp. */ if( im__coeff( xr1, yr1, xs1, ys1, xr2, yr2, xs2, ys2, &a, &b, &dx, &dy ) || apply_similarity( &trn, t[1], t[2], a, b, dx, dy ) ) return( -1 ); /* Map points on sec to rotated image. */ im__transform_forward( &trn, xs1, ys1, &xs3, &ys3 ); im__transform_forward( &trn, xs2, ys2, &xs4, &ys4 ); /* Refine tie-points on rotated image. Remember the clip * im__transform_set_area() has set, and move the sec tie-points * accordingly. */ if( im_correl( t[0], t[2], xr1, yr1, xs3 - trn.oarea.left, ys3 - trn.oarea.top, halfcorrelation, halfarea, &cor1, &xs5, &ys5 ) ) return( -1 ); if( im_correl( t[0], t[2], xr2, yr2, xs4 - trn.oarea.left, ys4 - trn.oarea.top, halfcorrelation, halfarea, &cor2, &xs6, &ys6 ) ) return( -1 ); #ifdef DEBUG printf( "rotjoin_search: nudged pair 1 from %d, %d to %d, %d\n", xs3 - trn.oarea.left, ys3 - trn.oarea.top, xs5, ys5 ); printf( "rotjoin_search: nudged pair 2 from %d, %d to %d, %d\n", xs4 - trn.oarea.left, ys4 - trn.oarea.top, xs6, ys6 ); #endif /*DEBUG*/ /* Put the sec tie-points back into output space. */ xs5 += trn.oarea.left; ys5 += trn.oarea.top; xs6 += trn.oarea.left; ys6 += trn.oarea.top; /* ... and now back to input space again. */ im__transform_inverse( &trn, xs5, ys5, &xs7, &ys7 ); im__transform_inverse( &trn, xs6, ys6, &xs8, &ys8 ); /* Recalc the transform using the refined points. */ if( im__coeff( xr1, yr1, xs7, ys7, xr2, yr2, xs8, ys8, &a, &b, &dx, &dy ) ) return( -1 ); /* Scale and rotate final. */ if( jfn( ref, sec, out, a, b, dx, dy, mwidth ) ) return( -1 ); return( 0 ); }