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


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

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

1.2
date	94.08.31.05.24.49;	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.4
log
@Added algorithm name to header.  Correct spelling errors.
Made style changes.  Added support for median-gamma<T> instantiation.
@
text
@// median-gamma.c       Section: 2.8  Median Filter
//      Copyright 1994, Center for Computer Vision and Visualization,
//      University of Florida.  All rights reserved.
// Support file for the iac++ implementation of a median filter,
//      utilizing neighborhood operations.
//

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


///////////////////////////////////////////////////////////////////
// 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
@This file is now obsolete.  The definition of median_gamma() has
  been moved into median.c
@
text
@d1 1
a1 1
// median-gamma.c       Section: 2.8
d16 1
a16 1
#if 1
a59 82
#else


// Cfront seems to be just brain dead when it comes to instantiation
//    of function templates, so we will side step this for now.

u_char  median_gamma( u_char *values, unsigned int arraySize ) {

    if (arraySize == 0) {
	ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return u_char(0);
    }
    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]) {
		u_char tmp = values[i];
		values[i] = values[j];
		values[j] = tmp;
	    }
	}
    }

    // Even or odd ?
    if (arraySize % 2) {
	return values[ midpt ];
    } else {
	return (values[midpt-1] + values[midpt]) / 2;
    }
}


int     median_gamma( int *values, unsigned int arraySize ) {

    if (arraySize == 0) {
	ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return int(0);
    }
    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]) {
		int tmp = values[i];
		values[i] = values[j];
		values[j] = tmp;
	    }
	}
    }

    // Even or odd ?
    if (arraySize % 2) {
	return values[ midpt ];
    } else {
	return (values[midpt-1] + values[midpt]) / 2;
    }
}


float   median_gamma( float *values, unsigned int arraySize ) {

    if (arraySize == 0) {
	ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__ );
	return float(0);
    }
    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]) {
		float tmp = values[i];
		values[i] = values[j];
		values[j] = tmp;
	    }
	}
    }

    // Even or odd ?
    if (arraySize % 2) {
	return values[ midpt ];
    } else {
	return (values[midpt-1] + values[midpt]) / 2;
    }
}
a60 1
#endif
@


1.2
log
@Commented out the template verison of median_gamma() and
  provided three specific version, for u_char, int, and float.
@
text
@d16 1
a16 1
#if 0
d59 2
a60 1
#endif
d142 2
@


1.1
log
@Initial revision
@
text
@d16 1
d56 82
@
