im_project() becomes a class
This commit is contained in:
parent
f68a09949a
commit
2088e3d111
@ -5,7 +5,7 @@
|
|||||||
- rewrite im_buildlut(), im_identity*(), im_maplut(), im_falsecolour(),
|
- rewrite im_buildlut(), im_identity*(), im_maplut(), im_falsecolour(),
|
||||||
im_gammacorrect(), im_histgr(), im_histcum(), im_histnorm(), im_heq(),
|
im_gammacorrect(), im_histgr(), im_histcum(), im_histnorm(), im_heq(),
|
||||||
im_histnD(), im_histindexed(), im_histspec(), im_invertlut(), im_lhisteq(),
|
im_histnD(), im_histindexed(), im_histspec(), im_invertlut(), im_lhisteq(),
|
||||||
im_stdif() as classes
|
im_stdif(), im_project() as classes
|
||||||
- vips_hist_local(), vips_stdif() do any number of bands
|
- vips_hist_local(), vips_stdif() do any number of bands
|
||||||
- thin vips8 wrapper for im_histplot()
|
- thin vips8 wrapper for im_histplot()
|
||||||
- added vips_error_freeze() / vips_error_thaw()
|
- added vips_error_freeze() / vips_error_thaw()
|
||||||
|
16
TODO
16
TODO
@ -1,3 +1,19 @@
|
|||||||
|
- try:
|
||||||
|
|
||||||
|
$ vips extract_band 50310.svs x.tif[pyramid,tile,compression=jpeg,tile-width=256,tile-height=256] 0 --n 3
|
||||||
|
** VIPS:ERROR:buffer.c:216:vips_buffer_undone: assertion failed: (cache->thread == g_thread_self())
|
||||||
|
Aborted (core dumped)
|
||||||
|
|
||||||
|
not showing in 7.34, perhaps because asserts are off?
|
||||||
|
|
||||||
|
- support planar config in tiff reader
|
||||||
|
|
||||||
|
- support GA (greyscale with alpha) in tiff reader
|
||||||
|
|
||||||
|
$ vips extract_band shark.jpg x.tif 0 -n 2
|
||||||
|
$ header x.tif
|
||||||
|
header: tiff2vips: required field 277 = 2, not 1
|
||||||
|
|
||||||
- is vips_hist_local() correct? it seems to leave white dots everywhere
|
- is vips_hist_local() correct? it seems to leave white dots everywhere
|
||||||
|
|
||||||
- use VipsInterpolate to generate intermediate values in buildlut etc.
|
- use VipsInterpolate to generate intermediate values in buildlut etc.
|
||||||
|
@ -18,6 +18,7 @@ libarithmetic_la_SOURCES = \
|
|||||||
hist_find.c \
|
hist_find.c \
|
||||||
hist_find_ndim.c \
|
hist_find_ndim.c \
|
||||||
hist_find_indexed.c \
|
hist_find_indexed.c \
|
||||||
|
project.c \
|
||||||
subtract.c \
|
subtract.c \
|
||||||
math.c \
|
math.c \
|
||||||
arithmetic.c \
|
arithmetic.c \
|
||||||
|
@ -695,6 +695,7 @@ vips_arithmetic_operation_init( void )
|
|||||||
extern GType vips_hist_find_get_type( void );
|
extern GType vips_hist_find_get_type( void );
|
||||||
extern GType vips_hist_find_ndim_get_type( void );
|
extern GType vips_hist_find_ndim_get_type( void );
|
||||||
extern GType vips_hist_find_indexed_get_type( void );
|
extern GType vips_hist_find_indexed_get_type( void );
|
||||||
|
extern GType vips_project_get_type( void );
|
||||||
extern GType vips_measure_get_type( void );
|
extern GType vips_measure_get_type( void );
|
||||||
extern GType vips_round_get_type( void );
|
extern GType vips_round_get_type( void );
|
||||||
extern GType vips_relational_get_type( void );
|
extern GType vips_relational_get_type( void );
|
||||||
@ -727,6 +728,7 @@ vips_arithmetic_operation_init( void )
|
|||||||
vips_hist_find_get_type();
|
vips_hist_find_get_type();
|
||||||
vips_hist_find_ndim_get_type();
|
vips_hist_find_ndim_get_type();
|
||||||
vips_hist_find_indexed_get_type();
|
vips_hist_find_indexed_get_type();
|
||||||
|
vips_project_get_type();
|
||||||
vips_measure_get_type();
|
vips_measure_get_type();
|
||||||
vips_round_get_type();
|
vips_round_get_type();
|
||||||
vips_relational_get_type();
|
vips_relational_get_type();
|
||||||
|
@ -419,6 +419,7 @@ vips_hist_find_init( VipsHistFind *hist_find )
|
|||||||
* vips_hist_find:
|
* vips_hist_find:
|
||||||
* @in: input image
|
* @in: input image
|
||||||
* @out: output image
|
* @out: output image
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
|
@ -400,6 +400,7 @@ vips_hist_find_indexed_init( VipsHistFindIndexed *hist_find )
|
|||||||
* @in: input image
|
* @in: input image
|
||||||
* @index: input index image
|
* @index: input index image
|
||||||
* @out: output image
|
* @out: output image
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* Make a histogram of @in, but use image @index to pick the bins. In other
|
* Make a histogram of @in, but use image @index to pick the bins. In other
|
||||||
* words, element zero in @out contains the sum of all the pixels in @in
|
* words, element zero in @out contains the sum of all the pixels in @in
|
||||||
|
@ -318,6 +318,7 @@ vips_hist_find_ndim_init( VipsHistFindNDim *ndim )
|
|||||||
* vips_hist_find_ndim:
|
* vips_hist_find_ndim:
|
||||||
* @in: input image
|
* @in: input image
|
||||||
* @out: output image
|
* @out: output image
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
|
395
libvips/arithmetic/project.c
Normal file
395
libvips/arithmetic/project.c
Normal file
@ -0,0 +1,395 @@
|
|||||||
|
/* horizontal and vertical projection
|
||||||
|
*
|
||||||
|
* 20/4/06
|
||||||
|
* - from im_histgr()
|
||||||
|
* 25/3/10
|
||||||
|
* - gtkdoc
|
||||||
|
* - small celanups
|
||||||
|
* 11/9/13
|
||||||
|
* - redo as a class, from vips_hist_find()
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
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 <string.h>
|
||||||
|
|
||||||
|
#include <vips/vips.h>
|
||||||
|
|
||||||
|
#include "statistic.h"
|
||||||
|
|
||||||
|
struct _Project;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/* Horizontal array: sums of all columns.
|
||||||
|
*/
|
||||||
|
void *column_sums;
|
||||||
|
|
||||||
|
/* Vertical array: sums of all rows.
|
||||||
|
*/
|
||||||
|
void *row_sums;
|
||||||
|
} Histogram;
|
||||||
|
|
||||||
|
typedef struct _VipsProject {
|
||||||
|
VipsStatistic parent_instance;
|
||||||
|
|
||||||
|
/* Main image histogram. Subhists accumulate to this.
|
||||||
|
*/
|
||||||
|
Histogram *hist;
|
||||||
|
|
||||||
|
/* Write sums here.
|
||||||
|
*/
|
||||||
|
VipsImage *columns;
|
||||||
|
VipsImage *rows;
|
||||||
|
|
||||||
|
} VipsProject;
|
||||||
|
|
||||||
|
typedef VipsStatisticClass VipsProjectClass;
|
||||||
|
|
||||||
|
G_DEFINE_TYPE( VipsProject, vips_project, VIPS_TYPE_STATISTIC );
|
||||||
|
|
||||||
|
/* Save a bit of typing.
|
||||||
|
*/
|
||||||
|
#define UI VIPS_FORMAT_UINT
|
||||||
|
#define I VIPS_FORMAT_INT
|
||||||
|
#define D VIPS_FORMAT_DOUBLE
|
||||||
|
#define N VIPS_FORMAT_NOTSET
|
||||||
|
|
||||||
|
static const VipsBandFormat vips_project_format_table[10] = {
|
||||||
|
/* UC C US S UI I F X D DX */
|
||||||
|
UI, I, UI, I, UI, I, D, N, D, N
|
||||||
|
};
|
||||||
|
|
||||||
|
static Histogram *
|
||||||
|
histogram_new( VipsProject *project )
|
||||||
|
{
|
||||||
|
VipsStatistic *statistic = VIPS_STATISTIC( project );
|
||||||
|
VipsImage *in = statistic->ready;
|
||||||
|
VipsBandFormat outfmt = vips_project_format_table[in->BandFmt];
|
||||||
|
int psize = vips__image_sizeof_bandformat[outfmt] * in->Bands;
|
||||||
|
|
||||||
|
Histogram *hist;
|
||||||
|
|
||||||
|
if( !(hist = VIPS_NEW( project, Histogram )) )
|
||||||
|
return( NULL );
|
||||||
|
hist->column_sums = VIPS_ARRAY( project, psize * in->Xsize, guchar );
|
||||||
|
hist->row_sums = VIPS_ARRAY( project, psize * in->Ysize, guchar );
|
||||||
|
if( !hist->column_sums ||
|
||||||
|
!hist->row_sums )
|
||||||
|
return( NULL );
|
||||||
|
|
||||||
|
memset( hist->column_sums, 0, psize * in->Xsize );
|
||||||
|
memset( hist->row_sums, 0, psize * in->Ysize );
|
||||||
|
|
||||||
|
return( hist );
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
vips_project_build( VipsObject *object )
|
||||||
|
{
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||||
|
VipsStatistic *statistic = VIPS_STATISTIC( object );
|
||||||
|
VipsProject *project = (VipsProject *) object;
|
||||||
|
|
||||||
|
int y;
|
||||||
|
|
||||||
|
if( statistic->in &&
|
||||||
|
vips_check_noncomplex( class->nickname, statistic->in ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
g_object_set( object,
|
||||||
|
"columns", vips_image_new(),
|
||||||
|
"rows", vips_image_new(),
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
/* main hist made on first thread start.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( VIPS_OBJECT_CLASS( vips_project_parent_class )->build( object ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
/* Make the output image.
|
||||||
|
*/
|
||||||
|
if( vips_image_copy_fields( project->columns, statistic->ready ) ||
|
||||||
|
vips_image_copy_fields( project->rows, statistic->ready ) )
|
||||||
|
return( -1 );
|
||||||
|
project->columns->Ysize = 1;
|
||||||
|
project->columns->BandFmt =
|
||||||
|
vips_project_format_table[statistic->ready->BandFmt];
|
||||||
|
project->columns->Type = VIPS_INTERPRETATION_HISTOGRAM;
|
||||||
|
project->rows->Xsize = 1;
|
||||||
|
project->rows->BandFmt =
|
||||||
|
vips_project_format_table[statistic->ready->BandFmt];
|
||||||
|
project->rows->Type = VIPS_INTERPRETATION_HISTOGRAM;
|
||||||
|
|
||||||
|
if( vips_image_write_line( project->columns, 0,
|
||||||
|
(VipsPel *) project->hist->column_sums ) )
|
||||||
|
return( -1 );
|
||||||
|
for( y = 0; y < project->rows->Ysize; y++ )
|
||||||
|
if( vips_image_write_line( project->rows, y,
|
||||||
|
(VipsPel *) project->hist->row_sums +
|
||||||
|
y * VIPS_IMAGE_SIZEOF_PEL( project->rows ) ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Build a sub-hist, based on the main hist.
|
||||||
|
*/
|
||||||
|
static void *
|
||||||
|
vips_project_start( VipsStatistic *statistic )
|
||||||
|
{
|
||||||
|
VipsProject *project = (VipsProject *) statistic;
|
||||||
|
|
||||||
|
/* Make the main hist, if necessary.
|
||||||
|
*/
|
||||||
|
if( !project->hist )
|
||||||
|
project->hist = histogram_new( project );
|
||||||
|
|
||||||
|
return( (void *) histogram_new( project ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add a line of pixels.
|
||||||
|
*/
|
||||||
|
#define ADD_PIXELS( OUT, IN ) { \
|
||||||
|
OUT *row_sums = ((OUT *) project->hist->row_sums) + y * nb; \
|
||||||
|
OUT *column_sums; \
|
||||||
|
IN *p; \
|
||||||
|
\
|
||||||
|
column_sums = ((OUT *) project->hist->column_sums) + x * nb; \
|
||||||
|
p = (IN *) in; \
|
||||||
|
for( i = 0; i < n; i++ ) { \
|
||||||
|
for( j = 0; j < nb; j++ ) { \
|
||||||
|
column_sums[j] += p[j]; \
|
||||||
|
row_sums[j] += p[j]; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
p += nb; \
|
||||||
|
column_sums += nb; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add a region to a project.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
vips_project_scan( VipsStatistic *statistic, void *seq,
|
||||||
|
int x, int y, void *in, int n )
|
||||||
|
{
|
||||||
|
VipsProject *project = (VipsProject *) statistic;
|
||||||
|
int nb = statistic->ready->Bands;
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
switch( statistic->ready->BandFmt ) {
|
||||||
|
case VIPS_FORMAT_UCHAR:
|
||||||
|
//ADD_PIXELS( guint, guchar );
|
||||||
|
|
||||||
|
{
|
||||||
|
guint *row_sums = ((guint *) project->hist->row_sums) + y * nb;
|
||||||
|
guint *column_sums;
|
||||||
|
guchar *p;
|
||||||
|
|
||||||
|
column_sums = ((guint *) project->hist->column_sums) + x * nb;
|
||||||
|
p = (guchar *) in;
|
||||||
|
for( i = 0; i < n; i++ ) {
|
||||||
|
for( j = 0; j < nb; j++ ) {
|
||||||
|
column_sums[j] += p[j];
|
||||||
|
row_sums[j] += p[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
p += nb;
|
||||||
|
column_sums += nb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_CHAR:
|
||||||
|
ADD_PIXELS( int, char );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_USHORT:
|
||||||
|
ADD_PIXELS( guint, gushort );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_SHORT:
|
||||||
|
ADD_PIXELS( int, short );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_UINT:
|
||||||
|
ADD_PIXELS( guint, guint );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_INT:
|
||||||
|
ADD_PIXELS( int, int );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_FLOAT:
|
||||||
|
ADD_PIXELS( double, float );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_DOUBLE:
|
||||||
|
ADD_PIXELS( double, double );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ADD_BUFFER( TYPE, Q, P, N ) { \
|
||||||
|
TYPE *p = (TYPE *) (P); \
|
||||||
|
TYPE *q = (TYPE *) (Q); \
|
||||||
|
int n = (N); \
|
||||||
|
int i; \
|
||||||
|
\
|
||||||
|
for( i = 0; i < n; i++ ) \
|
||||||
|
q[i] += p[i]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Join a sub-project onto the main project.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
vips_project_stop( VipsStatistic *statistic, void *seq )
|
||||||
|
{
|
||||||
|
VipsProject *project = (VipsProject *) statistic;
|
||||||
|
Histogram *hist = project->hist;
|
||||||
|
Histogram *sub_hist = (Histogram *) seq;
|
||||||
|
VipsImage *in = statistic->ready;
|
||||||
|
VipsBandFormat outfmt = vips_project_format_table[in->BandFmt];
|
||||||
|
int psize = vips__image_sizeof_bandformat[outfmt] * in->Bands;
|
||||||
|
int hsz = in->Xsize * in->Bands;
|
||||||
|
int vsz = in->Ysize * in->Bands;
|
||||||
|
|
||||||
|
/* Add on sub-data.
|
||||||
|
*/
|
||||||
|
switch( outfmt ) {
|
||||||
|
case VIPS_FORMAT_UINT:
|
||||||
|
ADD_BUFFER( guint,
|
||||||
|
hist->column_sums, sub_hist->column_sums, hsz );
|
||||||
|
ADD_BUFFER( guint, hist->row_sums, sub_hist->row_sums, vsz );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_INT:
|
||||||
|
ADD_BUFFER( int,
|
||||||
|
hist->column_sums, sub_hist->column_sums, hsz );
|
||||||
|
ADD_BUFFER( int, hist->row_sums, sub_hist->row_sums, vsz );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_DOUBLE:
|
||||||
|
ADD_BUFFER( double,
|
||||||
|
hist->column_sums, sub_hist->column_sums, hsz );
|
||||||
|
ADD_BUFFER( double, hist->row_sums, sub_hist->row_sums, vsz );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Blank out sub-project to make sure we can't add it again.
|
||||||
|
*/
|
||||||
|
memset( sub_hist->column_sums, 0, psize * in->Xsize );
|
||||||
|
memset( sub_hist->row_sums, 0, psize * in->Ysize );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_project_class_init( VipsProjectClass *class )
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = (GObjectClass *) class;
|
||||||
|
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||||
|
VipsStatisticClass *sclass = VIPS_STATISTIC_CLASS( class );
|
||||||
|
|
||||||
|
gobject_class->set_property = vips_object_set_property;
|
||||||
|
gobject_class->get_property = vips_object_get_property;
|
||||||
|
|
||||||
|
object_class->nickname = "project";
|
||||||
|
object_class->description = _( "find image projections" );
|
||||||
|
object_class->build = vips_project_build;
|
||||||
|
|
||||||
|
sclass->start = vips_project_start;
|
||||||
|
sclass->scan = vips_project_scan;
|
||||||
|
sclass->stop = vips_project_stop;
|
||||||
|
|
||||||
|
VIPS_ARG_IMAGE( class, "columns", 100,
|
||||||
|
_( "Columns" ),
|
||||||
|
_( "Sums of colums" ),
|
||||||
|
VIPS_ARGUMENT_REQUIRED_OUTPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsProject, columns ) );
|
||||||
|
|
||||||
|
VIPS_ARG_IMAGE( class, "rows", 101,
|
||||||
|
_( "Rows" ),
|
||||||
|
_( "Sums of rows" ),
|
||||||
|
VIPS_ARGUMENT_REQUIRED_OUTPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsProject, rows ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
vips_project_init( VipsProject *project )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* vips_project:
|
||||||
|
* @in: input image
|
||||||
|
* @hout: sums of rows
|
||||||
|
* @vout: sums of columns
|
||||||
|
* @...: %NULL-terminated list of optional named arguments
|
||||||
|
*
|
||||||
|
* Find the horizontal and vertical projections of an image, ie. the sum
|
||||||
|
* of every row of pixels, and the sum of every column of pixels. The output
|
||||||
|
* format is uint, int or double, depending on the input format.
|
||||||
|
*
|
||||||
|
* Non-complex images only.
|
||||||
|
*
|
||||||
|
* See also: vips_hist_find(), vips_profile().
|
||||||
|
*
|
||||||
|
* Returns: 0 on success, -1 on error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vips_project( VipsImage *in, VipsImage **hout, VipsImage **vout, ... )
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
va_start( ap, vout );
|
||||||
|
result = vips_call_split( "project", ap, in, hout, vout );
|
||||||
|
va_end( ap );
|
||||||
|
|
||||||
|
return( result );
|
||||||
|
}
|
||||||
|
|
@ -3522,6 +3522,29 @@ im_hist_indexed( VipsImage *index, VipsImage *value, VipsImage *out )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
im_project( IMAGE *in, IMAGE *hout, IMAGE *vout )
|
||||||
|
{
|
||||||
|
VipsImage *x, *y;
|
||||||
|
|
||||||
|
if( vips_project( in, &x, &y, NULL ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
|
if( im_copy( x, hout ) ) {
|
||||||
|
g_object_unref( x );
|
||||||
|
g_object_unref( y );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
g_object_unref( x );
|
||||||
|
|
||||||
|
if( im_copy( y, vout ) ) {
|
||||||
|
g_object_unref( y );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
g_object_unref( y );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
int
|
int
|
||||||
im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
|
im_hsp( IMAGE *in, IMAGE *ref, IMAGE *out )
|
||||||
{
|
{
|
||||||
|
@ -15,7 +15,6 @@ libhistogram_la_SOURCES = \
|
|||||||
stdif.c \
|
stdif.c \
|
||||||
\
|
\
|
||||||
im_mpercent.c \
|
im_mpercent.c \
|
||||||
im_project.c \
|
|
||||||
tone.c
|
tone.c
|
||||||
|
|
||||||
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
AM_CPPFLAGS = -I${top_srcdir}/libvips/include @VIPS_CFLAGS@ @VIPS_INCLUDES@
|
||||||
|
@ -1,304 +0,0 @@
|
|||||||
/* horizontal and vertical projection
|
|
||||||
*
|
|
||||||
* 20/4/06
|
|
||||||
* - from im_histgr()
|
|
||||||
* 25/3/10
|
|
||||||
* - gtkdoc
|
|
||||||
* - small celanups
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
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 <string.h>
|
|
||||||
|
|
||||||
#include <vips/vips.h>
|
|
||||||
|
|
||||||
/* Accumulate a projection in one of these.
|
|
||||||
*/
|
|
||||||
typedef struct {
|
|
||||||
IMAGE *in;
|
|
||||||
IMAGE *hout;
|
|
||||||
IMAGE *vout;
|
|
||||||
void *columns;
|
|
||||||
void *rows;
|
|
||||||
} Project;
|
|
||||||
|
|
||||||
/* For each input bandfmt, the type we accumulate pixels in.
|
|
||||||
*/
|
|
||||||
static int project_type[] = {
|
|
||||||
IM_BANDFMT_UINT, /* IM_BANDFMT_UCHAR */
|
|
||||||
IM_BANDFMT_INT, /* IM_BANDFMT_CHAR */
|
|
||||||
IM_BANDFMT_UINT, /* IM_BANDFMT_USHORT */
|
|
||||||
IM_BANDFMT_INT, /* IM_BANDFMT_SHORT */
|
|
||||||
IM_BANDFMT_UINT, /* IM_BANDFMT_UINT */
|
|
||||||
IM_BANDFMT_INT, /* IM_BANDFMT_INT */
|
|
||||||
IM_BANDFMT_DOUBLE, /* IM_BANDFMT_FLOAT */
|
|
||||||
IM_BANDFMT_NOTSET, /* IM_BANDFMT_COMPLEX */
|
|
||||||
IM_BANDFMT_DOUBLE, /* IM_BANDFMT_DOUBLE */
|
|
||||||
IM_BANDFMT_NOTSET /* IM_BANDFMT_DPCOMPLEX */
|
|
||||||
};
|
|
||||||
|
|
||||||
static Project *
|
|
||||||
project_new( IMAGE *in, IMAGE *hout, IMAGE *vout )
|
|
||||||
{
|
|
||||||
Project *project;
|
|
||||||
int psize = IM_IMAGE_SIZEOF_PEL( hout );
|
|
||||||
|
|
||||||
if( !(project = IM_NEW( hout, Project )) )
|
|
||||||
return( NULL );
|
|
||||||
project->in = in;
|
|
||||||
project->hout = hout;
|
|
||||||
project->vout = vout;
|
|
||||||
project->columns = IM_ARRAY( hout, psize * in->Xsize, guchar );
|
|
||||||
project->rows = IM_ARRAY( hout, psize * in->Ysize, guchar );
|
|
||||||
if( !project->columns || !project->rows )
|
|
||||||
return( NULL );
|
|
||||||
|
|
||||||
memset( project->columns, 0, psize * in->Xsize );
|
|
||||||
memset( project->rows, 0, psize * in->Ysize );
|
|
||||||
|
|
||||||
return( project );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Build a sub-project, based on the main project.
|
|
||||||
*/
|
|
||||||
static void *
|
|
||||||
project_new_sub( IMAGE *out, void *a, void *b )
|
|
||||||
{
|
|
||||||
Project *mproject = (Project *) a;
|
|
||||||
|
|
||||||
return( project_new( mproject->in, mproject->hout, mproject->vout ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ADD_BUFFER( TYPE, Q, P, N ) { \
|
|
||||||
TYPE *p = (TYPE *) (P); \
|
|
||||||
TYPE *q = (TYPE *) (Q); \
|
|
||||||
int n = (N); \
|
|
||||||
int i; \
|
|
||||||
\
|
|
||||||
for( i = 0; i < n; i++ ) \
|
|
||||||
q[i] += p[i]; \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Join a sub-project onto the main project.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
project_merge( void *seq, void *a, void *b )
|
|
||||||
{
|
|
||||||
Project *sproject = (Project *) seq;
|
|
||||||
Project *mproject = (Project *) a;
|
|
||||||
IMAGE *in = mproject->in;
|
|
||||||
IMAGE *out = mproject->hout;
|
|
||||||
int hsz = in->Xsize * in->Bands;
|
|
||||||
int vsz = in->Ysize * in->Bands;
|
|
||||||
|
|
||||||
g_assert( sproject->hout == mproject->hout );
|
|
||||||
g_assert( sproject->vout == mproject->vout );
|
|
||||||
|
|
||||||
/* Add on sub-data.
|
|
||||||
*/
|
|
||||||
switch( out->BandFmt ) {
|
|
||||||
case IM_BANDFMT_UINT:
|
|
||||||
ADD_BUFFER( guint, mproject->columns, sproject->columns, hsz );
|
|
||||||
ADD_BUFFER( guint, mproject->rows, sproject->rows, vsz );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_INT:
|
|
||||||
ADD_BUFFER( int, mproject->columns, sproject->columns, hsz );
|
|
||||||
ADD_BUFFER( int, mproject->rows, sproject->rows, vsz );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_DOUBLE:
|
|
||||||
ADD_BUFFER( double, mproject->columns, sproject->columns, hsz );
|
|
||||||
ADD_BUFFER( double, mproject->rows, sproject->rows, vsz );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_assert( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Blank out sub-project to make sure we can't add it again.
|
|
||||||
*/
|
|
||||||
memset( sproject->columns, 0, IM_IMAGE_SIZEOF_ELEMENT( out ) * hsz );
|
|
||||||
memset( sproject->rows, 0, IM_IMAGE_SIZEOF_ELEMENT( out ) * vsz );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add an area of pixels.
|
|
||||||
*/
|
|
||||||
#define ADD_PIXELS( OUTTYPE, INTYPE ) { \
|
|
||||||
OUTTYPE *rows; \
|
|
||||||
OUTTYPE *columns; \
|
|
||||||
INTYPE *p; \
|
|
||||||
\
|
|
||||||
rows = ((OUTTYPE *) project->rows) + to * nb; \
|
|
||||||
for( y = 0; y < r->height; y++ ) { \
|
|
||||||
columns = ((OUTTYPE *) project->columns) + le * nb; \
|
|
||||||
p = (INTYPE *) IM_REGION_ADDR( reg, le, y + to ); \
|
|
||||||
\
|
|
||||||
for( x = 0; x < r->width; x++ ) { \
|
|
||||||
for( z = 0; z < nb; z++ ) { \
|
|
||||||
columns[z] += p[z]; \
|
|
||||||
rows[z] += p[z]; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
p += nb; \
|
|
||||||
columns += nb; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
rows += nb; \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Add a region to a project.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
project_scan( REGION *reg, void *seq, void *a, void *b, gboolean *stop )
|
|
||||||
{
|
|
||||||
Project *project = (Project *) seq;
|
|
||||||
Rect *r = ®->valid;
|
|
||||||
int le = r->left;
|
|
||||||
int to = r->top;
|
|
||||||
int nb = project->in->Bands;
|
|
||||||
int x, y, z;
|
|
||||||
|
|
||||||
switch( project->in->BandFmt ) {
|
|
||||||
case IM_BANDFMT_UCHAR:
|
|
||||||
ADD_PIXELS( guint, guchar );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_CHAR:
|
|
||||||
ADD_PIXELS( int, char );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_USHORT:
|
|
||||||
ADD_PIXELS( guint, gushort );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_SHORT:
|
|
||||||
ADD_PIXELS( int, short );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_UINT:
|
|
||||||
ADD_PIXELS( guint, guint );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_INT:
|
|
||||||
ADD_PIXELS( int, int );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_FLOAT:
|
|
||||||
ADD_PIXELS( double, float );
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IM_BANDFMT_DOUBLE:
|
|
||||||
ADD_PIXELS( double, double );
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
g_assert( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* im_project:
|
|
||||||
* @in: input image
|
|
||||||
* @hout: sums of rows
|
|
||||||
* @vout: sums of columns
|
|
||||||
*
|
|
||||||
* Find the horizontal and vertical projections of an image, ie. the sum
|
|
||||||
* of every row of pixels, and the sum of every column of pixels. The output
|
|
||||||
* format is uint, int or double, depending on the input format.
|
|
||||||
*
|
|
||||||
* Non-complex images only.
|
|
||||||
*
|
|
||||||
* See also: im_histgr(), im_profile().
|
|
||||||
*
|
|
||||||
* Returns: 0 on success, -1 on error
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
im_project( IMAGE *in, IMAGE *hout, IMAGE *vout )
|
|
||||||
{
|
|
||||||
Project *mproject;
|
|
||||||
int y;
|
|
||||||
|
|
||||||
/* Check images. PIO from in, WIO to out.
|
|
||||||
*/
|
|
||||||
if( im_check_uncoded( "im_project", in ) ||
|
|
||||||
im_check_noncomplex( "im_project", in ) ||
|
|
||||||
im_pincheck( in ) ||
|
|
||||||
im_outcheck( hout ) ||
|
|
||||||
im_outcheck( vout ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* Make the output images.
|
|
||||||
*/
|
|
||||||
if( im_cp_desc( hout, in ) ||
|
|
||||||
im_cp_desc( vout, in ) )
|
|
||||||
return( -1 );
|
|
||||||
hout->Xsize = 1;
|
|
||||||
hout->BandFmt = project_type[in->BandFmt];
|
|
||||||
hout->Type = IM_TYPE_HISTOGRAM;
|
|
||||||
vout->Ysize = 1;
|
|
||||||
vout->BandFmt = project_type[in->BandFmt];
|
|
||||||
vout->Type = IM_TYPE_HISTOGRAM;
|
|
||||||
|
|
||||||
/* Build the main project we accumulate data in.
|
|
||||||
*/
|
|
||||||
if( !(mproject = project_new( in, hout, vout )) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
/* Accumulate data.
|
|
||||||
*/
|
|
||||||
if( vips_sink( in,
|
|
||||||
project_new_sub, project_scan, project_merge, mproject, NULL ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
if( im_setupout( hout ) ||
|
|
||||||
im_setupout( vout ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
if( im_writeline( 0, vout, (VipsPel *) mproject->columns ) )
|
|
||||||
return( -1 );
|
|
||||||
for( y = 0; y < in->Ysize; y++ )
|
|
||||||
if( im_writeline( y, hout, (VipsPel *) mproject->rows +
|
|
||||||
y * IM_IMAGE_SIZEOF_PEL( hout ) ) )
|
|
||||||
return( -1 );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
@ -384,6 +384,8 @@ int vips_hist_find_ndim( VipsImage *in, VipsImage **out, ... )
|
|||||||
int vips_hist_find_indexed( VipsImage *in, VipsImage *index,
|
int vips_hist_find_indexed( VipsImage *in, VipsImage *index,
|
||||||
VipsImage **out, ... )
|
VipsImage **out, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
int vips_project( VipsImage *in, VipsImage **hout, VipsImage **vout, ... )
|
||||||
|
__attribute__((sentinel));
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,6 @@ int vips_hist_local( VipsImage *in, VipsImage **out,
|
|||||||
int vips_stdif( VipsImage *in, VipsImage **out, int width, int height, ... )
|
int vips_stdif( VipsImage *in, VipsImage **out, int width, int height, ... )
|
||||||
__attribute__((sentinel));
|
__attribute__((sentinel));
|
||||||
|
|
||||||
int im_project( VipsImage *in, VipsImage *hout, VipsImage *vout );
|
|
||||||
|
|
||||||
int im_ismonotonic( VipsImage *lut, int *out );
|
int im_ismonotonic( VipsImage *lut, int *out );
|
||||||
|
|
||||||
int im_mpercent( VipsImage *in, double percent, int *out );
|
int im_mpercent( VipsImage *in, double percent, int *out );
|
||||||
|
@ -861,6 +861,7 @@ int im_heq( VipsImage *in, VipsImage *out, int bandno );
|
|||||||
int im_histnD( VipsImage *in, VipsImage *out, int bins );
|
int im_histnD( VipsImage *in, VipsImage *out, int bins );
|
||||||
int im_hist_indexed( VipsImage *index, VipsImage *value, VipsImage *out );
|
int im_hist_indexed( VipsImage *index, VipsImage *value, VipsImage *out );
|
||||||
int im_histplot( VipsImage *in, VipsImage *out );
|
int im_histplot( VipsImage *in, VipsImage *out );
|
||||||
|
int im_project( VipsImage *in, VipsImage *hout, VipsImage *vout );
|
||||||
int im_hsp( VipsImage *in, VipsImage *ref, VipsImage *out );
|
int im_hsp( VipsImage *in, VipsImage *ref, VipsImage *out );
|
||||||
int im_histspec( VipsImage *in, VipsImage *ref, VipsImage *out );
|
int im_histspec( VipsImage *in, VipsImage *ref, VipsImage *out );
|
||||||
int im_lhisteq( VipsImage *in, VipsImage *out, int xwin, int ywin );
|
int im_lhisteq( VipsImage *in, VipsImage *out, int xwin, int ywin );
|
||||||
|
Loading…
Reference in New Issue
Block a user