median2D.c 335 Bytes
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "fd.h"

float	median2d(float **mat, int ny, int nx){

	signed long	k;
	float		*t, med=0.0;
	
	t = vector(1,nx*ny);
	
	k = nx*ny;
	memmove(&t[1], &mat[1][1], k*sizeof(float));
	quicksort(&t[1],1,k);

	if (k%2)	med = t[k/2+1];
	else		med = (t[k/2] + t[k/2+1]) / 2.0;
	
	free_vector(t,1,nx*ny);
	return med;
}