im_scaleps() is a class
actually an option to vips_scale(), with a param for the exponent as well
This commit is contained in:
parent
4311d452f1
commit
caed1199ed
@ -3,7 +3,8 @@
|
||||
- turn off caching for im_copy()/vips_copy(), we use copy to stop sharing, and
|
||||
it's cheap so caching doesn't help anyway
|
||||
- auto rshift down to 8 bits on save, if necessary
|
||||
- im_gaussnoise(), im_copy_file(), im_grid(), im_scale() redone as classes
|
||||
- im_gaussnoise(), im_copy_file(), im_grid(), im_scale(), im_scaleps()
|
||||
redone as classes
|
||||
- add --angle option to dzsave
|
||||
|
||||
14/5/13 started 7.32.4
|
||||
|
@ -30,7 +30,6 @@ libconversion_la_SOURCES = \
|
||||
im_msb.c \
|
||||
grid.c \
|
||||
scale.c \
|
||||
im_scaleps.c \
|
||||
im_subsample.c \
|
||||
im_system.c \
|
||||
im_system_image.c \
|
||||
|
@ -1,100 +0,0 @@
|
||||
/* im_scaleps
|
||||
*
|
||||
* Copyright: 1990, N. Dessipris.
|
||||
*
|
||||
* Author: Nicos Dessipris
|
||||
* Written on: 02/05/1990
|
||||
* Modified on: 14/03/1991
|
||||
* 15/6/93 J.Cupitt
|
||||
* - externs fixed
|
||||
* - includes fixed
|
||||
* 13/2/95 JC
|
||||
* - ANSIfied
|
||||
* - cleaned up
|
||||
* 11/7/02 JC
|
||||
* - rewritten ... got rid of the stuff for handling -ves, never used
|
||||
* (and was broken anyway)
|
||||
* 1/2/10
|
||||
* - gtkdoc
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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
|
||||
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif /*HAVE_CONFIG_H*/
|
||||
#include <vips/intl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
/**
|
||||
* im_scaleps:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Scale a power spectrum. Transform with log10(1.0 + pow(x, 0.25)) + .5,
|
||||
* then scale so max == 255.
|
||||
*
|
||||
* See also: im_scale().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
im_scaleps( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
IMAGE *t[4];
|
||||
double mx;
|
||||
double scale;
|
||||
|
||||
if( im_open_local_array( out, t, 4, "im_scaleps-1", "p" ) ||
|
||||
im_max( in, &mx ) )
|
||||
return( -1 );
|
||||
|
||||
if( mx <= 0.0 )
|
||||
/* Range of zero: just return black.
|
||||
*/
|
||||
return( im_black( out, in->Xsize, in->Ysize, in->Bands ) );
|
||||
|
||||
scale = 255.0 / log10( 1.0 + pow( mx, .25 ) );
|
||||
|
||||
/* Transform!
|
||||
*/
|
||||
if( im_powtra( in, t[0], 0.25 ) ||
|
||||
im_lintra( 1.0, t[0], 1.0, t[1] ) ||
|
||||
im_log10tra( t[1], t[2] ) ||
|
||||
im_lintra( scale, t[2], 0.0, t[3] ) ||
|
||||
im_clip2fmt( t[3], out, IM_BANDFMT_UCHAR ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
* - gtkdoc
|
||||
* 30/5/13
|
||||
* - redo as a class
|
||||
* - add log scale and exponent as an option
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -63,6 +64,9 @@ typedef struct _VipsScale {
|
||||
|
||||
VipsImage *in;
|
||||
|
||||
gboolean log;
|
||||
double exp;
|
||||
|
||||
} VipsScale;
|
||||
|
||||
typedef VipsConversionClass VipsScaleClass;
|
||||
@ -98,6 +102,17 @@ vips_scale_build( VipsObject *object )
|
||||
vips_image_write( t[1], conversion->out ) )
|
||||
return( -1 );
|
||||
}
|
||||
else if( scale->log ) {
|
||||
double f = 255.0 / log10( 1.0 + pow( mx, scale->exp ) );
|
||||
|
||||
if( vips_pow_const1( scale->in, &t[2], scale->exp, NULL ) ||
|
||||
vips_linear1( t[2], &t[3], 1.0, 1.0, NULL ) ||
|
||||
vips_log10( t[3], &t[4], NULL ) ||
|
||||
vips_linear1( t[4], &t[5], f, 0.0, NULL ) ||
|
||||
vips_cast( t[5], &t[6], VIPS_FORMAT_UCHAR, NULL ) ||
|
||||
vips_image_write( t[6], conversion->out ) )
|
||||
return( -1 );
|
||||
}
|
||||
else {
|
||||
double f = 255.0 / (mx - mn);
|
||||
double a = -(mn * f);
|
||||
@ -130,11 +145,26 @@ vips_scale_class_init( VipsScaleClass *class )
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsScale, in ) );
|
||||
|
||||
VIPS_ARG_BOOL( class, "log", 3,
|
||||
_( "Log" ),
|
||||
_( "Log scale" ),
|
||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||
G_STRUCT_OFFSET( VipsScale, log ),
|
||||
FALSE );
|
||||
|
||||
VIPS_ARG_DOUBLE( class, "exp", 3,
|
||||
_( "Exponent" ),
|
||||
_( "Exponent for log scale" ),
|
||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||
G_STRUCT_OFFSET( VipsScale, exp ),
|
||||
0.00001, 10000, 0.25 );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_scale_init( VipsScale *scale )
|
||||
{
|
||||
scale->exp = 0.25;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,10 +173,18 @@ vips_scale_init( VipsScale *scale )
|
||||
* @out: output image
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Optional arguments:
|
||||
*
|
||||
* @log: log scale pixels
|
||||
* @exp: exponent for log scale
|
||||
*
|
||||
* Search the image for the maximum and minimum value, then return the image
|
||||
* as unsigned 8-bit, scaled so that the maximum value is 255 and the
|
||||
* minimum is zero.
|
||||
*
|
||||
* If @log is set, transform with log10(1.0 + pow(x, @exp)) + .5,
|
||||
* then scale so max == 255. By default, @exp is 0.25.
|
||||
*
|
||||
* See also: vips_cast().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
|
@ -1527,6 +1527,22 @@ im_scale( VipsImage *in, VipsImage *out )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_scaleps( VipsImage *in, VipsImage *out )
|
||||
{
|
||||
VipsImage *t;
|
||||
|
||||
if( vips_scale( in, &t, "log", TRUE, NULL ) )
|
||||
return( -1 );
|
||||
if( vips_image_write( t, out ) ) {
|
||||
g_object_unref( t );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( t );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int
|
||||
vips__math( VipsImage *in, VipsImage *out, VipsOperationMath math )
|
||||
{
|
||||
|
@ -258,8 +258,6 @@ int vips_flatten( VipsImage *in, VipsImage **out, ... )
|
||||
int im_msb( VipsImage *in, VipsImage *out );
|
||||
int im_msb_band( VipsImage *in, VipsImage *out, int band );
|
||||
|
||||
int im_scaleps( VipsImage *in, VipsImage *out );
|
||||
|
||||
int im_falsecolour( VipsImage *in, VipsImage *out );
|
||||
|
||||
int im_text( VipsImage *out, const char *text, const char *font,
|
||||
|
@ -712,6 +712,7 @@ int im_black( VipsImage *out, int x, int y, int bands );
|
||||
int im_gaussnoise( VipsImage *out, int x, int y, double mean, double sigma );
|
||||
int im_grid( VipsImage *in, VipsImage *out, int tile_height, int across, int down );
|
||||
int im_scale( VipsImage *in, VipsImage *out );
|
||||
int im_scaleps( VipsImage *in, VipsImage *out );
|
||||
|
||||
int im_c2amph( VipsImage *in, VipsImage *out );
|
||||
int im_c2rect( VipsImage *in, VipsImage *out );
|
||||
|
@ -75,7 +75,6 @@ libvips/conversion/replicate.c
|
||||
libvips/conversion/join.c
|
||||
libvips/conversion/im_text.c
|
||||
libvips/conversion/conver_dispatch.c
|
||||
libvips/conversion/im_scaleps.c
|
||||
libvips/conversion/im_wrap.c
|
||||
libvips/conversion/insert.c
|
||||
libvips/conversion/tilecache.c
|
||||
|
Loading…
Reference in New Issue
Block a user