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


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

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


desc
@Initial version of the template version of the Median Filter.
@


1.2
log
@Modified includes to make iac++ 2.0 compliant.
@
text
@// median3x3.c          Section: 2.8
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
// Image Algebra C++ implementation of a 3x3 median filter
//


#include "median3x3.h"
#include "DDTempl.h"
#include "UcharConv.h"
#include "IntConv.h"
#include "FloatConv.h"



///////////////////////////////////////////////////////////////////
// median3x3()
// Calculate the median image for this image, based on a 3x3 grid,
//    utilizing templates.

template <class P, class T>
IA_Image<P,T>
median3x3( const IA_Image<P,T> & aImage ) {

    unsigned int aDimen = aImage.domain().dim();
    if (aDimen != 2) {
	ia_throw( IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return aImage;
    }


    // Create the necessary 1 point point sets
    IA_Set< P >
	t1_pointset( P( 0, 1) ),
	t2_pointset( P(-1, 1) ),
	t3_pointset( P(-1, 0) ),
	t4_pointset( P(-1,-1) ),
	t5_pointset( P( 0,-1) ),
	t6_pointset( P( 1,-1) ),
	t7_pointset( P( 1, 0) ),
	t8_pointset( P( 1, 1) );

    IA_Image<P,T>
	t1_image( t1_pointset, T(1) ), // Create images by assigning
	t2_image( t2_pointset, T(1) ), // values to domain points
	t3_image( t3_pointset, T(1) ),
	t4_image( t4_pointset, T(1) ),
	t5_image( t5_pointset, T(1) ),
	t6_image( t6_pointset, T(1) ),
	t7_image( t7_pointset, T(1) ),
	t8_image( t8_pointset, T(1) );

    // The domain of these templates are all the same,
    // the argument image domain.
    IA_Set< P >
	aps(aImage.domain());


    IA_DDTemplate< IA_Image<P,T> >
	t1( aps, t1_image ),  // Make templates from images
	t2( aps, t2_image ),
	t3( aps, t3_image ),
	t4( aps, t4_image ),
	t5( aps, t5_image ),
	t6( aps, t6_image ),
	t7( aps, t7_image ),
	t8( aps, t8_image );


    //////////////////////////////////////////////////////
    //  End of template definition section
    //////////////////////////////////////////////////////


    // Declare the image variables that are to be used

    IA_Image<P,T>  a[9];


    // The first image in the array is simply the input image.
    a[0] = aImage;

    // The other images are products of the first image and a template
    a[1] = linear_product( aImage, t1 );
    a[2] = linear_product( aImage, t2 );
    a[3] = linear_product( aImage, t3 );
    a[4] = linear_product( aImage, t4 );
    a[5] = linear_product( aImage, t5 );
    a[6] = linear_product( aImage, t6 );
    a[7] = linear_product( aImage, t7 );
    a[8] = linear_product( aImage, t8 );


    //////////////////////////////////////////////////////
    // Most of the work has now been done.
    // Now the median value of the 9 parallel images must
    //   be found.  This can be done by sorting the image values,
    //   the result is then be a[4].
    //

    for (int i=0; i<=4; i++) {
	for (int j=i+1; j<=8; j++) {
	    IA_Image<P,T>
		b = max(a[i],a[j]);
	    a[j]  = min(a[i],a[j]);
	    a[i]  = b;
	}
    }

    return a[4];
}
@


1.1
log
@Initial revision
@
text
@d10 3
a12 3
#include "UcharConvolutions.h"
#include "IntConvolutions.h"
#include "FloatConvolutions.h"
@
