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 ); }
/** * 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 ); }
/* Call im_tbmerge via arg vector. */ static int tbmerge_vec( im_object *argv ) { int dx = *((int *) argv[3]); int dy = *((int *) argv[4]); int mwidth = *((int *) argv[5]); return( im_tbmerge( argv[0], argv[1], argv[2], dx, dy, mwidth ) ); }