added yafrnohalo

This commit is contained in:
John Cupitt 2008-10-29 22:23:28 +00:00
parent ab99b59e1c
commit 92e10f403d
9 changed files with 1302 additions and 79 deletions

View File

@ -3,8 +3,9 @@
- bumped version number to 7.17.0
- re-added type.[hc]
- added vipsinterpolate and im_affinei
- added yafr-smooth interpolation
- added yafrsmooth interpolation
- added yafrtest
- added yafrnohalo
11/9/08 started 7.16.3
- oop typo in manpage for im_project()

View File

@ -25,6 +25,7 @@ pkginclude_HEADERS = \
version.h \
vips.h \
yafrsmooth.h \
yafrnohalo.h \
yafrtest.h \
vips \
intl.h \

View File

@ -501,7 +501,8 @@ typedef struct {
#include <vips/dispatch.h>
#include <vips/region.h>
#include <vips/interpolate.h>
#include <vips/yafr.h>
#include <vips/yafrsmooth.h>
#include <vips/yafrnohalo.h>
#include <vips/yafrtest.h>
#include <vips/semaphore.h>
#include <vips/threadgroup.h>

100
include/vips/yafrnohalo.h Normal file
View File

@ -0,0 +1,100 @@
/* YAFRNOHALO interpolator.
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifndef VIPS_YAFRNOHALO_H
#define VIPS_YAFRNOHALO_H
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
#define VIPS_TYPE_INTERPOLATE_YAFRNOHALO (vips_interpolate_yafrnohalo_get_type())
#define VIPS_INTERPOLATE_YAFRNOHALO( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
VIPS_TYPE_INTERPOLATE_YAFRNOHALO, VipsInterpolateYafrnohalo ))
#define VIPS_INTERPOLATE_YAFRNOHALO_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), \
VIPS_TYPE_INTERPOLATE_YAFRNOHALO, VipsInterpolateYafrnohaloClass))
#define VIPS_IS_INTERPOLATE_YAFRNOHALO( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE_YAFRNOHALO ))
#define VIPS_IS_INTERPOLATE_YAFRNOHALO_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE_YAFRNOHALO ))
#define VIPS_INTERPOLATE_YAFRNOHALO_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
VIPS_TYPE_INTERPOLATE_YAFRNOHALO, VipsInterpolateYafrnohaloClass ))
typedef struct _VipsInterpolateYafrnohalo {
VipsInterpolate parent_object;
/* "sharpening" is a continuous method parameter which is
* proportional to the amount of "diagonal straightening" which the
* nonlinear correction part of the method may add to the underlying
* linear scheme. You may also think of it as a sharpening
* parameter: higher values correspond to more sharpening, and
* negative values lead to strange looking effects.
*
* The default value is sharpening = 4/3 when the scheme being
* "straightened" is bilinear---as is the case here. This value
* fixes key pixel values near the diagonal boundary between two
* monochrome regions (the diagonal boundary pixel values being set
* to the halfway colour).
*
* If resampling seems to add unwanted texture artifacts, push
* sharpening toward 0. It is not generally not recommended to set
* sharpening to a value larger than 2.
*
* In order to simplify interfacing with users, the parameter which
* should be set by the user is normalized so that user_sharpening =
* 1 when sharpening is equal to the recommended value. Consistently
* with the above discussion, values of user_sharpening between 0
* and about 1.5 give good results.
*/
double sharpening;
} VipsInterpolateYafrnohalo;
typedef struct _VipsInterpolateYafrnohaloClass {
VipsInterpolateClass parent_class;
} VipsInterpolateYafrnohaloClass;
GType vips_interpolate_yafrnohalo_get_type( void );
VipsInterpolate *vips_interpolate_yafrnohalo_new( void );
void vips_interpolate_yafrnohalo_set_sharpening( VipsInterpolateYafrnohalo *,
double sharpening );
/* Convenience: return a static default yafrnohalo, so no need to free it.
*/
VipsInterpolate *vips_interpolate_yafrnohalo_static( void );
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /*VIPS_YAFRNOHALO_H*/

View File

@ -1,4 +1,4 @@
/* YAFR interpolator.
/* YAFRSMOOTH interpolator.
*/
/*
@ -27,29 +27,30 @@
*/
#ifndef VIPS_YAFR_H
#define VIPS_YAFR_H
#ifndef VIPS_YAFRSMOOTH_H
#define VIPS_YAFRSMOOTH_H
#ifdef __cplusplus
extern "C" {
#endif /*__cplusplus*/
#define VIPS_TYPE_INTERPOLATE_YAFR (vips_interpolate_yafr_get_type())
#define VIPS_INTERPOLATE_YAFR( obj ) \
#define VIPS_TYPE_INTERPOLATE_YAFRSMOOTH \
(vips_interpolate_yafrsmooth_get_type())
#define VIPS_INTERPOLATE_YAFRSMOOTH( obj ) \
(G_TYPE_CHECK_INSTANCE_CAST( (obj), \
VIPS_TYPE_INTERPOLATE_YAFR, VipsInterpolateYafr ))
#define VIPS_INTERPOLATE_YAFR_CLASS( klass ) \
VIPS_TYPE_INTERPOLATE_YAFRSMOOTH, VipsInterpolateYafrsmooth ))
#define VIPS_INTERPOLATE_YAFRSMOOTH_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_CAST( (klass), \
VIPS_TYPE_INTERPOLATE_YAFR, VipsInterpolateYafrClass))
#define VIPS_IS_INTERPOLATE_YAFR( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE_YAFR ))
#define VIPS_IS_INTERPOLATE_YAFR_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE_YAFR ))
#define VIPS_INTERPOLATE_YAFR_GET_CLASS( obj ) \
VIPS_TYPE_INTERPOLATE_YAFRSMOOTH, VipsInterpolateYafrsmoothClass))
#define VIPS_IS_INTERPOLATE_YAFRSMOOTH( obj ) \
(G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE_YAFRSMOOTH ))
#define VIPS_IS_INTERPOLATE_YAFRSMOOTH_CLASS( klass ) \
(G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE_YAFRSMOOTH ))
#define VIPS_INTERPOLATE_YAFRSMOOTH_GET_CLASS( obj ) \
(G_TYPE_INSTANCE_GET_CLASS( (obj), \
VIPS_TYPE_INTERPOLATE_YAFR, VipsInterpolateYafrClass ))
VIPS_TYPE_INTERPOLATE_YAFRSMOOTH, VipsInterpolateYafrsmoothClass ))
typedef struct _VipsInterpolateYafr {
typedef struct _VipsInterpolateYafrsmooth {
VipsInterpolate parent_object;
/* "sharpening" is a continuous method parameter which is
@ -82,25 +83,25 @@ typedef struct _VipsInterpolateYafr {
* and about 3.625 give good results.
*/
double sharpening;
} VipsInterpolateYafr;
} VipsInterpolateYafrsmooth;
typedef struct _VipsInterpolateYafrClass {
typedef struct _VipsInterpolateYafrsmoothClass {
VipsInterpolateClass parent_class;
} VipsInterpolateYafrClass;
} VipsInterpolateYafrsmoothClass;
GType vips_interpolate_yafr_get_type( void );
VipsInterpolate *vips_interpolate_yafr_new( void );
void vips_interpolate_yafr_set_sharpening( VipsInterpolateYafr *,
GType vips_interpolate_yafrsmooth_get_type( void );
VipsInterpolate *vips_interpolate_yafrsmooth_new( void );
void vips_interpolate_yafrsmooth_set_sharpening( VipsInterpolateYafrsmooth *,
double sharpening );
/* Convenience: return a static default yafr, so no need to free it.
/* Convenience: return a static default yafrsmooth, so no need to free it.
*/
VipsInterpolate *vips_interpolate_yafr_static( void );
VipsInterpolate *vips_interpolate_yafrsmooth_static( void );
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#endif /*VIPS_YAFR_H*/
#endif /*VIPS_YAFRSMOOTH_H*/

View File

@ -1,7 +1,6 @@
noinst_LTLIBRARIES = libmosaicing.la
libmosaicing_la_SOURCES = \
yafrtest.cpp \
im_affinei.c \
im_affine.c \
im_align_bands.c \
@ -14,7 +13,9 @@ libmosaicing_la_SOURCES = \
im_chkpair.c \
im_clinear.c \
interpolate.c \
yafr.c \
yafrsmooth.c \
yafrnohalo.c \
yafrtest.cpp \
im_improve.c \
im_initialize.c \
im_lrcalcon.c \

File diff suppressed because it is too large Load Diff

View File

@ -569,19 +569,23 @@ affinei_vec( im_object *argv )
break;
case 4:
interpolate = vips_interpolate_yafr_new();
interpolate = vips_interpolate_yafrsmooth_new();
break;
case 5:
interpolate = vips_interpolate_yafr_new();
vips_interpolate_yafr_set_sharpening(
VIPS_INTERPOLATE_YAFR( interpolate ), 2.0 );
interpolate = vips_interpolate_yafrsmooth_new();
vips_interpolate_yafrsmooth_set_sharpening(
VIPS_INTERPOLATE_YAFRSMOOTH( interpolate ), 2.0 );
break;
case 6:
interpolate = vips_interpolate_yafr_test_new();
break;
case 7:
interpolate = vips_interpolate_yafrnohalo_new();
break;
default:
im_error( "affinei_vec", _( "bad interpolation" ) );
return( -1 );

View File

@ -1,4 +1,4 @@
/* vipsinterpolateyafr ... yarf as a vips interpolate class
/* yafrsmooth ... yafr-smooth as a vips interpolate class
*/
/*
@ -50,16 +50,16 @@
*/
#define FLOOR( V ) ((V) >= 0 ? (int)(V) : (int)((V) - 1))
static VipsInterpolateClass *vips_interpolate_yafr_parent_class = NULL;
static VipsInterpolateClass *vips_interpolate_yafrsmooth_parent_class = NULL;
/* Copy-paste of gegl-sampler-yafr-smooth.c starts
/* Copy-paste of gegl-sampler-yafrsmooth-smooth.c starts
*/
/*
* 2008 (c) Nicolas Robidoux (developer of Yet Another Fast
* Resampler).
*
* Acknowledgement: N. Robidoux's research on YAFR funded in part by
* Acknowledgement: N. Robidoux's research on YAFRSMOOTH funded in part by
* an NSERC (National Science and Engineering Research Council of
* Canada) Discovery Grant.
*/
@ -85,7 +85,7 @@ static VipsInterpolateClass *vips_interpolate_yafr_parent_class = NULL;
#endif
/*
* YAFR = Yet Another Fast Resampler
* YAFRSMOOTH = Yet Another Fast Resampler
*
* Yet Another Fast Resampler is a nonlinear resampler which consists
* of a linear scheme (in this version, Catmull-Rom) plus a nonlinear
@ -94,26 +94,26 @@ static VipsInterpolateClass *vips_interpolate_yafr_parent_class = NULL;
*
* Key properties:
*
* YAFR (smooth) is interpolatory:
* YAFRSMOOTH (smooth) is interpolatory:
*
* If asked for the value at the center of an input pixel, it will
* return the corresponding value, unchanged.
*
* YAFR (smooth) preserves local averages:
* YAFRSMOOTH (smooth) preserves local averages:
*
* The average of the reconstructed intensity surface over any region
* is the same as the average of the piecewise constant surface with
* values over pixel areas equal to the input pixel values (the
* "nearest neighbour" surface), except for a small amount of blur at
* the boundary of the region. More precicely: YAFR (smooth) is a box
* the boundary of the region. More precicely: YAFRSMOOTH (smooth) is a box
* filtered exact area method.
*
* Main weaknesses of YAFR (smooth):
* Main weaknesses of YAFRSMOOTH (smooth):
*
* Weakness 1: YAFR (smooth) improves on Catmull-Rom only for images
* Weakness 1: YAFRSMOOTH (smooth) improves on Catmull-Rom only for images
* with at least a little bit of smoothness.
*
* Weakness 2: Catmull-Rom introduces a lot of haloing. YAFR (smooth)
* Weakness 2: Catmull-Rom introduces a lot of haloing. YAFRSMOOTH (smooth)
* is based on Catmull-Rom, and consequently it too introduces a lot
* of haloing.
*
@ -121,11 +121,11 @@ static VipsInterpolateClass *vips_interpolate_yafr_parent_class = NULL;
*
* If a portion of the image is such that every pixel has immediate
* neighbours in the horizontal and vertical directions which have
* exactly the same pixel value, then YAFR (smooth) boils down to
* exactly the same pixel value, then YAFRSMOOTH (smooth) boils down to
* Catmull-Rom, and the computation of the correction is a waste.
* Extreme case: If all the pixels are either pure black or pure white
* in some region, as in some text images (more generally, if the
* region is "bichromatic"), then the YAFR (smooth) correction is 0 in
* region is "bichromatic"), then the YAFRSMOOTH (smooth) correction is 0 in
* the interior of the bichromatic region.
*/
@ -134,7 +134,7 @@ static VipsInterpolateClass *vips_interpolate_yafr_parent_class = NULL;
*/
static inline void
catrom_yafr (float* restrict out, const float* restrict in,
catrom_yafrsmooth (float* restrict out, const float* restrict in,
const int channels,
const int pixels_per_buffer_row,
const float sharpening,
@ -206,7 +206,7 @@ catrom_yafr (float* restrict out, const float* restrict in,
/*
* Load the useful pixel values for the channel under
* consideration. The in pointer is assumed
* to point to uno_one when catrom_yafr is entered.
* to point to uno_one when catrom_yafrsmooth is entered.
*/
const float uno_one = in[ 0 ];
const float uno_two = in[ channels ];
@ -229,7 +229,7 @@ catrom_yafr (float* restrict out, const float* restrict in,
const float qua_fou = in[ ( 3 + 3 * pixels_per_buffer_row ) * channels ];
/*
* Computation of the YAFR correction:
* Computation of the YAFRSMOOTH correction:
*
* Basically, if two consecutive pixel value differences have the
* same sign, the smallest one (in absolute value) is taken to be
@ -312,7 +312,7 @@ catrom_yafr (float* restrict out, const float* restrict in,
const float deux_rite_times_troi_rite = deux_rite * troi_rite;
/*
* Branching parts of the computation of the YAFR correction (could
* Branching parts of the computation of the YAFRSMOOTH correction (could
* be unbranched using arithmetic branching and C99 math intrinsics,
* although the compiler may be smart enough to remove the branching
* on its own):
@ -346,7 +346,7 @@ catrom_yafr (float* restrict out, const float* restrict in,
const float deux_rite_vs_troi_rite =
deux_rite_squared < troi_rite_squared ? deux_rite : troi_rite;
/*
* The YAFR correction computation will resume after the computation
* The YAFRSMOOTH correction computation will resume after the computation
* of the Catmull-Rom baseline.
*/
@ -399,7 +399,7 @@ catrom_yafr (float* restrict out, const float* restrict in,
);
/*
* Computation of the YAFR slopes.
* Computation of the YAFRSMOOTH slopes.
*/
/*
* "up":
@ -431,9 +431,9 @@ catrom_yafr (float* restrict out, const float* restrict in,
deux_rite_times_troi_rite < 0.f ? 0.f : deux_rite_vs_troi_rite;
/*
* Assemble the unweighted YAFR correction:
* Assemble the unweighted YAFRSMOOTH correction:
*/
const float unweighted_yafr_correction =
const float unweighted_yafrsmooth_correction =
left_width_times_up__height_times_rite_width
*
( mx_left__up - mx_rite__up )
@ -451,20 +451,21 @@ catrom_yafr (float* restrict out, const float* restrict in,
( my_rite__up - my_rite_dow );
/*
* Add the Catmull-Rom baseline and the weighted YAFR correction:
* Add the Catmull-Rom baseline and the weighted YAFRSMOOTH correction:
*/
const float newval =
sharpening_over_two * unweighted_yafr_correction + catmull_rom;
sharpening_over_two * unweighted_yafrsmooth_correction + catmull_rom;
*out = newval;
}
static void
vips_interpolate_yafr_interpolate( VipsInterpolate *interpolate,
vips_interpolate_yafrsmooth_interpolate( VipsInterpolate *interpolate,
REGION *out, REGION *in,
int out_x, int out_y, double x, double y )
{
VipsInterpolateYafr *yafr = VIPS_INTERPOLATE_YAFR( interpolate );
VipsInterpolateYafrsmooth *yafrsmooth =
VIPS_INTERPOLATE_YAFRSMOOTH( interpolate );
/*
* Note: The computation is structured to foster software
@ -583,9 +584,9 @@ vips_interpolate_yafr_interpolate( VipsInterpolate *interpolate,
int z;
for( z = 0; z < channels; z++ )
catrom_yafr ((float *) q + z, (float *) p + z,
catrom_yafrsmooth ((float *) q + z, (float *) p + z,
channels, pixels_per_buffer_row,
yafr->sharpening,
yafrsmooth->sharpening,
cardinal_one,
cardinal_two,
cardinal_thr,
@ -601,77 +602,79 @@ vips_interpolate_yafr_interpolate( VipsInterpolate *interpolate,
}
static void
vips_interpolate_yafr_class_init( VipsInterpolateYafrClass *class )
vips_interpolate_yafrsmooth_class_init( VipsInterpolateYafrsmoothClass *class )
{
VipsInterpolateClass *interpolate_class =
VIPS_INTERPOLATE_CLASS( class );
vips_interpolate_yafr_parent_class =
vips_interpolate_yafrsmooth_parent_class =
g_type_class_peek_parent( class );
interpolate_class->interpolate = vips_interpolate_yafr_interpolate;
interpolate_class->interpolate =
vips_interpolate_yafrsmooth_interpolate;
interpolate_class->window_size = 4;
}
static void
vips_interpolate_yafr_init( VipsInterpolateYafr *yafr )
vips_interpolate_yafrsmooth_init( VipsInterpolateYafrsmooth *yafrsmooth )
{
#ifdef DEBUG
printf( "vips_interpolate_yafr_init: " );
vips_object_print( VIPS_OBJECT( yafr ) );
printf( "vips_interpolate_yafrsmooth_init: " );
vips_object_print( VIPS_OBJECT( yafrsmooth ) );
#endif /*DEBUG*/
yafr->sharpening = 1.0;
yafrsmooth->sharpening = 1.0;
}
GType
vips_interpolate_yafr_get_type( void )
vips_interpolate_yafrsmooth_get_type( void )
{
static GType type = 0;
if( !type ) {
static const GTypeInfo info = {
sizeof( VipsInterpolateYafrClass ),
sizeof( VipsInterpolateYafrsmoothClass ),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) vips_interpolate_yafr_class_init,
(GClassInitFunc) vips_interpolate_yafrsmooth_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof( VipsInterpolateYafr ),
sizeof( VipsInterpolateYafrsmooth ),
32, /* n_preallocs */
(GInstanceInitFunc) vips_interpolate_yafr_init,
(GInstanceInitFunc) vips_interpolate_yafrsmooth_init,
};
type = g_type_register_static( VIPS_TYPE_INTERPOLATE,
"VipsInterpolateYafr", &info, 0 );
"VipsInterpolateYafrsmooth", &info, 0 );
}
return( type );
}
VipsInterpolate *
vips_interpolate_yafr_new( void )
vips_interpolate_yafrsmooth_new( void )
{
return( VIPS_INTERPOLATE( g_object_new(
VIPS_TYPE_INTERPOLATE_YAFR, NULL ) ) );
VIPS_TYPE_INTERPOLATE_YAFRSMOOTH, NULL ) ) );
}
void
vips_interpolate_yafr_set_sharpening( VipsInterpolateYafr *yafr,
vips_interpolate_yafrsmooth_set_sharpening(
VipsInterpolateYafrsmooth *yafrsmooth,
double sharpening )
{
yafr->sharpening = sharpening;
yafrsmooth->sharpening = sharpening;
}
/* Convenience: return a static yafr you don't need to free.
/* Convenience: return a static yafrsmooth you don't need to free.
*/
VipsInterpolate *
vips_interpolate_yafr_static( void )
vips_interpolate_yafrsmooth_static( void )
{
static VipsInterpolate *interpolate = NULL;
if( !interpolate )
interpolate = vips_interpolate_yafr_new();
interpolate = vips_interpolate_yafrsmooth_new();
return( interpolate );
}