/* Call im_spcor via arg vector. */ static int spcor_vec( im_object *argv ) { return( im_spcor( argv[0], argv[1], argv[2] ) ); }
/** * im_correl: * @ref: reference image * @sec: secondary image * @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 * @correlation: return detected correlation * @x: return found position * @y: return found position * * This operation finds the position of @sec within @ref. * * The area around * (@xsec, @ysec) is searched for the best match to the area around (@xref, * @yref). It searches an area of size @hsearchsize for a * match of size @hwindowsize. The position of the best match is * returned, together with the correlation at that point. * * Only the first band of each image is correlated. @ref and @sec may be * very large --- the function extracts and generates just the * parts needed. Correlation is done with im_spcor(); the position of * the maximum is found with im_maxpos(). * * See also: im_match_linear(), im_match_linear_search(), im_lrmosaic(). * * Returns: 0 on success, -1 on error */ int im_correl( IMAGE *ref, IMAGE *sec, int xref, int yref, int xsec, int ysec, int hwindowsize, int hsearchsize, double *correlation, int *x, int *y ) { IMAGE *surface = im_open( "surface", "t" ); IMAGE *t1, *t2, *t3, *t4; Rect refr, secr; Rect winr, srhr; Rect wincr, srhcr; if( !surface || !(t1 = im_open_local( surface, "correlate:1", "p" )) || !(t2 = im_open_local( surface, "correlate:1", "p" )) || !(t3 = im_open_local( surface, "correlate:1", "p" )) || !(t4 = im_open_local( surface, "correlate:1", "p" )) ) return( -1 ); /* Find position of window and search area, and clip against image * size. */ refr.left = 0; refr.top = 0; refr.width = ref->Xsize; refr.height = ref->Ysize; winr.left = xref - hwindowsize; winr.top = yref - hwindowsize; winr.width = hwindowsize*2 + 1; winr.height = hwindowsize*2 + 1; im_rect_intersectrect( &refr, &winr, &wincr ); secr.left = 0; secr.top = 0; secr.width = sec->Xsize; secr.height = sec->Ysize; srhr.left = xsec - hsearchsize; srhr.top = ysec - hsearchsize; srhr.width = hsearchsize*2 + 1; srhr.height = hsearchsize*2 + 1; im_rect_intersectrect( &secr, &srhr, &srhcr ); /* Extract window and search area. */ if( im_extract_area( ref, t1, wincr.left, wincr.top, wincr.width, wincr.height ) || im_extract_area( sec, t2, srhcr.left, srhcr.top, srhcr.width, srhcr.height ) ) { im_close( surface ); return( -1 ); } /* Make sure we have just one band. From im_*mosaic() we will, but * from im_match_linear_search() etc. we may not. */ if( t1->Bands != 1 ) { if( im_extract_band( t1, t3, 0 ) ) { im_close( surface ); return( -1 ); } t1 = t3; } if( t2->Bands != 1 ) { if( im_extract_band( t2, t4, 0 ) ) { im_close( surface ); return( -1 ); } t2 = t4; } /* Search! */ if( im_spcor( t2, t1, surface ) ) { im_close( surface ); return( -1 ); } /* Find maximum of correlation surface. */ if( im_maxpos( surface, x, y, correlation ) ) { im_close( surface ); return( -1 ); } im_close( surface ); /* Translate back to position within sec. */ *x += srhcr.left; *y += srhcr.top; return( 0 ); }