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


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

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

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


desc
@Initial cut of local-averaging algorithm.  Since the algorithm
  is so straight forward I have chosen to simply provide a
  simple test program rather than an external interface.
@


1.3
log
@Made header confrom with section name.  Spelling error corrections.
@
text
@// test-local-averaging.c  Section: 2.3  Local Averaging
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
//
// The local averaging code is pretty straight forward, so we just
//      define a test program that utilizes it.
// Note that this program implements local averaging using
//      IA_Neighborhood<P,P> and a function that calcualtes an average
//      over just the points in neighborhood around the the target.
// This means that this implementation avoids edge effects by
//      averaging only over the points actually in the image.
//
// This program takes up to two command line arguments:
//      1st arg: radius of shaped-pointset to use (default == 1)
//      2nd arg: if 1 then use cross_hair() otherwise, digital_disc()


#include "Image.h"
#include "Nbh.h"
#include "shaped-pointset.h"


u_char
nbhd_avg( u_char* values, unsigned int vcount ) {
    // We assume that vcount > 0
    int total( 0 );

    for( int i=0; i<vcount; i++ ) {
	total += values[ i ];
    }
    return u_char( total / vcount );
}


int main(int argc, char *argv[]) {
    
    // Radius value ?
    double  argvalue = ( argc > 1 ? atof(argv[1]) : 0.0);
    double  radius(argvalue != 0.0 ? argvalue : 1.0);
    cerr << "Using radius = " << radius << endl;
    
    // Point set shape ?
    //   == 0 => cross_hair()
    //   == 1 => digital_disc()
    int psShape = ( argc > 2 ? atoi(argv[2]) : 0);
    cerr << "Using point set shape = " <<
	    (psShape == 1 ? "cross_hair()" : "digital_disc()" ) << endl;


    IA_Image<IA_Point<int>,u_char>
	a = IA_Image<IA_Point<int>,u_char>::read_PGM(cin);

    // Now we have to decide how to define the neighborhood.
    unsigned int  nbhd_dim = a.domain().dim();

    // Define a neighborhood of the appropriate dimension and
    //   shape.
    IA_Point<int>
	origin = extend_to_point( int(0), nbhd_dim );
    IA_Set<IA_Point<int> >
	nbhd_ps = ( psShape == 1 ?
		    cross_hair( origin, int( radius ) ) :
		    digital_disc( origin, radius ) );

    IA_Neighborhood<IA_Point<int>,IA_Point<int> >
	nbhd( nbhd_dim, nbhd_ps );

    a = neighborhood_reduction( a, nbhd, a.domain(), nbhd_avg );
    
    a.write_PGM(cout);

    return 0;
}
@


1.2
log
@Modified includes to be iac++ 2.0 compliant.
@
text
@d1 1
a1 1
// test-local-averaging.c  Section: 2.3
d5 1
a5 1
// The local averaging code is pretty straigt forward, so we just
d13 1
a13 1
// This program takes upto two command line arguments:
d35 1
a35 1
void main(int argc, char *argv[]) {
d71 2
@


1.1
log
@Initial revision
@
text
@d4 1
d19 1
a19 1
#include "Neighborhood.h"
@
