From 4306b402eeb579ea6b2f32621590a5e5312ad1be Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 24 Mar 2010 16:20:09 +0000 Subject: [PATCH] hist hacking --- ChangeLog | 3 ++- libvips/histograms_lut/im_histeq.c | 4 +-- libvips/histograms_lut/im_histspec.c | 2 +- libvips/histograms_lut/im_hsp.c | 40 +++++++++++++++------------- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e429f3f..21a8dacf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,7 +2,8 @@ - added progress feedback to threadpool - --vips-wbuffer2 switch does all wbuffer use now - im_wbuffer2() renamed as vips_discsink(), some cleanups -- im_gammacorrect() can do 16-bit iamges too +- im_gammacorrect() can do 16-bit images too +- im_histplot() could fail for signed int histograms 16/1/10 started 7.21.2 - "invalidate" is careful to keep images alive, so invalidate callbacks can do diff --git a/libvips/histograms_lut/im_histeq.c b/libvips/histograms_lut/im_histeq.c index 2b03a424..deff9828 100644 --- a/libvips/histograms_lut/im_histeq.c +++ b/libvips/histograms_lut/im_histeq.c @@ -219,11 +219,11 @@ im_histnorm( IMAGE *in, IMAGE *out ) int im_histeq( IMAGE *in, IMAGE *out ) { - IMAGE *t1 = im_open_local( out, "im_histeq:1", "p" ); + IMAGE *t1; /* Normalised cumulative. */ - if( !(t1 = im_open_local( out, "im_histeq:1", "p" )) || + if( !(t1 = im_open_local( out, "im_histeq", "p" )) || im_histcum( in, t1 ) || im_histnorm( t1, out ) ) return( -1 ); diff --git a/libvips/histograms_lut/im_histspec.c b/libvips/histograms_lut/im_histspec.c index d8b98835..5ba9cfb9 100644 --- a/libvips/histograms_lut/im_histspec.c +++ b/libvips/histograms_lut/im_histspec.c @@ -169,7 +169,7 @@ match( IMAGE *in, IMAGE *ref, IMAGE *out ) * formed, will produce an image whose PDF matches that of the image from * which @ref was formed. * - * See also: im_histgr(), im_maplut(). + * See also: im_hsp(), im_histgr(), im_maplut(). * * Returns: 0 on success, -1 on error */ diff --git a/libvips/histograms_lut/im_hsp.c b/libvips/histograms_lut/im_hsp.c index 79af9c2b..0db4fbd0 100644 --- a/libvips/histograms_lut/im_hsp.c +++ b/libvips/histograms_lut/im_hsp.c @@ -1,13 +1,4 @@ -/* @(#) Maps imagein to imageout with histogram specified by imageref - * @(#) Both images should have the same number of bands - * @(#) Each band of the output image is specified according to the distribution - * @(#) of grey levels of the reference image - * @(#) - * @(#) Usage: - * @(#) int im_hsp(in, ref, out) - * @(#) IMAGE *in, *ref, *out; - * @(#) - * @(#) Return 0 on success and -1 on error +/* match histograms * * Copyright: 1990, N. Dessipris. * @@ -18,6 +9,8 @@ * - im_ioflag() call changed to im_iocheck() * 25/5/95 JC * - revised + * 24/3/10 + * - gtkdoc */ /* @@ -59,18 +52,29 @@ #include #endif /*WITH_DMALLOC*/ +/** + * 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 *histin = im_open_local( out, "im_hsp:#1", "p" ); - IMAGE *histref = im_open_local( out, "im_hsp:#2", "p" ); - IMAGE *lut = im_open_local( out, "im_hsp:#3", "p" ); + IMAGE *t[3]; - if( !histin || !histref || !lut || - im_histgr( in, histin, -1 ) || - im_histgr( ref, histref, -1 ) || - im_histspec( histin, histref, lut ) || - im_maplut( in, out, lut ) ) + 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 );