2D Median
2D Median values of input array
Libraries:
Computer Vision Toolbox /
Statistics
Description
The 2D Median block computes the median value of an input array. The median value of an array is calculated by using these steps.
The values in the matrix are sorted in numeric order.
To find the median, of an array, A, with a total number of elements, p, where p is:
Odd — Median = A(
ceil
(p / 2))Even — Median = (A (p / 2) + A (( p / 2) + 1)) / 2
Examples
Median based Image Thresholding
Perfom image thresholding with the median value of the image as a global threshold.
Ports
Input
Port_1 — Input array
scalar  vector  matrix  ND array
Specify the Input array as a vector, matrix, or ND array.
Data Types: double
 single
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Complex Number Support: Yes
Output
Port_1 — Output median values
scalar  vector  matrix  ND array
The median values are returned as scalar, vector, matrix, orN array. The size of the output and how median is calculated depends on the setting of the Find the median value over parameter.
For MbyN,the input array, the value of the Find the median value over parameter determines the output form in this manner.
Entire input
—The output is the median value of all the elements of theMbyN input array as a scalarEach row
— The output is a Mby1 column vector, where each element in the vector is the median value of the corresponding row in the input array.Each column
— The output is a 1byN row vector, where each element in the vector is the median value of the corresponding column in the input array.Specified dimension
— If the Dimension parameter is set to1
, the output is the same when you selectEach column
. If the Dimension parameter is set to2
, the output is the same as when you selectEach row
. If the Dimension parameter is set to3
, the output at each sample time is an MbyN matrix containing the median value of each vector over the third dimension of the input
For an ND array, the value of the Find the median value over parameter determines the output form in this manner.
Entire input
— The output is the median value of all elements of the MbyNbyP input array as scalar.Each row
— The output is a Mby1byP array, where each element contains the median value of each row vector in each plane.Each column
— The output dimension is a 1byNbyP array, where each element contains the median value of each column vector for each plane.Specified dimension
— The output depends on Dimension. If Dimension is set to1
, the output is the same as when you selectEach column
. If Dimension is set to2
, the output is the same as when you selectEach row
. If Dimension is set to3
, the output dimension is a MbyN matrix containing the median value of each vector over the third dimension of the input
Data Types: single
 double
 int8
 int16
 int32
 uint8
 uint16
 uint32
 fixed point
Parameters
Main
Sort algorithm — Algorithm to sort input array
Quick sort
(default)  Insertion sort
Specify the algorithm by which to sort the input array.
Quick sort
— This sorting algorithm uses a recursive sort method and is faster at sorting more than 32 elements.Insertion sort
— This sorting algorithm uses a nonrecursive method and is faster at sorting fewer than 32 elements.
When you generate code, to avoid recursive function calls, use the
Insertion sort
algorithm.
Find the median value over — Dimension in which to compute median
Entire input
(default)  Each row
 Each column
 Specified dimension
Specify the dimension of the input in which the block computes the median.
Entire input
— Computes the median over the entire input. The output value is scalarEach row
— Computes the median over each row of the input. The output is column vectorEach column
— Computes the median over each column of the input. The output is row vectorSpecified dimension
— Computes the median over the dimension of the input specified in the Dimension parameter.If Dimension is
1
, the output is the same as when you selectEach column
If Dimension is
2
, the output is the same as when you selectEach row
Dimension — Custom dimension
1
(default)  positive scalar
Specify the dimension (onebased value) of the input array, over which the block computes the median. The value of this parameter must not exceed the number of dimensions in the input array.
Dependencies
To enable this parameter, set the Find the median value over
parameter to Specified dimension
.
Data Types Tab
For details on the fixedpoint block parameters, see Specify FixedPoint Attributes for Blocks (DSP System Toolbox).
Lock data type settings against change by the fixedpoint tools — Option to prevent fixedpoint tools from overriding data types
off
(default)  on
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify in this block. For more information, see Lock the Output Data Type Setting (FixedPoint Designer).
Note
Floatingpoint inheritance takes precedence over the data type settings defined on this pane. When inputs are floating point, the block ignores these settings, and all internal data types are floating point.
Block Characteristics
Data Types 

Multidimensional Signals 

VariableSize Signals 

Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Generated code relies on memcpy
or memset
functions (string.h) under certain conditions.
Version History
Introduced before R2006a
See Also
Blocks
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)