This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Typedefs | |
| typedef float | pixelvalue |
| Typedef for input data. | |
Functions | |
| void | swap (pixelvalue *, pixelvalue *) |
| Function implementing basic pixel swapping algorithm. | |
| pixelvalue | quick_select (pixelvalue a[], int n) |
| Function implementing quickselect algorithm. | |
| pixelvalue | kth_smallest (pixelvalue *, int, int) |
| Rank-order filter for Wirth's algorithm (requires macro). | |
| pixelvalue | wirth (pixelvalue a[], int n) |
| Function wrapper for kth_smallest to get Wirth's median. | |
| pixelvalue | torben (pixelvalue a[], int n) |
| Function implementing Torben's algorithm. | |
These are various C routines for doing a 1-dimensional median search. QuickSelect and Wirth are the fastest for nominal size input data, but require a copy of the array in memory. Torben is much slower in general, but operates on a read-only data set of arbitrary size.
All the functions take the same input parameters and return the same output. The typedef should be changed as appropriate for the input data.
Definition in file medians_1D.h.
| typedef pixelvalue |
Typedef for input data.
This should be changed according to the data being filtered, e.g., filtering 8-bit gray-scale images would use "int".
Definition at line 105 of file medians_1D.h.
| pixelvalue kth_smallest | ( | pixelvalue * | , | |
| int | , | |||
| int | ||||
| ) |
Rank-order filter for Wirth's algorithm (requires macro).
Function : kth_smallest()
Reference:
Author: Wirth, Niklaus (1976) Algorithms + data structures = programs, Prentice-Hall, Englewood Cliffs, NJ. Original code by Nicolas Devillard - 1998. Public domain. Modified by Stephen Arnold <stephen.arnold@acm.org> August 2005.
| pixelvalue quick_select | ( | pixelvalue | a[], | |
| int | n | |||
| ) |
Function implementing quickselect algorithm.
Function : quick_select()
Definition at line 70 of file medians_1D.c.
References swap().
Referenced by bench().
00070 { 00071 int low, high ; 00072 int median; 00073 int middle, ll, hh; 00074 00075 low = 0 ; high = n-1 ; median = (low + high) / 2; 00076 for (;;) { 00077 if (high <= low) /* One element only */ 00078 return a[median] ; 00079 00080 if (high == low + 1) { /* Two elements only */ 00081 if (a[low] > a[high]) 00082 swap(&a[low], &a[high]) ; 00083 return a[median] ; 00084 } 00085 00086 /* Find median of low, middle and high items; swap into position low */ 00087 middle = (low + high) / 2; 00088 if (a[middle] > a[high]) swap(&a[middle], &a[high]) ; 00089 if (a[low] > a[high]) swap(&a[low], &a[high]) ; 00090 if (a[middle] > a[low]) swap(&a[middle], &a[low]) ; 00091 00092 /* Swap low item (now in position middle) into position (low+1) */ 00093 swap(&a[middle], &a[low+1]) ; 00094 00095 /* Nibble from each end towards middle, swapping items when stuck */ 00096 ll = low + 1; 00097 hh = high; 00098 for (;;) { 00099 do ll++; while (a[low] > a[ll]) ; 00100 do hh--; while (a[hh] > a[low]) ; 00101 00102 if (hh < ll) 00103 break; 00104 00105 swap(&a[ll], &a[hh]) ; 00106 } 00107 00108 /* Swap middle item (in position low) back into correct position */ 00109 swap(&a[low], &a[hh]) ; 00110 00111 /* Re-set active partition */ 00112 if (hh <= median) 00113 low = ll; 00114 if (hh >= median) 00115 high = hh - 1; 00116 } 00117 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void swap | ( | pixelvalue * | a, | |
| pixelvalue * | b | |||
| ) |
Function implementing basic pixel swapping algorithm.
Macro left-over from initial implementation. Need to change to a real function and let the compiler do the work
Definition at line 53 of file medians_1D.c.
Referenced by kth_smallest(), and quick_select().
00053 { 00054 register pixelvalue t; 00055 t=*a; *a=*b; *b=t; 00056 return; 00057 }
Here is the caller graph for this function:

| pixelvalue torben | ( | pixelvalue | m[], | |
| int | n | |||
| ) |
Function implementing Torben's algorithm.
Function : torben()
Definition at line 178 of file medians_1D.c.
Referenced by bench().
00178 { 00179 int i, less, greater, equal, half; 00180 pixelvalue min, max, guess, maxltguess, mingtguess; 00181 00182 half = (n+1)/2 ; 00183 min = max = m[0] ; 00184 for (i=1 ; i<n ; i++) { 00185 if (m[i]<min) min=m[i]; 00186 if (m[i]>max) max=m[i]; 00187 } 00188 00189 while (1) { 00190 guess = (min+max)/2; 00191 less = 0; greater = 0; equal = 0; 00192 maxltguess = min ; 00193 mingtguess = max ; 00194 for (i=0; i<n; i++) { 00195 if (m[i]<guess) { 00196 less++; 00197 if (m[i]>maxltguess) maxltguess = m[i] ; 00198 } else if (m[i]>guess) { 00199 greater++; 00200 if (m[i]<mingtguess) mingtguess = m[i] ; 00201 } else equal++; 00202 } 00203 if (less <= half && greater <= half) break ; 00204 else if (less>greater) max = maxltguess ; 00205 else min = mingtguess; 00206 } 00207 if (less >= half) return maxltguess; 00208 else if (less+equal >= half) return guess; 00209 else return mingtguess; 00210 }
Here is the caller graph for this function:

| pixelvalue wirth | ( | pixelvalue | a[], | |
| int | n | |||
| ) |
Function wrapper for kth_smallest to get Wirth's median.
Function : wirth()
Definition at line 163 of file medians_1D.c.
References kth_smallest().
Referenced by bench().
00163 { 00164 return kth_smallest(a,n,(((n)&1)?((n)/2):(((n)/2)-1))); 00165 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.5.1