redo im_mpercent*() as a class
This commit is contained in:
parent
b11de1ce22
commit
326365ab6c
@ -5,7 +5,8 @@
|
||||
- rewrite im_buildlut(), im_identity*(), im_maplut(), im_falsecolour(),
|
||||
im_gammacorrect(), im_histgr(), im_histcum(), im_histnorm(), im_heq(),
|
||||
im_histnD(), im_histindexed(), im_histspec(), im_invertlut(), im_lhisteq(),
|
||||
im_stdif(), im_project(), im_profile(), im_tone_build*() as classes
|
||||
im_stdif(), im_project(), im_profile(), im_tone_build*(), im_mpercent*()
|
||||
as classes
|
||||
- vips_hist_local(), vips_stdif() do any number of bands
|
||||
- thin vips8 wrapper for im_histplot()
|
||||
- added vips_error_freeze() / vips_error_thaw()
|
||||
|
7
TODO
7
TODO
@ -2,8 +2,6 @@
|
||||
|
||||
needs im_conv()
|
||||
|
||||
- need to do im_profile() before we can finish hist_percent()
|
||||
|
||||
- try:
|
||||
|
||||
$ vips extract_band 50310.svs x.tif[pyramid,tile,compression=jpeg,tile-width=256,tile-height=256] 0 --n 3
|
||||
@ -36,6 +34,11 @@
|
||||
effect what vips does for open-via-disc, and therefore see >100mb ram
|
||||
use even in open-via-disc mode
|
||||
|
||||
add SEQUENTIAL_UNBUFFERED?
|
||||
|
||||
could we spot from the demand style? they do almost the same thing,
|
||||
though one is static and one dynamic, I guess
|
||||
|
||||
- support multiscan jpeg write? see
|
||||
|
||||
https://github.com/jcupitt/ruby-vips/issues/41
|
||||
|
@ -3626,6 +3626,25 @@ im_profile( IMAGE *in, IMAGE *out, int dir )
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_mpercent( IMAGE *in, double percent, int *out )
|
||||
{
|
||||
if( vips_hist_percent( in, percent, out, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_mpercent_hist( IMAGE *in, double percent, int *out )
|
||||
{
|
||||
/* Hard to do this in a wrapper.
|
||||
*/
|
||||
vips_error( "im_mpercent_hist", "%s", _( "no compat implemented" ) );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
int
|
||||
im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
|
||||
{
|
||||
|
@ -12,9 +12,9 @@ libhistogram_la_SOURCES = \
|
||||
hist_plot.c \
|
||||
hist_match.c \
|
||||
hist_local.c \
|
||||
hist_percent.c \
|
||||
stdif.c \
|
||||
\
|
||||
im_mpercent.c \
|
||||
tone.c
|
||||
|
||||
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||
|
@ -14,6 +14,7 @@
|
||||
* - gtkdoc
|
||||
* 20/9/13
|
||||
* - wrap as a class
|
||||
* - more accurate
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -70,7 +71,7 @@ static int
|
||||
vips_hist_percent_build( VipsObject *object )
|
||||
{
|
||||
VipsHistPercent *percent = (VipsHistPercent *) object;
|
||||
VipsImage **t = (VipsImage **) vips_object_local_array( object, 6 );
|
||||
VipsImage **t = (VipsImage **) vips_object_local_array( object, 7 );
|
||||
|
||||
double threshold;
|
||||
|
||||
@ -81,14 +82,13 @@ vips_hist_percent_build( VipsObject *object )
|
||||
if( vips_hist_find( percent->in, &t[0], NULL ) ||
|
||||
vips_hist_cum( t[0], &t[1], NULL ) ||
|
||||
vips_hist_norm( t[1], &t[2], NULL ) ||
|
||||
vips_less_const1( t[2], &t[3],
|
||||
percent->percent * t[2]->Xsize, NULL ) ||
|
||||
vips_flip( t[3], &t[4], VIPS_DIRECTION_HORIZONTAL, NULL ) ||
|
||||
im_profile( t[4], &t[5], 1 ) ||
|
||||
vips_avg( t[5], &threshold ) )
|
||||
vips_more_const1( t[2], &t[3],
|
||||
(percent->percent / 100.0) * t[2]->Xsize, NULL ) ||
|
||||
vips_profile( t[3], &t[5], &t[6], NULL ) ||
|
||||
vips_avg( t[6], &threshold, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
percent->threshold = threshold;
|
||||
g_object_set( object, "threshold", (int) threshold, NULL );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -119,7 +119,7 @@ vips_hist_percent_class_init( VipsHistPercentClass *class )
|
||||
G_STRUCT_OFFSET( VipsHistPercent, percent ),
|
||||
0, 100, 50 );
|
||||
|
||||
VIPS_ARG_INT( class, "threshold", 2,
|
||||
VIPS_ARG_INT( class, "threshold", 3,
|
||||
_( "threshold" ),
|
||||
_( "threshold above which lie percent of pixels" ),
|
||||
VIPS_ARGUMENT_REQUIRED_OUTPUT,
|
||||
|
@ -239,6 +239,7 @@ vips_histogram_operation_init( void )
|
||||
extern GType vips_hist_plot_get_type( void );
|
||||
extern GType vips_hist_match_get_type( void );
|
||||
extern GType vips_hist_local_get_type( void );
|
||||
extern GType vips_hist_percent_get_type( void );
|
||||
extern GType vips_stdif_get_type( void );
|
||||
|
||||
vips_maplut_get_type();
|
||||
@ -248,5 +249,6 @@ vips_histogram_operation_init( void )
|
||||
vips_hist_plot_get_type();
|
||||
vips_hist_match_get_type();
|
||||
vips_hist_local_get_type();
|
||||
vips_hist_percent_get_type();
|
||||
vips_stdif_get_type();
|
||||
}
|
||||
|
@ -1,133 +0,0 @@
|
||||
/* find percent of pixels
|
||||
* Copyright: 1990, N. Dessipris
|
||||
*
|
||||
* Author: N. Dessipris
|
||||
* Written on: 02/08/1990
|
||||
* Modified on : 29/4/93 K.Martinez for Sys5
|
||||
* 20/2/95 JC
|
||||
* - now returns result through parameter
|
||||
* - ANSIfied a little
|
||||
* 19/1/07
|
||||
* - redone with the vips hist operators
|
||||
* 25/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 <string.h>
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
/**
|
||||
* im_mpercent_hist:
|
||||
* @hist: input histogram image
|
||||
* @percent: threshold percentage
|
||||
* @out: output threshold value
|
||||
*
|
||||
* Just like im_mpercent(), except it works on an image histogram. Handy if
|
||||
* you want to run im_mpercent() several times without having to recompute the
|
||||
* histogram each time.
|
||||
*
|
||||
* See also: im_mpercent().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
im_mpercent_hist( IMAGE *hist, double percent, int *out )
|
||||
{
|
||||
IMAGE *base;
|
||||
IMAGE *t[6];
|
||||
double pos;
|
||||
|
||||
if( im_check_hist( "im_mpercent", hist ) )
|
||||
return( -1 );
|
||||
|
||||
if( !(base = im_open( "im_mpercent", "p" )) )
|
||||
return( -1 );
|
||||
if( im_open_local_array( base, t, 6, "im_mpercent", "p" ) ) {
|
||||
im_close( base );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if( im_histcum( hist, t[1] ) ||
|
||||
im_histnorm( t[1], t[2] ) ||
|
||||
im_lessconst( t[2], t[3], percent * t[2]->Xsize ) ||
|
||||
im_fliphor( t[3], t[4] ) ||
|
||||
im_profile( t[4], t[5], 1 ) ||
|
||||
im_avg( t[5], &pos ) ) {
|
||||
im_close( base );
|
||||
return( -1 );
|
||||
}
|
||||
im_close( base );
|
||||
|
||||
*out = pos;
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* im_mpercent:
|
||||
* @in: input image
|
||||
* @percent: threshold percentage
|
||||
* @out: output threshold value
|
||||
*
|
||||
* im_mpercent() returns (through the @out parameter) the threshold above
|
||||
* which there are @percent values of @in. If for example percent=.1, the
|
||||
* number of pels of the input image with values greater than the returned
|
||||
* int will correspond to 10% of all pels of the image.
|
||||
*
|
||||
* The function works for uchar and ushort images only. It can be used
|
||||
* to threshold the scaled result of a filtering operation.
|
||||
*
|
||||
* See also: im_histgr(), im_profile().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int
|
||||
im_mpercent( IMAGE *in, double percent, int *out )
|
||||
{
|
||||
IMAGE *t;
|
||||
|
||||
if( !(t = im_open( "im_mpercent1", "p" )) )
|
||||
return( -1 );
|
||||
if( im_histgr( in, t, -1 ) ||
|
||||
im_mpercent_hist( t, percent, out ) ) {
|
||||
im_close( t );
|
||||
return( -1 );
|
||||
}
|
||||
im_close( t );
|
||||
|
||||
return( 0 );
|
||||
}
|
@ -53,14 +53,13 @@ int vips_hist_match( VipsImage *in, VipsImage *ref, VipsImage **out, ... )
|
||||
int vips_hist_local( VipsImage *in, VipsImage **out,
|
||||
int width, int height, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_hist_percent( VipsImage *in, double percent, int *threshold, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_stdif( VipsImage *in, VipsImage **out, int width, int height, ... )
|
||||
__attribute__((sentinel));
|
||||
|
||||
int im_ismonotonic( VipsImage *lut, int *out );
|
||||
|
||||
int im_mpercent( VipsImage *in, double percent, int *out );
|
||||
int im_mpercent_hist( VipsImage *hist, double percent, int *out );
|
||||
|
||||
int im_tone_analyse( VipsImage *in, VipsImage *out,
|
||||
double Ps, double Pm, double Ph, double S, double M, double H );
|
||||
int im_tone_map( VipsImage *in, VipsImage *out, VipsImage *lut );
|
||||
|
@ -876,6 +876,8 @@ int im_histspec( VipsImage *in, VipsImage *ref, VipsImage *out );
|
||||
int im_lhisteq( VipsImage *in, VipsImage *out, int xwin, int ywin );
|
||||
int im_stdif( VipsImage *in, VipsImage *out,
|
||||
double a, double m0, double b, double s0, int xwin, int ywin );
|
||||
int im_mpercent( VipsImage *in, double percent, int *out );
|
||||
int im_mpercent_hist( VipsImage *hist, double percent, int *out );
|
||||
|
||||
/* Not really correct, but who uses these.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user