move im_freqflt() to a class
and move im_freq_mask() to deprecated
This commit is contained in:
parent
9f150e3063
commit
f8b9645bd8
@ -32,7 +32,7 @@
|
||||
- vipsthumbnail has a --crop option
|
||||
- remove video4linux1 code, it was useless on all modern linuxes
|
||||
- redone freq filter builders as classes
|
||||
- redone im_fwfft(), im_invfft() as classes
|
||||
- redone im_fwfft(), im_invfft(), im_freqflt() as classes
|
||||
|
||||
20/11/13 started 7.36.5
|
||||
- better cache sizing in unbuffered sequential mode
|
||||
|
2
TODO
2
TODO
@ -5,7 +5,7 @@
|
||||
VIPS:ERROR:buffer.c:390:vips_buffer_new: assertion failed: (!buffer->cache)
|
||||
Aborted (core dumped)
|
||||
|
||||
- im_freq_mask.c can almost be deprecated .. just im_freqfilt() to do now I
|
||||
- im_freq_mask.c can almost be deprecated .. just im_freqflt() to do now I
|
||||
think
|
||||
|
||||
|
||||
|
@ -72,6 +72,7 @@ libdeprecated_la_SOURCES = \
|
||||
im_vips2tiff.c \
|
||||
conver_dispatch.c \
|
||||
im_vips2dz.c \
|
||||
im_freq_mask.c \
|
||||
matlab.c \
|
||||
radiance.c \
|
||||
raw.c
|
||||
|
@ -202,20 +202,6 @@ build_freq_mask( IMAGE *out, int xs, int ys, ImMaskType flag, va_list ap )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* im_flt_image_freq:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
* @flag: mask type
|
||||
* @Varargs: mask parameters
|
||||
*
|
||||
* Creates a mask (see im_create_fmask()) and filters an image with it (see
|
||||
* im_freqflt()).
|
||||
*
|
||||
* See also: im_create_fmask(), im_freqflt(),
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
im_flt_image_freq( IMAGE *in, IMAGE *out, ImMaskType flag, ... )
|
||||
{
|
@ -4423,3 +4423,19 @@ im_invfftr( IMAGE *in, IMAGE *out )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_freqflt( IMAGE *in, IMAGE *mask, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_freqmult( in, mask, &x, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -5,11 +5,10 @@ libfreqfilt_la_SOURCES = \
|
||||
pfreqfilt.h \
|
||||
fwfft.c \
|
||||
invfft.c \
|
||||
freqmult.c \
|
||||
im_phasecor_fft.c \
|
||||
freq_dispatch.c \
|
||||
im_disp_ps.c \
|
||||
im_fractsurf.c \
|
||||
im_freq_mask.c \
|
||||
im_freqflt.c
|
||||
im_fractsurf.c
|
||||
|
||||
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||
|
@ -159,10 +159,12 @@ vips_freqfilt_operation_init( void )
|
||||
extern GType vips_fwfft_get_type( void );
|
||||
extern GType vips_invfft_get_type( void );
|
||||
#endif /*HAVE_FFTW*/
|
||||
extern GType vips_freqmult_get_type( void );
|
||||
|
||||
#ifdef HAVE_FFTW
|
||||
vips_fwfft_get_type();
|
||||
vips_invfft_get_type();
|
||||
#endif /*HAVE_FFTW*/
|
||||
vips_freqmult_get_type();
|
||||
}
|
||||
|
||||
|
179
libvips/freqfilt/freqmult.c
Normal file
179
libvips/freqfilt/freqmult.c
Normal file
@ -0,0 +1,179 @@
|
||||
/* frequency-domain filter an image
|
||||
*
|
||||
* Author: Nicos Dessipris
|
||||
* Written on: 02/05/1990
|
||||
* Modified on : 08/03/1991
|
||||
* 16/6/93 J.Cupitt
|
||||
* - im_multiply() called, rather than im_cmultim()
|
||||
* 27/10/93 JC
|
||||
* - im_clip2*() called, rather than im_any2*()
|
||||
* 20/9/95 JC
|
||||
* - rewritten
|
||||
* 10/9/98 JC
|
||||
* - frees memory more quickly
|
||||
* 4/3/03 JC
|
||||
* - use im_invfftr() to get real back for speedup
|
||||
* 3/1/14
|
||||
* - redone as a class
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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 <vips/vips.h>
|
||||
#include "pfreqfilt.h"
|
||||
|
||||
typedef struct _VipsFreqmult {
|
||||
VipsFreqfilt parent_instance;
|
||||
|
||||
VipsImage *in;
|
||||
VipsImage *mask;
|
||||
} VipsFreqmult;
|
||||
|
||||
typedef VipsFreqfiltClass VipsFreqmultClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsFreqmult, vips_freqmult, VIPS_TYPE_FREQFILT );
|
||||
|
||||
static int
|
||||
vips_freqmult_build( VipsObject *object )
|
||||
{
|
||||
VipsFreqfilt *freqfilt = VIPS_FREQFILT( object );
|
||||
VipsFreqmult *freqmult = (VipsFreqmult *) object;
|
||||
VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 );
|
||||
|
||||
VipsImage *in;
|
||||
|
||||
if( VIPS_OBJECT_CLASS( vips_freqmult_parent_class )->
|
||||
build( object ) )
|
||||
return( -1 );
|
||||
|
||||
in = freqmult->in;
|
||||
|
||||
if( vips_bandfmt_iscomplex( in->BandFmt ) ) {
|
||||
if( vips_multiply( in, freqmult->mask, &t[0], NULL ) ||
|
||||
vips_invfft( t[0], &t[1], "real", TRUE, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
in = t[1];
|
||||
}
|
||||
else {
|
||||
/* Optimisation: output of vips_invfft() is double, we
|
||||
* will usually cast to char, so rather than keeping a
|
||||
* large double buffer and partial to char from that,
|
||||
* cast to a memory buffer and copy to out from that.
|
||||
*
|
||||
* FIXME does this actually work now we're a class? test
|
||||
* perhaps we need a temporary object
|
||||
*/
|
||||
t[4] = vips_image_new_buffer();
|
||||
|
||||
if( vips_fwfft( in, &t[0], NULL ) ||
|
||||
vips_multiply( t[0], freqmult->mask, &t[1], NULL ) ||
|
||||
vips_invfft( t[1], &t[2], "real", TRUE, NULL ) ||
|
||||
vips_cast( t[2], &t[3], in->BandFmt, NULL ) ||
|
||||
vips_image_write( t[3], t[4] ) )
|
||||
return( -1 );
|
||||
|
||||
in = t[4];
|
||||
}
|
||||
|
||||
if( vips_image_write( in, freqfilt->out ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_freqmult_class_init( VipsFreqmultClass *class )
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS( class );
|
||||
VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS( class );
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
||||
vobject_class->nickname = "freqmult";
|
||||
vobject_class->description = _( "frequency-domain filtering" );
|
||||
vobject_class->build = vips_freqmult_build;
|
||||
|
||||
VIPS_ARG_IMAGE( class, "in", -1,
|
||||
_( "in" ),
|
||||
_( "Input image" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsFreqmult, in ) );
|
||||
|
||||
VIPS_ARG_IMAGE( class, "mask", 0,
|
||||
_( "mask" ),
|
||||
_( "Input mask image" ),
|
||||
VIPS_ARGUMENT_REQUIRED_INPUT,
|
||||
G_STRUCT_OFFSET( VipsFreqmult, mask ) );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
vips_freqmult_init( VipsFreqmult *freqmult )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_freqmult:
|
||||
* @in: input image
|
||||
* @mask: mask image
|
||||
* @out: output image
|
||||
* @...: %NULL-terminated list of optional named arguments
|
||||
*
|
||||
* Multiply @in by @mask in Fourier space.
|
||||
*
|
||||
* @in is transformed to Fourier space, multipled with @mask, then
|
||||
* transformed back to real space. If @in is already a complex image, just
|
||||
* multiply then inverse transform.
|
||||
*
|
||||
* See also: vips_invfft(), vips_mask_ideal().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
vips_freqmult( VipsImage *in, VipsImage *mask, VipsImage **out, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, out );
|
||||
result = vips_call_split( "freqmult", ap, in, mask, out );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
@ -1,137 +0,0 @@
|
||||
/* @(#) Functions which takes as input a valid image and filters it
|
||||
* @(#) in the fourier domain with the filter mask
|
||||
* @(#) Input can have any format ; output is the same as input
|
||||
* @(#) imin can be char uchar, short, ushort, int, uint, float, double
|
||||
* @(#) or complex float; result is the same as input, clipped if necessary.
|
||||
* @(#) mask can have any format but the sizes of input and mask are equal
|
||||
* @(#) The function performs float fft and if the input is not complex float
|
||||
* @(#) the output is casted to the type of input according to im_clip2..()
|
||||
* @(#) Since buffer images are involved the size, is restricted to 512x512
|
||||
* @(#) for the SUN4 SPARC workstation
|
||||
* @(#)
|
||||
* @(#) int im_freqflt(imin, mask, imout)
|
||||
* @(#) IMAGE *imin, *mask, *imout;
|
||||
* @(#)
|
||||
* @(#) Returns 0 on success and -1 on error
|
||||
*
|
||||
* Copyright: 1990, N. Dessipris.
|
||||
*
|
||||
* Author: Nicos Dessipris
|
||||
* Written on: 02/05/1990
|
||||
* Modified on : 08/03/1991
|
||||
* 16/6/93 J.Cupitt
|
||||
* - im_multiply() called, rather than im_cmultim()
|
||||
* 27/10/93 JC
|
||||
* - im_clip2*() called, rather than im_any2*()
|
||||
* 20/9/95 JC
|
||||
* - rewritten
|
||||
* 10/9/98 JC
|
||||
* - frees memory more quickly
|
||||
* 4/3/03 JC
|
||||
* - use im_invfftr() to get real back for speedup
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
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 <math.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
/**
|
||||
* im_freqflt:
|
||||
* @in: input image
|
||||
* @mask: mask image
|
||||
* @out: output image
|
||||
*
|
||||
* Filter an image in Fourier space.
|
||||
*
|
||||
* @in is transformed to Fourier space, multipled with the mask image, then
|
||||
* transformed back to real space. If @in is already a complex image, just
|
||||
* multiply then inverse transform.
|
||||
*
|
||||
* See also: im_invfftr(), im_create_fmask().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_freqflt( IMAGE *in, IMAGE *mask, IMAGE *out )
|
||||
{
|
||||
IMAGE *dummy;
|
||||
|
||||
/* Placeholder for memory free.
|
||||
*/
|
||||
if( !(dummy = im_open( "memory-1", "p" )) )
|
||||
return( -1 );
|
||||
|
||||
if( vips_bandfmt_iscomplex( in->BandFmt ) ) {
|
||||
/* Easy case! Assume it has already been transformed.
|
||||
*/
|
||||
IMAGE *t1 = im_open_local( dummy, "im_freqflt-1", "p" );
|
||||
|
||||
if( !t1 ||
|
||||
im_multiply( in, mask, t1 ) ||
|
||||
im_invfftr( t1, out ) ) {
|
||||
im_close( dummy );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Harder - fft first, then mult, then force back to start
|
||||
* type.
|
||||
*
|
||||
* Optimisation: output of im_invfft() is float buffer, we
|
||||
* will usually chagetype to char, so rather than keeping a
|
||||
* large float buffer and partial to char from that, do
|
||||
* changetype to a memory buffer, and copy to out from that.
|
||||
*/
|
||||
IMAGE *t[3];
|
||||
IMAGE *t3;
|
||||
|
||||
if( im_open_local_array( dummy, t, 3, "im_freqflt-1", "p" ) ||
|
||||
!(t3 = im_open_local( out, "im_freqflt-3", "t" )) ||
|
||||
im_fwfft( in, t[0] ) ||
|
||||
im_multiply( t[0], mask, t[1] ) ||
|
||||
im_invfftr( t[1], t[2] ) ||
|
||||
im_clip2fmt( t[2], t3, in->BandFmt ) ||
|
||||
im_copy( t3, out ) ) {
|
||||
im_close( dummy );
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
im_close( dummy );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -42,8 +42,9 @@ int vips_fwfft( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_invfft( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_freqmult( VipsImage *in, VipsImage *mask, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int im_freqflt( VipsImage *in, VipsImage *mask, VipsImage *out );
|
||||
int im_disp_ps( VipsImage *in, VipsImage *out );
|
||||
int im_phasecor_fft( VipsImage *in1, VipsImage *in2, VipsImage *out );
|
||||
|
||||
|
@ -970,6 +970,8 @@ int im_fwfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfft( VipsImage *in, VipsImage *out );
|
||||
int im_invfftr( VipsImage *in, VipsImage *out );
|
||||
|
||||
int im_freqflt( VipsImage *in, VipsImage *mask, VipsImage *out );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
Loading…
Reference in New Issue
Block a user