remove rump of im_histspec()

This commit is contained in:
John Cupitt 2013-09-04 12:07:32 +01:00
parent f35e27135a
commit 56df56c737
7 changed files with 67 additions and 224 deletions

View File

@ -3471,6 +3471,55 @@ im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
return( 0 );
}
static int
match( VipsImage *in, VipsImage *ref, VipsImage *out )
{
VipsImage *x;
if( vips_hist_match( in, ref, &x, NULL ) )
return( -1 );
if( im_copy( x, out ) ) {
g_object_unref( x );
return( -1 );
}
g_object_unref( x );
return( 0 );
}
int
im_histspec( IMAGE *in, IMAGE *ref, IMAGE *out )
{
IMAGE *t[5];
VipsImage *x;
guint64 px;
int fmt;
if( im_check_uint( "im_histspec", in ) ||
im_check_uint( "im_histspec", ref ) )
return( -1 );
if( im_open_local_array( out, t, 5, "im_histspec", "p" ) ||
im_histeq( in, t[0] ) ||
im_histeq( ref, t[2] ) ||
match( t[0], t[2], t[4] ) )
return( -1 );
px = VIPS_IMAGE_N_PELS( t[4] );
if( px <= 256 )
fmt = IM_BANDFMT_UCHAR;
else if( px <= 65536 )
fmt = IM_BANDFMT_USHORT;
else
fmt = IM_BANDFMT_UINT;
if( im_clip2fmt( t[4], out, fmt ) )
return( -1 );
return( 0 );
}
int
im_falsecolour( IMAGE *in, IMAGE *out )
{

View File

@ -13,7 +13,6 @@ libhistogram_la_SOURCES = \
hist_match.c \
\
hist_dispatch.c \
im_histspec.c \
im_mpercent.c \
im_invertlut.c \
im_lhisteq.c \

View File

@ -164,13 +164,13 @@ vips_hist_match_class_init( VipsHistMatchClass *class )
VIPS_ARG_IMAGE( class, "in", 1,
_( "Input" ),
_( "Input image" ),
_( "Input histogram" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsHistMatch, in ) );
VIPS_ARG_IMAGE( class, "ref", 2,
_( "Reference" ),
_( "Reference image" ),
_( "Reference histogram" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsHistMatch, ref ) );
@ -186,12 +186,14 @@ vips_hist_match_init( VipsHistMatch *match )
* @in: input histogram
* @ref: reference histogram
* @out: output histogram
* @...: %NULL-terminated list of optional named arguments
*
* Creates a lut which, when applied to the image from which histogram @in was
* formed, will produce an image whose PDF matches that of the image from
* which @ref was formed.
* Adjust @in to match @ref. If @in and @ref are normalised
* cumulative histograms, @out will be a LUT that adjusts the PDF of the image
* from which @in was made to match the PDF of @ref's image.
*
* See also: im_hsp(), im_histgr(), im_maplut().
* See also: vips_maplut(), vips_hist_find(), vips_hist_norm(),
* vips_hist_cum().
*
* Returns: 0 on success, -1 on error
*/

View File

@ -76,7 +76,7 @@
G_DEFINE_ABSTRACT_TYPE( VipsHistogram, vips_histogram, VIPS_TYPE_OPERATION );
/* sizealike by expanding in just one dimension.
/* sizealike by expanding in just one dimension and copying the final element.
*/
static int
vips__hist_sizealike_vec( VipsImage **in, VipsImage **out, int n )
@ -93,13 +93,15 @@ vips__hist_sizealike_vec( VipsImage **in, VipsImage **out, int n )
for( i = 0; i < n; i++ )
if( in[i]->Ysize == 1 ) {
if( vips_embed( in[i], &out[i],
0, 0, max_size, 1, NULL ) )
if( vips_embed( in[i], &out[i], 0, 0, max_size, 1,
"extend", VIPS_EXTEND_COPY,
NULL ) )
return( -1 );
}
else {
if( vips_embed( in[i], &out[i],
0, 0, 1, max_size, NULL ) )
if( vips_embed( in[i], &out[i], 0, 0, 1, max_size,
"extend", VIPS_EXTEND_COPY,
NULL ) )
return( -1 );
}
@ -235,10 +237,12 @@ vips_histogram_operation_init( void )
extern GType vips_hist_norm_get_type( void );
extern GType vips_hist_equal_get_type( void );
extern GType vips_hist_plot_get_type( void );
extern GType vips_hist_match_get_type( void );
vips_maplut_get_type();
vips_hist_cum_get_type();
vips_hist_norm_get_type();
vips_hist_equal_get_type();
vips_hist_plot_get_type();
vips_hist_match_get_type();
}

View File

@ -1,211 +0,0 @@
/* match PDFs
*
* Copyright: 1991, N. Dessipris.
*
* Author: Nicos Dessipris
* Written on: 19/07/1990
* Modified on: 26/03/1991
*
* 1/3/01 JC
* - bleurg! rewritten, now does 16 bits as well, bugs removed, faster,
* smaller
* 24/3/10
* - gtkdoc
* - small cleanups
*/
/*
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 <assert.h>
#include <vips/vips.h>
/*
#define DEBUG
*/
/*
#define PIM_RINT
*/
/* Match two normalised cumulative histograms.
*/
static int
match( IMAGE *in, IMAGE *ref, IMAGE *out )
{
const guint64 inpx = VIPS_IMAGE_N_PELS( in );
const guint64 refpx = VIPS_IMAGE_N_PELS( ref );
const int bands = in->Bands;
unsigned int *inbuf; /* in and ref, padded to same size */
unsigned int *refbuf;
unsigned int *outbuf; /* Always output as uint */
guint64 px; /* Number of pixels */
guint64 max; /* px * bands */
guint64 i, j;
if( im_iocheck( in, out ) ||
im_iocheck( ref, out ) ||
im_check_uncoded( "im_histspec", in ) ||
im_check_format( "im_histspec", in, IM_BANDFMT_UINT ) ||
im_check_coding_same( "im_histspec", in, ref ) ||
im_check_format_same( "im_histspec", in, ref ) ||
im_check_bands_same( "im_histspec", in, ref ) ||
im_check_hist( "im_histspec", in ) ||
im_check_hist( "im_histspec", ref ) )
return( -1 );
/* How big?
*/
if( inpx <= 256 && refpx <= 256 )
px = 256;
else if( inpx <= 65536 && refpx <= 65536 )
px = 65536;
else
px = IM_MAX( inpx, refpx );
max = px * bands;
/* Unpack to equal-sized buffers.
*/
inbuf = IM_ARRAY( out, max, unsigned int );
refbuf = IM_ARRAY( out, max, unsigned int );
outbuf = IM_ARRAY( out, max, unsigned int );
if( !inbuf || !refbuf || !outbuf )
return( -1 );
for( i = 0; i < inpx * bands; i++ )
inbuf[i] = ((unsigned int *)in->data)[i];
for( ; i < max; i++ )
inbuf[i] = 0;
for( i = 0; i < refpx * bands; i++ )
refbuf[i] = ((unsigned int *)ref->data)[i];
for( ; i < max; i++ )
refbuf[i] = 0;
for( j = 0; j < bands; j++ ) {
/* Track up refbuf[] with this.
*/
int ri = j;
int limit = max - bands;
for( i = j; i < max; i += bands ) {
unsigned int inv = inbuf[i];
for( ; ri < limit; ri += bands )
if( inv <= refbuf[ri] )
break;
if( ri < limit ) {
/* Simple rounding.
*/
double mid = refbuf[ri] +
refbuf[ri + bands] / 2.0;
if( inv < mid )
outbuf[i] = ri/bands;
else
outbuf[i] = ri/bands + 1;
}
else
outbuf[i] = refbuf[ri];
}
}
if( im_cp_descv( out, in, ref, NULL ) )
return( -1 );
out->Xsize = px;
out->Ysize = 1;
out->Type = IM_TYPE_HISTOGRAM;
if( im_setupout( out ) )
return( -1 );
if( im_writeline( 0, out, (VipsPel *) outbuf ) )
return( -1 );
return( 0 );
}
/**
* im_histspec:
* @in: input histogram
* @ref: reference histogram
* @out: output histogram
*
* Creates a lut which, when applied to the image from which histogram @in was
* formed, will produce an image whose PDF matches that of the image from
* which @ref was formed.
*
* See also: im_hsp(), im_histgr(), im_maplut().
*
* Returns: 0 on success, -1 on error
*/
int
im_histspec( IMAGE *in, IMAGE *ref, IMAGE *out )
{
IMAGE *t[5];
guint64 px;
int fmt;
if( im_check_uint( "im_histspec", in ) ||
im_check_uint( "im_histspec", ref ) )
return( -1 );
/* Match hists.
*/
if( im_open_local_array( out, t, 5, "im_histspec", "p" ) ||
im_histeq( in, t[0] ) ||
im_clip2fmt( t[0], t[1], IM_BANDFMT_UINT ) ||
im_histeq( ref, t[2] ) ||
im_clip2fmt( t[2], t[3], IM_BANDFMT_UINT ) ||
match( t[1], t[3], t[4] ) )
return( -1 );
/* Clip type down.
*/
px = VIPS_IMAGE_N_PELS( t[4] );
if( px <= 256 )
fmt = IM_BANDFMT_UCHAR;
else if( px <= 65536 )
fmt = IM_BANDFMT_USHORT;
else
fmt = IM_BANDFMT_UINT;
if( im_clip2fmt( t[4], out, fmt ) )
return( -1 );
return( 0 );
}

View File

@ -55,7 +55,6 @@ int vips_hist_match( VipsImage *in, VipsImage *ref, VipsImage **out, ... )
int im_invertlut( DOUBLEMASK *input, VipsImage *output, int lut_size );
int im_project( VipsImage *in, VipsImage *hout, VipsImage *vout );
int im_histspec( VipsImage *in, VipsImage *ref, VipsImage *out );
int im_ismonotonic( VipsImage *lut, int *out );
int im_mpercent( VipsImage *in, double percent, int *out );

View File

@ -861,6 +861,7 @@ int im_histnD( VipsImage *in, VipsImage *out, int bins );
int im_hist_indexed( VipsImage *index, VipsImage *value, VipsImage *out );
int im_histplot( VipsImage *in, VipsImage *out );
int im_hsp( VipsImage *in, VipsImage *ref, VipsImage *out );
int im_histspec( VipsImage *in, VipsImage *ref, VipsImage *out );
/* ruby-vips uses this
*/