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


1.7
date	94.10.14.04.20.40;	author rjj;	state Exp;
branches;
next	1.6;

1.6
date	94.10.13.06.45.35;	author rjj;	state Exp;
branches;
next	1.5;

1.5
date	94.09.02.04.25.49;	author rjj;	state Exp;
branches;
next	1.4;

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

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

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

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


desc
@Initial neighborhood version of the Median-Filter.
@


1.7
log
@Comment editing and deleting of commented out code.
@
text
@// median.c             Section: 2.8  Median Filter
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
// Image Algebra C++ implementation of a median filter,
//      utilizing neighborhood operations.
//

#include "median.h"
#include "median-gamma.h"


///////////////////////////////////////////////////////////////////
// median()
// Calculate the median filtered image for this image,
//    based on a user supplied neighborhood.

template <class P, class T>
IA_Image<P,T>
median( const IA_Image<P,T> & aImage,
	const IA_Neighborhood<P,P> & median_nbhd ) {

    // We will use a function that takes a array of values
    //   and returns the median of that array.
    // Now we can use the generalized neighborhood_reduction()
    //   with our "gamma()" function to calculate the result image.

    // Force correct choice of median_gamma() functions
    T (*f)(T*,unsigned);
    f = median_gamma;

    return
	neighborhood_reduction( aImage,
				median_nbhd,
				aImage.domain(),
				f );
}
@


1.6
log
@Added algorithm name to header.  Correct spelling errors.
Made style changes.  Added support for median-gamma<T> instantiation.
@
text
@d27 1
a27 1
    // force instantiation of the median_gamma() function.
a31 1
//	neighborhood_reduction( (IA_CoreImage<IA_Point<int>, T> &)aImage,
@


1.5
log
@Cfront seems to require each template function to have its own .c file,
  so I am including  median-gamma.c  directly in median.c.
@
text
@d1 1
a1 1
// median.c             Section: 2.8
d9 1
a9 1
#include "median-gamma.c"
d14 1
a14 1
// Calculate the median image for this image,
d32 2
a33 1
	neighborhood_reduction( (IA_CoreImage<IA_Point<int>, T> &)aImage,
@


1.4
log
@Deleted dependency on files median-gamma.*, instead the contents
  of file median-gamma.c, e.g. definition of median_gamma()
  is now in median.c, where it should have been all along.
@
text
@d9 1
a9 49

///////////////////////////////////////////////////////////////////
// median_gamma<T>()
//    Calculate the median value from an array of values

template <class T>
T
median_gamma( T *values, unsigned int arraySize ) {

    if (arraySize == 0) {
	// This is very bad, because we do not have a default
	//   value to return, or even a resonable guess.
	// So we\'ll issue an error, and return 0 if we
	//   continue from here.
	ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return T(0);
    }

    // We can calculate the median of N items by sorting
    // the array and returning the middle value if odd,
    // otherwise return the average of the middle two values.

    // We could use a quick-sort, but I\'ll use bubble sort
    // for now.

    int midpt = arraySize / 2;
    for( int i=0; i<=midpt; i++ ) { // enough if even or odd
	for( int j=i+1; j<=arraySize; j++ ) {
	    if (values[i] > values[j]) {
		T tmp = values[i];
		values[i] = values[j];
		values[j] = tmp;
	    }
	}
    }

    // Even or odd ?
    // Of course, this assumes that type T supports both
    //   additon (+) and division (/)....
    if (arraySize % 2) {
	// Odd arraySize, so return the middle value
	return values[ midpt ];
    } else {
	// Even arraySize, so return average
	return (values[midpt-1] + values[midpt]) / 2;
    }
}


@


1.3
log
@Tried a couple of things to make the template verison of the
  median_gamma() function instantiate correctly.  I have
  sort of given up on this.
Placing this file under control so it will not get inadvertently
  blown away by a gnumake spotless
@
text
@a8 1
#include "median-gamma.h"
d10 48
a57 3
// Make the definition of the median_gamma() function visible
//     to cfront, so it will provide the appropriate instantiation.
//#include "median-gamma.c"
a74 1
#if 0
d76 2
a77 3
    T mg[1]; mg[0] = T(0);
    mg[0] = median_gamma( mg, (unsigned int) 1 );
#endif
d80 1
a80 1
	neighborhood_reduction( aImage,
d83 1
a83 1
				median_gamma );
@


1.2
log
@Modified include stmts to be iac++ 2.0 compliant
@
text
@d11 3
d15 1
d30 6
@


1.1
log
@Initial revision
@
text
@a9 1
#include "Neighborhood.h"
@
