CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

Graphics

Order Statistic Filter Class

Freely available under GPL terms only
get a GPL licence
viewed 45 times and licensed 10 times

This class implements order-statistic image processing filters.

Controller: stevehs17  Contact Controller
+View other versions (3)
Contents hide toc
get GPL

Interface

#include <codecogs/graphics/order statistic filter class.h>

class Filt
This class implements order-statistic image processing filters.
float*alpha
float*max
float*median
float*midpoint
float*min
staticintDIM[const]
structwindat
typedef floatselfunc
float*filt
static floatalphaval
static floatmaxval
static floatmedval
static floatmidval
static floatminval
static intfcmp
float*fillborder
float* Filt::alpha (float out[], const float in[], int nx, int ny, int trim)
Apply an alpha-trimmed mean filter to an image.
float* Filt::max (float out[], const float in[], int nx, int ny)
Apply a max filter to an image.
float* Filt::median (float out[], const float in[], int nx, int ny)
Apply a median filter to an image.
float* Filt::midpoint (float out[], const float in[], int nx, int ny)
Apply a midpoint filter to an image.
float* Filt::min (float out[], const float in[], int nx, int ny)
Apply a min filter to an image.
float Filt::alphaval (windat *w)
Find the mean of the pixel values in the window ignoring trim/2 lowest and highest.
float Filt::minval (windat *w)
Find the minimum value of the pixels in the current window.
float Filt::maxval (windat *w)
Find the maximum value of the pixels in the window.
float Filt::medval (windat *w)
Find the median value of the pixels in the window.
float Filt::midval (windat *w)
Find the midpoint of the pixels in the current filter window (i.e. the mean of the lowest and highest values).
float* Filt::filt (float out[], const float in[], int nx, int ny, selfunc pf, int trim)
Apply a filter to an image.
float* Filt::fillborder (float img[], int nx, int ny)
Assign to each pixel on the border of an image the value of the closest interior pixel.
int Filt::fcmp (const void *p1, const void *p2)
Compare two floating point numbers.

Class Documentation

 
Filt
Order-statistic filters are used for eliminating or reducing noise in images. Like other spatial filters, these filters assign to each pixel in an image a value based on the values of the pixels in the neighborhood or window surrounding (and including) the pixel. What characterizes order-statistic filters is that the replacement value is based on an ordering or ranking, from smallest to largest, of the values of the pixels in the window. The max filter assigns to each pixel the maximum value of the pixels in the window, the min filter the minimum value, the median filter the median value, and the midpoint filter the mean of the minimum and maximum values. The alpha-trimmed mean filter ignores the lowest and highest values of the pixels in the window, and finds the mean of the remaining values; the number of values ignored is determined by the trim value, with the trim/2 lowest and highest values ignored. In the limiting case of trim = 0, the filter becomes an averaging (mean) filter. In the other limiting case of M*N - 1, where M is the length of the window and N is the width of the window, the filter becomes a median filter.(Note that in this implementation the trim/2 value is truncated as an integer.)

Different order-statistic filters are suited for removing or reducing different kinds of noise. The median filter removes impulse or salt-and-pepper noise -- that is, small, scattered areas of low- and high-value pixels -- while preserving the edges of objects in the image. The min filter enhances areas of images with low-value pixels and removes salt noise. The max filter enhances areas of images with high-value pixels and removes pepper noise. The mid-point filter reduces noise that takes on a range of values, such as noise with a Gaussian or uniform distribution of values. The alpha-trimmed mean filter is useful where there are different kinds of noise, such as a combination of impulse and Gaussian noise.

The actual filtering of the image occurs in filt(). The selfunc parameter is the function that selects the values to be assigned to each pixel in the image by operating on the values of the pixels in the window after the values have been ordered. The particular function passed as an argument to filt() depends on the filter being applied. This is reflected in the naming scheme, with maxval() passed for the max filter, minval() passed for the min filter, and so on.

There are various ways to deal with the pixels on the border. In this implementation, the pixels are assigned the value of the nearest interior pixel. This is done in fillborder().

The selection functions (i.e. the *val() functions) are static so they can be passed as arguments to filt() with a much simpler syntax than if they were not static. fcmp() must be static so it can be passed as an argument to the qsort() function.
Authors:
Steve Simon (April 2009)
Source Code:

To view or download source code you need a GP Licence.

get GPL

Not a member, then Register with CodeCogs. Already a Member, then Login.


 
float*Filt::alphafloat*out
const float*in
intnx
intny
inttrim )
This function replaces the pixels in an image with the mean of the values of the pixels in the filter window after removing the lowest and highest values; how many values to remove is specified by the user. Alpha-trimmed mean filters are useful for reducing the noise in an image where the noise is of different types, such as a combination of impulse and Gaussian noise.
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber of rows
trimignore trim/2 lowest and highest values when finding mean of pixel values in filter window
Returns:
pointer to output image
Authors:
Steve Simon (April 2009)
References:
  1. Gonzalez, R. and Woods, R. "Digital Image Processing," 3rd ed., pp. 156-157 and 325-330.

 
float*Filt::maxfloat*out
const float*in
intnx
intny )
This function replaces the pixels in an image with the maximum value of the pixels in the filter window. Max filters enhance the parts of an image with high-value pixels and eliminate low-value impulse (or pepper) noise.
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber of rows
Returns:
pointer to output image
Authors:
Steve Simon (April 2009)

 
float*Filt::medianfloat*out
const float*in
intnx
intny )
This function replaces the pixels in an image with the median value of the pixels in the filter window. Median filters are useful for eliminating impulse, or salt-and-pepper, noise.
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber of rows
Returns:
pointer to output image
Authors:
Steve Simon (April 2009)

 
float*Filt::midpointfloat*out
const float*in
intnx
intny )
This function replaces the pixels in an image with the midpoint of the pixels in the filter window -- that is, the mean of the lowest and highest values. Midpoint filters reduce noise in an image where the noise takes on a range of values, such as noise with a Gaussian or uniform distribution of values.
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber of rows
Returns:
pointer to output image
Authors:
Steve Simon (April 2009)

 
float*Filt::minfloat*out
const float*in
intnx
intny )
This function replaces the pixels in an image with the minimum value of the pixels in the filter window. Min filters enhance the parts of an image with low-value pixels and eliminate high-value impulse (or salt) noise.
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber of rows
Returns:
pointer to output image
Authors:
Steve Simon (April 2009)

 
floatFilt::alphavalwindat*w )
Parameters:
wStructure containing information about current filtering window.
Returns:
The mean value of the pixels in the window ignoring the trim/2 lowest and highest.
Authors:
Steve Simon (April 2009)

 
floatFilt::minvalwindat*w )
Parameters:
wInformation about the current filter window.
Returns:
The minimum value of the pixels in the window.
Authors:
Steve Simon (April 2009)

 
floatFilt::maxvalwindat*w )
Parameters:
wInformation about the current filter window.
Returns:
The maximum value of the pixels in the window.
Authors:
Steve Simon (April 2009)

 
floatFilt::medvalwindat*w )
Parameters:
wInformation about the current filter window.
Returns:
The median value of the pixels in the window.
Authors:
Steve Simon (April 2009)

 
floatFilt::midvalwindat*w )
Parameters:
wInformation about the current filter window.
Returns:
The midpoint of the values of the pixels in the window.
Authors:
Steve Simon (April 2009)

 
float*Filt::filtfloat*out
const float*in
intnx
intny
selfuncpf
inttrim )
This function assigns a value to each pixel in an image. The value assigned is based on the values of the pixels in a neighborhood or window surrounding, and including, the pixel. (Note that the pixels on the border of the image are a special case; see below.) The length of the sides of the filter window is given by the constant DIM.

To assign a value to a pixel, the values of the pixels in the window are first sorted. Then a function, the selfunc parameter, is applied to the array of sorted values to select the value to assign. How the value is selected -- that is, how the selection function operates on the array of sorted values -- depends on the type of filter being applied. Thus different filters can be applied by passing different functions as an argument. After all the interior pixels have been assigned a value, the pixels on the border are assigned values by calling the function fillborder().
Parameters:
outoutput image
ininput image
nxnumber of columns
nynumber or rows
pfpointer to a function for selecting a value in the filter window
trimspecifies which pixel values to ignore (ignore the trim/2 lowest and highest)
Returns:
output image
Authors:
Steve Simon (April 2009)

 
float*Filt::fillborderfloat*img
intnx
intny )
Parameters:
imgimage to operate on
nxnumber of columns of image
nynumber of rows of image
Returns:
image operated on
Authors:
Steve Simon (April 2009)

 
intFilt::fcmpconst void*p1
const void*p2 )
Parameters:
p1first floating point number to compare
p2second floating point number to compare
Returns:
result of comparison (-1 if p1 < p2, 0 if p1 == p2, 1 otherwise)
Authors:
Steve Simon (April 2009)
References:
  1. Kernighan, B. and Pike, R. "The Practice of Programming." Section 2.3.

Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 28 Apr 09 @ 00:46     Page Rendered: 2010-03-11 19:02:54

Valid CSS!   Valid XHTML 1.0 Transitional