Documentation 
Find 2D Median value of each input matrix
The 2D Median block computes the median value of each row or column of the input, along vectors of a specified dimension of the input, or of the entire input. The median of a set of input values is calculated as follows:
The values are sorted.
If the number of values is odd, the median is the middle value.
If the number of values is even, the median is the average of the two middle values.
For a given input u, the size of the output array y depends on the setting of the Find the median value over parameter. For example, consider a 3dimensional input signal of size MbyNbyP:
Entire input — The output at each sample time is a scalar that contains the median value of the MbyNbyP input matrix.
y = median(u(:)) % Equivalent MATLAB code
Each row — The output at each sample time consists of an Mby1byP array, where each element contains the median value of each vector over the second dimension of the input. For an input that is an MbyN matrix, the output is an Mby1 column vector.
y = median(u,2) % Equivalent MATLAB code
Each column — The output at each sample time consists of a 1byNbyP array, where each element contains the median value of each vector over the first dimension of the input. For an input that is an MbyN matrix, the output at each sample time is a 1byN row vector.
y = median(u) % Equivalent MATLAB code
For convenience, lengthM 1D vector inputs are treated as Mby1 column vectors when the block is in this mode. Samplebased lengthM row vector inputs are also treated as Mby1 column vectors.
Specified dimension — The output at each sample time depends on Dimension. If Dimension is set to 1, the output is the same as when you select Each column. If Dimension is set to 2, the output is the same as when you select Each row. If Dimension is set to 3, the output at each sample time is an MbyN matrix containing the median value of each vector over the third dimension of the input.
y = median(u,Dimension) % Equivalent MATLAB code
The block sorts complex inputs according to their magnitude.
For fixedpoint inputs, you can specify accumulator, product output, and output data types as discussed in Dialog Box. Not all these fixedpoint parameters are applicable for all types of fixedpoint inputs. The following table shows when each kind of data type and scaling is used.
Output data type  Accumulator data type  Product output data type  

X  X  
X 
 
X  X  X  
X  X  X 
The accumulator and output data types and scalings are used for fixedpoint signals when M is even. The result of the sum performed while calculating the average of the two central rows of the input matrix is stored in the accumulator data type and scaling. The total result of the average is then put into the output data type and scaling.
The accumulator and product output parameters are used for complex fixedpoint inputs. The sum of the squares of the real and imaginary parts of such an input are formed before the input elements are sorted, as described in Description. The results of the squares of the real and imaginary parts are placed into the product output data type and scaling. The result of the sum of the squares is placed into the accumulator data type and scaling.
For fixedpoint inputs that are both complex and have even M, the data types are used in all of the ways described. Therefore, in such cases, the accumulator type is used in two different ways.
The Main pane of the 2–D Median block dialog appears as follows.
Specify whether to sort the elements of the input using a Quick sort or an Insertion sort algorithm.
Specify whether to find the median value along rows, columns, entire input, or the dimension specified in the Dimension parameter. For more information, see Description.
Specify the dimension (onebased value) of the input signal, over which the median is computed. The value of this parameter cannot exceed the number of dimensions in the input signal. This parameter is only visible when the Find the median value over parameter is set to Specified dimension.
The Data Types pane of the 2D Median block dialog appears as follows.
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. 
Select the Rounding mode for fixedpoint operations.
Select the Overflow mode for fixedpoint operations.
Specify the product output data type. See FixedPoint Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as input
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Product output data type parameter.
See Specify Data Types Using Data Type Assistant for more information.
Specify the accumulator data type. See FixedPoint Data Types for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:
A rule that inherits a data type, for example, Inherit: Same as product output
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Accumulator data type parameter.
See Specify Data Types Using Data Type Assistant for more information.
Specify the output data type. See FixedPoint Data Types for illustrations depicting the use of the output data type in this block. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as accumulator
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output data type parameter.
See Specify Data Types Using Data Type Assistant for more information.
Specify the minimum value that the block should output. The default value, [], is equivalent to Inf. Simulink^{®} software uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixedpoint data types
Specify the maximum value that the block should output. The default value, [], is equivalent to Inf. Simulink software uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixedpoint data types
Port  Supported Data Types 

Input 

Output 

The ex_vision_2dmedianex_vision_2dmedian calculates the median value over the entire input.
2D Maximum  Computer Vision System Toolbox™ 
2D Mean  Computer Vision System Toolbox 
2D Minimum  Computer Vision System Toolbox 
2D Standard Deviation  Computer Vision System Toolbox 
2D Variance  Computer Vision System Toolbox 
median  MATLAB 