deprecate im_hsp()

This commit is contained in:
John Cupitt 2013-08-19 16:40:30 +01:00
parent 81ee98fca7
commit 1c54970deb
7 changed files with 228 additions and 80 deletions

View File

@ -10,6 +10,7 @@
- used freeze() / thaw() to stop file format sniffers logging spurious errors
- vipsthumbnail uses embedded jpg thumbnails if it can
- rename vips_diag() as vips_info(), add --vips-info flag
- deprecate im_hsp()
3/7/13 started 7.34.2
- lower priority for Matlab load to reduce segvs from Mat_Open(), thanks

View File

@ -3456,6 +3456,21 @@ im_hist_indexed( VipsImage *index, VipsImage *value, VipsImage *out )
return( 0 );
}
int
im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
{
IMAGE *t[3];
if( im_open_local_array( out, t, 3, "im_hsp", "p" ) ||
im_histgr( in, t[0], -1 ) ||
im_histgr( ref, t[1], -1 ) ||
im_histspec( t[0], t[1], t[2] ) ||
im_maplut( in, out, t[2] ) )
return( -1 );
return( 0 );
}
int
im_falsecolour( IMAGE *in, IMAGE *out )
{

View File

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

View File

@ -0,0 +1,211 @@
/* 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

@ -1,78 +0,0 @@
/* match histograms
*
* Copyright: 1990, N. Dessipris.
*
* Author: Nicos Dessipris
* Written on: 08/05/1990
* Modified on :
* 16/6/93 J.Cupitt
* - im_ioflag() call changed to im_iocheck()
* 25/5/95 JC
* - revised
* 24/3/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 <vips/vips.h>
/**
* im_hsp:
* @in: input image
* @ref: reference histogram
* @out: output image
*
* Maps image @in to image @out, adjusting the histogram to match image @ref.
* Both images should have the same number of bands.
*
* See also: im_histspec(), im_histgr().
*
* Returns: 0 on success, -1 on error
*/
int
im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
{
IMAGE *t[3];
if( im_open_local_array( out, t, 3, "im_hsp", "p" ) ||
im_histgr( in, t[0], -1 ) ||
im_histgr( ref, t[1], -1 ) ||
im_histspec( t[0], t[1], t[2] ) ||
im_maplut( in, out, t[2] ) )
return( -1 );
return( 0 );
}

View File

@ -56,7 +56,6 @@ 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_hsp( VipsImage *in, VipsImage *ref, VipsImage *out );
int im_mpercent( VipsImage *in, double percent, int *out );
int im_mpercent_hist( VipsImage *hist, double percent, int *out );

View File

@ -859,6 +859,7 @@ int im_heq( VipsImage *in, VipsImage *out, int bandno );
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 );
/* ruby-vips uses this
*/