add a direct path to flood for labelregions
This commit is contained in:
parent
1380f59e89
commit
3277e26e65
7
TODO
7
TODO
@ -1,3 +1,10 @@
|
|||||||
|
- add a direct route to flood for label_regions, delay speeding up operation
|
||||||
|
dispatch for now, seems like a large job
|
||||||
|
|
||||||
|
a direct path can also avoid things like vector_to_ink, which involve
|
||||||
|
running a pipeline to generate a single pixel
|
||||||
|
|
||||||
|
almost working
|
||||||
|
|
||||||
- it was quick ..
|
- it was quick ..
|
||||||
|
|
||||||
|
@ -518,6 +518,68 @@ vips_draw_flood_init( VipsDrawFlood *draw_flood )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Direct path to flood for vips_labelregions(). We need to avoid the function
|
||||||
|
* dispatch system for speed.
|
||||||
|
*
|
||||||
|
* Equivalent to:
|
||||||
|
*
|
||||||
|
* vips_draw_flood1( image, serial, x, y,
|
||||||
|
* "test", test,
|
||||||
|
* "equal", TRUE,
|
||||||
|
* NULL )
|
||||||
|
*
|
||||||
|
* image must be 1-band int.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
vips__draw_flood_direct( VipsImage *image, VipsImage *test,
|
||||||
|
int serial, int x, int y )
|
||||||
|
{
|
||||||
|
VipsDrawFlood *flood = (VipsDrawFlood *)
|
||||||
|
vips_operation_new( "draw_flood" );
|
||||||
|
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( flood );
|
||||||
|
|
||||||
|
if( vips_check_format( class->nickname, image, VIPS_FORMAT_INT ) ||
|
||||||
|
vips_check_mono( class->nickname, image ) ||
|
||||||
|
vips_check_coding_known( class->nickname, test ) ||
|
||||||
|
vips_check_size_same( class->nickname, test, image ) ||
|
||||||
|
vips_image_wio_input( test ) ) {
|
||||||
|
g_object_unref( flood );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
((VipsDraw *) flood)->image = image;
|
||||||
|
|
||||||
|
if( !(((VipsDrawink *) flood)->pixel_ink = VIPS_ARRAY( flood,
|
||||||
|
VIPS_IMAGE_SIZEOF_PEL( image ), VipsPel )) ) {
|
||||||
|
g_object_unref( flood );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
*((int *) (((VipsDrawink *) flood)->pixel_ink)) = serial;
|
||||||
|
|
||||||
|
flood->test = test;
|
||||||
|
flood->tsize = VIPS_IMAGE_SIZEOF_PEL( test );
|
||||||
|
flood->left = flood->x;
|
||||||
|
flood->top = flood->y;
|
||||||
|
flood->right = flood->x;
|
||||||
|
flood->bottom = flood->y;
|
||||||
|
flood->in = buffer_build();
|
||||||
|
flood->out = buffer_build();
|
||||||
|
|
||||||
|
if( !(flood->edge =
|
||||||
|
(VipsPel *) im_malloc( flood, flood->tsize )) ) {
|
||||||
|
g_object_unref( flood );
|
||||||
|
return( -1 );
|
||||||
|
}
|
||||||
|
memcpy( flood->edge,
|
||||||
|
VIPS_IMAGE_ADDR( test, x, y ), flood->tsize );
|
||||||
|
|
||||||
|
vips_draw_flood_all( flood );
|
||||||
|
|
||||||
|
g_object_unref( flood );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vips_draw_floodv( VipsImage *image,
|
vips_draw_floodv( VipsImage *image,
|
||||||
double *ink, int n, int x, int y, va_list ap )
|
double *ink, int n, int x, int y, va_list ap )
|
||||||
|
@ -259,7 +259,7 @@ int *im_offsets45( int size );
|
|||||||
int im_conv_f_raw( VipsImage *in, VipsImage *out, DOUBLEMASK *mask );
|
int im_conv_f_raw( VipsImage *in, VipsImage *out, DOUBLEMASK *mask );
|
||||||
int im_convsep_f_raw( VipsImage *in, VipsImage *out, DOUBLEMASK *mask );
|
int im_convsep_f_raw( VipsImage *in, VipsImage *out, DOUBLEMASK *mask );
|
||||||
|
|
||||||
/* inplace
|
/* draw
|
||||||
*/
|
*/
|
||||||
|
|
||||||
VipsPel *vips__vector_to_ink( const char *domain,
|
VipsPel *vips__vector_to_ink( const char *domain,
|
||||||
@ -269,8 +269,9 @@ double *vips__ink_to_vector( const char *domain,
|
|||||||
|
|
||||||
VipsPel *im__vector_to_ink( const char *domain,
|
VipsPel *im__vector_to_ink( const char *domain,
|
||||||
VipsImage *im, int n, double *vec );
|
VipsImage *im, int n, double *vec );
|
||||||
VipsImage *im__inplace_base( const char *domain,
|
|
||||||
VipsImage *main, VipsImage *sub, VipsImage *out );
|
int vips__draw_flood_direct( VipsImage *image, VipsImage *test,
|
||||||
|
int serial, int x, int y );
|
||||||
|
|
||||||
/* Register base vips interpolators, called during startup.
|
/* Register base vips interpolators, called during startup.
|
||||||
*/
|
*/
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
|
#include <vips/internal.h>
|
||||||
|
|
||||||
#include "pmorphology.h"
|
#include "pmorphology.h"
|
||||||
|
|
||||||
@ -87,11 +88,16 @@ vips_labelregions_build( VipsObject *object )
|
|||||||
for( y = 0; y < t[1]->Ysize; y++ ) {
|
for( y = 0; y < t[1]->Ysize; y++ ) {
|
||||||
for( x = 0; x < t[1]->Xsize; x++ ) {
|
for( x = 0; x < t[1]->Xsize; x++ ) {
|
||||||
if( !m[x] ) {
|
if( !m[x] ) {
|
||||||
|
/*
|
||||||
if( vips_draw_flood1( t[1], serial, x, y,
|
if( vips_draw_flood1( t[1], serial, x, y,
|
||||||
"test", in,
|
"test", in,
|
||||||
"equal", TRUE,
|
"equal", TRUE,
|
||||||
NULL ) )
|
NULL ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
*/
|
||||||
|
if( vips__draw_flood_direct( t[1], in,
|
||||||
|
serial, x, y ) )
|
||||||
|
return( -1 );
|
||||||
|
|
||||||
serial += 1;
|
serial += 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user