head	1.4;
access;
symbols;
locks; strict;
comment	@// @;


1.4
date	95.01.10.19.12.53;	author rjj;	state Exp;
branches;
next	1.3;

1.3
date	95.01.10.05.15.24;	author rjj;	state Exp;
branches;
next	1.2;

1.2
date	94.08.29.02.03.01;	author rjj;	state Exp;
branches;
next	1.1;

1.1
date	94.08.05.00.06.23;	author rjj;	state Exp;
branches;
next	;


desc
@Initial version of this algorithm, but not packaged for the library.
@


1.4
log
@Added standard header, changed exit to return.
Modified the algorithm to use neighborhoods for the characteristic
   templates.  This seems to have resulted in a speed up.
@
text
@// File: cccbs.c        Section: 11.4,
//                               Counting Connected Components by Shrinking
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.

#include "Nbh.h"
#include "DDTempl.h"
#include "IntConv.h"


int main( int argc, char * argv[] ) {

    // If any command line args are provided then display
    //    intermediate results, otherwise don\'t.
    int display_intermediates = 0;
    if ( argc == 1 ) {
	cerr << "Intermediate images will not be displayed." << endl;
    } else {
	display_intermediates = 1;
    }

    // Build neighborhoods  s,  and t
    IA_Neighborhood<IA_Point<int>,IA_Point<int> >
	s( 2,
	   IA_boxy_pset( IA_Point<int>(0,-1), IA_Point<int>(0,0) )
	   | IA_Set<IA_Point<int> >( IA_Point<int>(1,0) )
	   ),
	t( 2,
	   IA_Set<IA_Point<int> >( IA_Point<int>(0,0) )
	   | IA_Set<IA_Point<int> >( IA_Point<int>(1,-1) )
	   );

    // Build template u
    IA_Image<IA_Point<int>,int>
	u_img( IA_boxy_pset( IA_Point<int>(-1,-1), IA_Point<int>(1,1) ),
	       1 );

    u_img[ IA_Point<int>(0,0) ] = 9;

    IA_DDTemplate<IA_Image<IA_Point<int>, int> >
	u( 2, u_img );

    //
    // And now for the real working stuff
    //
    IA_Image<IA_Point<int>,int>
	a = read_int_PGM(cin);

    int p = 0;
    int oldp = p;
    while ( a != 0 ) {
	// chi_xx results must be convered before using them...
	IA_Image<IA_Point<int>,u_char>
	    chi_image = chi_eq(linear_product(a,u), 9);

	p += sum( chi_image );  // Add any new single points.

	if ( display_intermediates && (p != oldp) ) {
	    oldp = p;
	    display( to_uchar(a) );
	    cout << "Patterns found so far: " << p << endl;
	    cout.flush();
	}

	// chi_xx results are not well handled yet, so do this in steps
	chi_image  = chi_gt( sum(a,s), 1 );
	chi_image += IA_Image<IA_Point<int>,u_char>(
	    chi_gt( sum(a,t), 1 ) );
	a = chi_gt( chi_image, 0 );
    };

    cout << "Total number of patterns: " << p << endl;
    cout.flush();

    return 0;
}
@


1.3
log
@Added standard header, changed read to non member version, changed
   some variable names for readibility, added switch to control
   display of intermediates.
@
text
@d6 1
d22 10
a31 1
    // Build templates  s,  t,  and  u
d33 1
a34 6
	s_img( IA_boxy_pset( IA_Point<int>(0,-1), IA_Point<int>(0,0) )
	       | IA_Set<IA_Point<int> >( IA_Point<int>(1,0) ),
	       1 ),
	t_img( IA_Set<IA_Point<int> >( IA_Point<int>(0,0) )
	       | IA_Set<IA_Point<int> >( IA_Point<int>(1,-1) ),
	       1 ),
a40 2
	s( 2, s_img ),
	t( 2, t_img ),
d66 1
a66 1
	chi_image  = chi_gt( linear_product(a,s), 1 );
d68 1
a68 1
	    chi_gt( linear_product(a,t), 1 ) );
@


1.2
log
@Modified includes stmts to make iac++ 2.0 compliant.
@
text
@d1 2
a2 1
// File: cccbs.c        Section: 11.4
a4 1
// Counting Connected Components by Shrinking
d10 11
a20 1
int main() {
d44 1
a44 1
	a( IA_Image<IA_Point<int>,int>::read_PGM(cin) );
d51 3
a53 2
	    chi_im( chi_eq(linear_product(a,u), 9) );
	p = p + sum( chi_im );
d55 2
a56 2
	if (p != oldp) {
	    oldp=p;
d63 2
a64 2
	chi_im  = chi_gt( linear_product(a,s), 1 );
	chi_im += IA_Image<IA_Point<int>,u_char>(
d66 1
a66 1
	a = chi_gt( chi_im, 0 );
d72 1
a72 1
    exit( 0 );
@


1.1
log
@Initial revision
@
text
@d7 1
a7 1
#include "IntConvolutions.h"
d10 1
a10 1
main() {
d60 2
@
