IMG_median_3x3_16


Detailed Description


Functions

void IMG_median_3x3_16 (const unsigned short *restrict i_data, int n, unsigned short *restrict o_data)


Function Documentation

void IMG_median_3x3_16 ( const unsigned short *restrict  i_data,
int  n,
unsigned short *restrict  o_data 
)

Description:
This kernel performs a 3x3 median filter operation on 16-bit unsigned image pixels. The grey level at each pixel is replaced by the median of nine adjacent values. The median of a set of nine numbers is the middle element so that half of the elements in the list are larger and half are smaller. Median filters remove the effects of extreme values from data, such as salt and pepper noise.
The input image contains 3 adjacent rows from an actual image. The output array will be a single row of the median values of the masked input. For the first two outputs, the two columns outside the image are assumed to be all zeros.
The first 2 values in the output array will not contain any meaningful data. The 3rd value in the output array will be the median of 2nd value in the middle row of input array and so on. The nth value in the output array will be the median of the (n-1)th value in the mid row of input array. Hence the output array will not contain the median values of the first and last elements in the middle row of input image. Instead it will contain two meaningless values at the beginning of the array.
Parameters:
i_data Input image containing 3 rows (i.e., size of 3 x n)
n Width of input image in pixels
o_data Output image containing 1 row (i.e., size of 1 x n)
Algorithm:
This implementation uses an incremental sorting technique to greatly reduce the number of compares and exchanges necessary to sort the image pixels.
The main loop reads three new pixels from the input image each iteration. These three pixels form the right edge of the filter mask. The filter data from the previous iteration is "slid over" by one pixel to form the complete 3x3 mask.
Each 3-pixel "column" is sorted as it is read in from the image, resulting in a "lo", "medium" and "hi" pixel value for the column. This results in a 3x3 filter mask with sorted columns or three rows -- a row of "minimums", a row of "middle values", and a row of "maximums".
The median filter operates from this partially ordered mask. It finds the smallest element in the row of "maximums", the middle element in the row of "middle values", and the largest element in the row of "minimums". The median value of these three values is the median for the entire 3x3 mask.
This process minimizes compares, as the whole mask does not need to be sorted between iterations. Rather, the partial ordering for two of the three columns from one iteration is used directly for the next iteration.
The natural C implementation has no restrictions. The optimized intrinsic C code has restrictions as noted in Assumptions below.
Assumptions:
  • The input array and output array should not overlap
  • The minimum value for width of input image 'n' is 4
  • The width of input image 'n' must be a multiple of 4
Implementation Notes:
  • This code is fully interruptible
  • This code is compatible with C66x processors
  • No bank conflicts occur
Benchmarks:
See IMGLIB_Test_Report.html for cycle and memory information.


Copyright 2012, Texas Instruments Incorporated