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


1.3
date	95.01.10.05.18.07;	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.3
log
@Added standard header, cmd line switch to control display of
  intermediate images, general cleanup.
@
text
@// File: cccbs-alt.c    Section: 11.4, (alternative version)
//                               Counting Connected Components by Shrinking
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.

#include "DDTempl.h"
#include "UcharConv.h"


// f() defined to count 8-components
u_char
f(u_char  r) {
    switch (r%16) {
    case 3:
    case 5:
    case 7:
    case 9:
    case 10:
    case 11:
    case 13:
    case 14:
    case 15:
	return 1;
    };
    return 0;
}


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 template s

    IA_Image<IA_Point<int>,u_char>
	s_img( IA_boxy_pset( IA_Point<int>(-1,-1), IA_Point<int>(1,1) ), 1 );

    s_img[ IA_Point<int>(-1,-1) ] =  16;
    s_img[ IA_Point<int>(-1, 0) ] =  32;
    s_img[ IA_Point<int>(-1, 1) ] =  64;
    s_img[ IA_Point<int>( 0,-1) ] =   8;
    // Target point already has value 1
    s_img[ IA_Point<int>( 0, 1) ] = 128;
    s_img[ IA_Point<int>( 1,-1) ] =   4;
    s_img[ IA_Point<int>( 1, 0) ] =   2;
    s_img[ IA_Point<int>( 1, 1) ] = 256;

    IA_DDTemplate<IA_Image<IA_Point<int>,u_char> >
	s( 2, s_img );

    //
    // And now for the real working stuff
    //
    IA_Image<IA_Point<int>,u_char>
	a( IA_Image<IA_Point<int>,u_char>::read_PGM(cin) );

    int p = 0;
    int oldp = p;
    while ( a != 0 ) {
	a = linear_product(a,s);
	p += sum( IA_Image<IA_Point<int>,u_char>(chi_eq(a,1)) );

	if ( display_intermediates && (p != oldp) ) {
	    display( a );
	    cout << "Patterns found so far: " << p << endl;
	    oldp = p;
	}
	a = compose( f, a );
    };

    cout << "Number of patterns: " << p << endl;

    return 0;
}
@


1.2
log
@Modified includes stmts to make iac++ 2.0 compliant.
@
text
@d1 2
a2 1
// File: cccbs-alt.c    Section: 11.4
a4 1
// Counting Connected Components by Shrinking -- Alternate IA Formulation
d29 10
a38 1
int main() {
d67 3
a69 2
	p = p + sum( IA_Image<IA_Point<int>,u_char>(chi_eq(a,1)) );
	if (p != oldp) {
d79 1
a79 1
    exit( 0 );
@


1.1
log
@Initial revision
@
text
@d7 1
a7 1
#include "UcharConvolutions.h"
d28 2
a29 1
main() {
d68 2
@
