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


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

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

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


desc
@Initial verions of the euler algorithm, worked under iac++ v1.0
@


1.3
log
@Extracted the implementation of the euler code into this file,
   the .o may be placed in the iah library.
@
text
@// euler.c              Section: 11.6, Euler Number
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.


#include "euler.h"
#include "UcharDI.h"
#include "DDTempl.h"
#include "UcharConv.h"


//////////////////////////////////////////////////////////////////
// Create the template used for Euler calcuations.
//
IA_DDTemplate<IA_Image<IA_Point<int>, u_char> >
euler_template() {
    // Create template t

    IA_Image<IA_Point<int>,u_char>
	t_im( IA_boxy_pset( IA_Point<int>(0,0), IA_Point<int>(1,1) ),
	      u_char(3) ); // a common value

    t_im[ IA_Point<int>(1, 0) ] = 1;
    t_im[ IA_Point<int>(0, 1) ] = 1;

    // template t created.
    return
	IA_DDTemplate<IA_Image<IA_Point<int>, u_char> >( 2, t_im );
}


//////////////////////////////////////////////////////////////////
// 4-connected Euler Number
//
int
euler_number_e4( const IA_Image<IA_Point<int>,IA_Bit> & image ) {

    // Convert the input to a UDI
    IA_Image<IA_Point<int>,u_char>
	a = image,
	b = linear_product( a, euler_template() );

    return
	sum( IA_Image<IA_Point<int>,u_char>( chi_eq(b,1) )
	     + IA_Image<IA_Point<int>,u_char>( chi_eq(b,3) )
	     - IA_Image<IA_Point<int>,u_char>( chi_eq(b,5) )
	     - IA_Image<IA_Point<int>,u_char>( chi_eq(b,7) )
	     + 2* IA_Image<IA_Point<int>,u_char>( chi_eq(b,2) )
	     + 2* IA_Image<IA_Point<int>,u_char>( chi_eq(b,6) )
	     ) / 4;
}


//////////////////////////////////////////////////////////////////
// 8-connected Euler Number
//
int
euler_number_e8( const IA_Image<IA_Point<int>,IA_Bit> & image ) {

    // Convert the input to a UDI
    IA_Image<IA_Point<int>,u_char>
	a = image,
	b = linear_product( a, euler_template() );

    return
	sum( IA_Image<IA_Point<int>,u_char>( chi_eq(b,1) )
	     + IA_Image<IA_Point<int>,u_char>( chi_eq(b,3) )
	     - IA_Image<IA_Point<int>,u_char>( chi_eq(b,5) )
	     - IA_Image<IA_Point<int>,u_char>( chi_eq(b,7) )
	     - 2* IA_Image<IA_Point<int>,u_char>( chi_eq(b,2) )
	     - 2* IA_Image<IA_Point<int>,u_char>( chi_eq(b,6) )
	     ) / 4;
}
@


1.2
log
@Modified file header and include stmts to be iac++ 2.0 compliant.
Added exit() to main() for picky systems.
@
text
@d1 1
a1 1
// File: euler.c        Section: 11.6, Euler Number
d6 2
d12 5
a16 2
int  main() {

d27 3
a29 1
    IA_DDTemplate<IA_Image<IA_Point<int>, u_char> >  t( 2, t_im );
d32 5
a36 1
    // Let\'s read the image in.
d38 1
d40 2
a41 1
	a( IA_Image<IA_Point<int>,u_char>::read_PGM( cin ) );
d43 16
a58 3
    // Calculate the linear product.
    IA_Image<IA_Point<int>,u_char>
	b( linear_product( a, t ) );
d60 1
d62 2
a63 19
	chi1, chi2, chi3, chi5, chi6, chi7;

    // Calculate each characteristic image of interest

    chi1 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,1) );
    chi2 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,2) );
    chi3 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,3) );
    chi5 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,5) );
    chi6 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,6) );
    chi7 = IA_Image<IA_Point<int>,u_char>( chi_eq(b,7) );

    int e4, e8;

    e4 = sum( chi1 + chi3 - chi5 - chi7 + 2*chi2 + 2*chi6 ) / 4;

    e8 = sum( chi1 + chi3 - chi5 - chi7 - 2*chi2 - 2*chi6 ) / 4;

    cout << "4-connected Euler number is: " << e4 << "\n";
    cout << "8-connected Euler number is: " << e8 << "\n";
d65 8
a72 1
    exit( 0 );
@


1.1
log
@Initial revision
@
text
@d1 2
a2 2
// File: euler.c
//      Copyright 1993, Center for Computer Vision and Visualization,
d7 1
a7 1
#include "UcharConvolutions.h"
d10 1
a10 12
/////////////////////////////////////////////////////////////////////////////
//
// 7.3.3 Euler number, Image Algeber formulation
//
// Reference:  Image Algebra Handbook (IAH)
//
// Assumptions:
//    o  Image is read from standard in
//    o  Image format is PGM
//    o  The image is binary
//
/////////////////////////////////////////////////////////////////////////////
a11 3

main() {

d54 2
@
