diff --git a/ChangeLog b/ChangeLog index b9cc2604..1e8377b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,7 +33,7 @@ - added im_tile_cache_random() to help nip2 - added hough_circle() to vips7 C++ API - added Travis CI config, thanks Lovell -- im_*merge() redone as a class +- im_*merge(), im_*mosaic() redone as classes 6/3/14 started 7.38.6 - grey ramp minimum was wrong diff --git a/TODO b/TODO index 57419b61..6018fa34 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,7 @@ nip2 uses: im_*merge() done - im_*mosaic() + im_*mosaic() done im_global_balancef() im_remosaic() im_match_linear() diff --git a/libvips/include/vips/mosaicing.h b/libvips/include/vips/mosaicing.h index fee25e76..57f9f6b8 100644 --- a/libvips/include/vips/mosaicing.h +++ b/libvips/include/vips/mosaicing.h @@ -41,6 +41,9 @@ extern "C" { int vips_merge( VipsImage *ref, VipsImage *sec, VipsImage **out, VipsDirection direction, int dx, int dy, ... ) __attribute__((sentinel)); +int vips_mosaic( VipsImage *ref, VipsImage *sec, VipsImage **out, + VipsDirection direction, int xref, int yref, int xsec, int ysec, ... ) + __attribute__((sentinel)); diff --git a/libvips/mosaicing/Makefile.am b/libvips/mosaicing/Makefile.am index 3a593c3c..f53085c5 100644 --- a/libvips/mosaicing/Makefile.am +++ b/libvips/mosaicing/Makefile.am @@ -1,8 +1,9 @@ noinst_LTLIBRARIES = libmosaicing.la libmosaicing_la_SOURCES = \ - merge.c \ mosaicing.c \ + merge.c \ + mosaic.c \ \ im_align_bands.c \ match.c \ diff --git a/libvips/mosaicing/im_lrmerge.c b/libvips/mosaicing/im_lrmerge.c index 79057039..d7cb93d1 100644 --- a/libvips/mosaicing/im_lrmerge.c +++ b/libvips/mosaicing/im_lrmerge.c @@ -1088,43 +1088,6 @@ im__lrmerge( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth ) return ( 0 ); } -/** - * im_lrmerge: - * @ref: reference image - * @sec: secondary image - * @out: output image - * @dx: displacement of ref from sec - * @dy: displacement of ref from sec - * @mwidth: maximum seam width - * - * This operation joins two images left-right (with @ref on the left) with a - * smooth seam. - * - * 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 - * arithmetic). - * - * @dx and @dy give the displacement of @sec relative to @ref, in other words, - * the vector to get from the origin of @sec to the origin of @ref, in other - * words, @dx will generally be a negative number. - * - * @mwidth limits the maximum width 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. - * - * See also: im_lrmosaic(), im_tbmerge(), im_match_linear(), im_insert(). - * - * Returns: 0 on success, -1 on error - */ int im_lrmerge( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth ) { diff --git a/libvips/mosaicing/im_lrmosaic.c b/libvips/mosaicing/im_lrmosaic.c index edd0fe5f..9ef9f297 100644 --- a/libvips/mosaicing/im_lrmosaic.c +++ b/libvips/mosaicing/im_lrmosaic.c @@ -238,58 +238,6 @@ im__find_lroverlap( IMAGE *ref_in, IMAGE *sec_in, IMAGE *out, return( 0 ); } -/** - * im_lrmosaic: - * @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 left-right (with @ref on the left) - * 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_lrmerge() to join the two images - * together. - * - * @mwidth limits the maximum width 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 - * arithmetic). - * - * See also: im_lrmerge(), im_tbmosaic(), im_insert(), im_global_balance(). - * - * Returns: 0 on success, -1 on error - */ int im_lrmosaic( IMAGE *ref, IMAGE *sec, IMAGE *out, int bandno, diff --git a/libvips/mosaicing/im_tbmerge.c b/libvips/mosaicing/im_tbmerge.c index 1aea0d56..dda9997d 100644 --- a/libvips/mosaicing/im_tbmerge.c +++ b/libvips/mosaicing/im_tbmerge.c @@ -705,43 +705,6 @@ im__tbmerge( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth ) return ( 0 ); } -/** - * im_tbmerge: - * @ref: reference image - * @sec: secondary image - * @out: output image - * @dx: displacement of ref from sec - * @dy: displacement of ref from sec - * @mwidth: maximum seam width - * - * This operation joins two images top-bottom (with @ref on the top) with a - * smooth seam. - * - * 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 - * arithmetic). - * - * @dx and @dy give the displacement of @sec relative to @ref, in other words, - * the vector to get from the origin of @sec to the origin of @ref, in other - * words, @dx will generally be a negative number. - * - * @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. - * - * See also: im_lrmosaic(), im_lrmerge(), im_match_linear(), im_insert(). - * - * Returns: 0 on success, -1 on error - */ int im_tbmerge( IMAGE *ref, IMAGE *sec, IMAGE *out, int dx, int dy, int mwidth ) { diff --git a/libvips/mosaicing/im_tbmosaic.c b/libvips/mosaicing/im_tbmosaic.c index b0d24b3c..29d83bcd 100644 --- a/libvips/mosaicing/im_tbmosaic.c +++ b/libvips/mosaicing/im_tbmosaic.c @@ -214,58 +214,6 @@ im__find_tboverlap( IMAGE *ref_in, IMAGE *sec_in, IMAGE *out, 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 - * arithmetic). - * - * 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, diff --git a/libvips/mosaicing/merge.c b/libvips/mosaicing/merge.c index 581ddcbd..81bd9a54 100644 --- a/libvips/mosaicing/merge.c +++ b/libvips/mosaicing/merge.c @@ -82,6 +82,7 @@ vips_merge_build( VipsObject *object ) case VIPS_DIRECTION_VERTICAL: if( im_tbmerge( merge->ref, merge->sec, merge->out, merge->dx, merge->dy, merge->mblend ) ) + return( -1 ); break; default: @@ -167,6 +168,8 @@ vips_merge_init( VipsMerge *merge ) * @dx: displacement of ref from sec * @dy: displacement of ref from sec * @...: %NULL-terminated list of optional named arguments + * + * Optional arguments: * * @mblend: maximum blend size * @@ -194,7 +197,7 @@ vips_merge_init( VipsMerge *merge ) * is, zero pixels in the overlap area do not contribute to the merge. * This makes it possible to join non-rectangular images. * - * See also: im_lrmosaic(), im_tbmerge(), im_match_linear(), im_insert(). + * See also: vips_mosaic(), vips_insert(). * * Returns: 0 on success, -1 on error */ @@ -206,7 +209,8 @@ vips_merge( VipsImage *ref, VipsImage *sec, VipsImage **out, int result; va_start( ap, dy ); - result = vips_call_split( "merge", ap, ref, sec, out, direction ); + result = vips_call_split( "merge", ap, + ref, sec, out, direction, dx, dy ); va_end( ap ); return( result ); diff --git a/libvips/mosaicing/mosaic.c b/libvips/mosaicing/mosaic.c new file mode 100644 index 00000000..37a7d46d --- /dev/null +++ b/libvips/mosaicing/mosaic.c @@ -0,0 +1,265 @@ +/* mosaic two images left/right or up/down + * + * 22/5/14 + * - from vips_mosaic() + */ + +/* + + This file is part of VIPS. + + VIPS is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA + + */ + +/* + + These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk + + */ + +/* This is a simple wrapper over the old vips7 functions. At some point we + * should rewrite this as a pure vips8 class and redo the vips7 functions as + * wrappers over this. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /*HAVE_CONFIG_H*/ +#include + +#include + +#include + +typedef struct { + VipsOperation parent_instance; + + VipsImage *ref; + VipsImage *sec; + VipsImage *out; + VipsDirection direction; + int xref; + int yref; + int xsec; + int ysec; + int mblend; + int bandno; + int hwindow; + int harea; + +} VipsMosaic; + +typedef VipsOperationClass VipsMosaicClass; + +G_DEFINE_TYPE( VipsMosaic, vips_mosaic, VIPS_TYPE_OPERATION ); + +static int +vips_mosaic_build( VipsObject *object ) +{ + VipsMosaic *mosaic = (VipsMosaic *) object; + + g_object_set( mosaic, "out", vips_image_new(), NULL ); + + if( VIPS_OBJECT_CLASS( vips_mosaic_parent_class )->build( object ) ) + return( -1 ); + + switch( mosaic->direction ) { + case VIPS_DIRECTION_HORIZONTAL: + if( im_lrmosaic( mosaic->ref, mosaic->sec, mosaic->out, + mosaic->bandno, + mosaic->xref, mosaic->yref, + mosaic->xsec, mosaic->ysec, + mosaic->hwindow, mosaic->harea, + 0, + mosaic->mblend ) ) + return( -1 ); + break; + + case VIPS_DIRECTION_VERTICAL: + if( im_tbmosaic( mosaic->ref, mosaic->sec, mosaic->out, + mosaic->bandno, + mosaic->xref, mosaic->yref, + mosaic->xsec, mosaic->ysec, + mosaic->hwindow, mosaic->harea, + 0, + mosaic->mblend ) ) + return( -1 ); + break; + + default: + g_assert( 0 ); + } + + return( 0 ); +} + +static void +vips_mosaic_class_init( VipsMosaicClass *class ) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS( class ); + VipsObjectClass *object_class = (VipsObjectClass *) class; + + gobject_class->set_property = vips_object_set_property; + gobject_class->get_property = vips_object_get_property; + + object_class->nickname = "mosaic"; + object_class->description = _( "mosaic two images" ); + object_class->build = vips_mosaic_build; + + VIPS_ARG_IMAGE( class, "ref", 1, + _( "Reference" ), + _( "Reference image" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, ref ) ); + + VIPS_ARG_IMAGE( class, "sec", 2, + _( "Secondary" ), + _( "Secondary image" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, sec ) ); + + VIPS_ARG_IMAGE( class, "out", 3, + _( "Output" ), + _( "Output image" ), + VIPS_ARGUMENT_REQUIRED_OUTPUT, + G_STRUCT_OFFSET( VipsMosaic, out ) ); + + VIPS_ARG_ENUM( class, "direction", 4, + _( "Direction" ), + _( "Horizontal or vertcial mosaic" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, direction ), + VIPS_TYPE_DIRECTION, VIPS_DIRECTION_HORIZONTAL ); + + VIPS_ARG_INT( class, "xref", 5, + _( "xref" ), + _( "Position of reference tie-point" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, xref ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "yref", 6, + _( "yref" ), + _( "Position of reference tie-point" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, yref ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "xsec", 7, + _( "xsec" ), + _( "Position of reference tie-point" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, xsec ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "ysec", 8, + _( "ysec" ), + _( "Position of reference tie-point" ), + VIPS_ARGUMENT_REQUIRED_INPUT, + G_STRUCT_OFFSET( VipsMosaic, ysec ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "hwindow", 9, + _( "hwindow" ), + _( "Half window size" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsMosaic, hwindow ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "harea", 10, + _( "harea" ), + _( "Half area size" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsMosaic, harea ), + 0, 1000000000, 1 ); + + VIPS_ARG_INT( class, "mblend", 11, + _( "Max blend" ), + _( "Maximum blend size" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsMosaic, mblend ), + 0, 10000, 10 ); + + VIPS_ARG_INT( class, "bandno", 12, + _( "Search band" ), + _( "Band to search for features on" ), + VIPS_ARGUMENT_OPTIONAL_INPUT, + G_STRUCT_OFFSET( VipsMosaic, bandno ), + 0, 10000, 0 ); + +} + +static void +vips_mosaic_init( VipsMosaic *mosaic ) +{ + mosaic->mblend = 10; + mosaic->hwindow = 5; + mosaic->harea = 15; +} + +/** + * vips_mosaic: + * @ref: reference image + * @sec: secondary image + * @out: output image + * @direction: horizontal or vertical join + * @xref: position in reference image + * @yref: position in reference image + * @xsec: position in secondary image + * @ysec: position in secondary image + * + * Optional arguments: + * + * @bandno: band to search for features + * @hwindow: half window size + * @harea: half search size + * @mblend: maximum blend size + * + * This operation joins two images left-right (with @ref on the left) or + * top-bottom (with @ref above) 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 + * @hwindow and @harea (see vips_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 vips_merge() to join the two images + * together. + * + * See also: vips_merge(), vips_insert(). + * + * Returns: 0 on success, -1 on error + */ +int +vips_mosaic( VipsImage *ref, VipsImage *sec, VipsImage **out, + VipsDirection direction, int xref, int yref, int xsec, int ysec, ... ) +{ + va_list ap; + int result; + + va_start( ap, ysec ); + result = vips_call_split( "mosaic", ap, ref, sec, out, + direction, xref, yref, xsec, ysec ); + va_end( ap ); + + return( result ); +} diff --git a/libvips/mosaicing/mosaicing.c b/libvips/mosaicing/mosaicing.c index dab6f3cf..47098262 100644 --- a/libvips/mosaicing/mosaicing.c +++ b/libvips/mosaicing/mosaicing.c @@ -96,6 +96,8 @@ void vips_mosaicing_operation_init( void ) { extern int vips_merge_get_type( void ); + extern int vips_mosaic_get_type( void ); vips_merge_get_type(); + vips_mosaic_get_type(); }