This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm.
I need it to find the median value of a set of 3x3x3 voxel values. Since the volume is made of a billion voxels and the algorithm is recursive, it better be a little bit fast.
In general it can be expected that values are relatively close.
The fastest known algorithm I have tried out so far uses the quick sort partition function. I would like to know if there is a faster one.
I’ve “invented” a 20% faster one using two heaps, but expected an even faster one using a hash. Before implementing this, I’d like to know if a blitz fast solution already exist out there.
The fact that I’m using floats shouldn’t matter since they can be considered as unsigned integer after inverting the sign bit. The order will be preserved.
EDIT: benchmark and source code moved into a separate answer as suggested by
Davy Landman. See below for the answer by chmike.
EDIT: The most efficient algorithm so far was referenced below by Boojum as a link to the Fast Median and Bilateral Filtering paper which is now the answer to this question. The first smart idea of this method is to use radix sort, the second is to combine median search of adjacent pixels who share a lot of pixels.
Since it sounds like you’re performing a median filter on a large array of volume data, you might want to take a look at the Fast Median and Bilateral Filtering paper from SIGGRAPH 2006. That paper deals with 2D image processing, but you might be able to adapt the algorithm for 3D volumes. If nothing else, it might give you some ideas on how to step back and look at the problem from a slightly different perspective.