Find mean value of each input matrix
Statistics
visionstatistics
The 2D Mean block computes the mean of each row or column of the input, along vectors of a specified dimension of the input, or of the entire input. The 2D Mean block can also track the mean value in a sequence of inputs over a period of time. To track the mean value in a sequence of inputs, select the Running mean check box.
Port  Supported Data Types 

Input 

Reset 

ROI  Rectangles and lines:
Binary Mask:

Label 

Label Numbers 

Output 

Flag 

When you do not select the Running mean check
box, the block computes the mean value in each row or column of the
input, along vectors of a specified dimension of the input, or of
the entire input at each individual sample time. Each element in the
output array y
is the mean value of the corresponding
column, row, vector, or entire input. The output array, y
,
depends on the setting of the Find the mean 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 mean value
of the MbyNbyP input
matrix.
y = mean(u(:)) % Equivalent MATLAB code
Each row
— The output
at each sample time consists of an Mby1byP array,
where each element contains the mean value of each vector over the
second dimension of the input. For an input that is an MbyN matrix,
the output at each sample time is an Mby1 column
vector.
y = mean(u,2) % Equivalent MATLAB code
Each column
— The
output at each sample time consists of a 1byNbyP array,
where each element contains the mean 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 = mean(u) % Equivalent MATLAB code
In this mode, the block treats lengthM unoriented vector inputs as Mby1 column vectors.
Specified dimension
—
The output at each sample time depends on the value of the Dimension parameter.
If you set the Dimension to 1
,
the output is the same as when you select Each column
.
If you set the Dimension to 2
,
the output is the same as when you select Each row
.
If you set the Dimension to 3
,
the output at each sample time is an MbyN matrix
containing the mean value of each vector over the third dimension
of the input.
y = mean(u,Dimension) % Equivalent MATLAB code
The mean of a complex input is computed independently for the real and imaginary components, as shown in the following figure.
When you select the Running mean check box, the block tracks the mean value of each channel in a time sequence of inputs. In this mode, the block treats each element as a channel.
The block resets the running mean whenever a reset event is detected at the optional Rst port. The reset sample time must be a positive integer multiple of the input sample time.
When a reset event occurs, the running mean for each channel is initialized to the value in the corresponding channel of the current input.
You specify the reset event by the Reset port parameter:
None
disables the Rst port.
Rising edge
— Triggers
a reset operation when the Rst input does one of the following:
Rises from a negative value to a positive value or zero
Rises from zero to a positive value, where the rise is not a continuation of a rise from a negative value to zero (see the following figure)
Falling edge
— Triggers
a reset operation when the Rst
input does one of
the following:
Falls from a positive value to a negative value or zero
Falls from zero to a negative value, where the fall is not a continuation of a fall from a positive value to zero (see the following figure)
Either edge
— Triggers
a reset operation when the Rst
input is a Rising
edge
or Falling edge
(as
described earlier)
Nonzero sample
—
Triggers a reset operation at each sample time that the Rst
input
is not zero
Note: When running simulations in the Simulink^{®} MultiTasking mode, reset signals have a onesample latency. Therefore, when the block detects a reset event, there is a onesample delay at the reset port rate before the block applies the reset. 
To calculate the statistical value within a particular region
of interest (ROI) of the input, select the Enable ROI processing check
box. This option is only available when the Find the mean
value over parameter is set to Entire input
and
the Running mean check box is not selected. ROI
processing is only supported for 2D inputs.
A binary mask is a binary image that enables you to specify which pixels to highlight, or select.
In a label matrix, pixels equal to 0 represent the
background, pixels equal to 1 represent the first object, pixels equal
to 2 represent the second object, and so on. When the ROI
type parameter is set to Label matrix
,
the Label and Label Numbers ports appear on the block. Use the Label
Numbers port to specify the objects in the label matrix for which
the block calculates statistics. The input to this port must be a
vector of scalar values that correspond to the labeled regions in
the label matrix.
For more information about the format of the input to the ROI port when the ROI is a rectangle or a line, see the Draw Shapes reference page.
For more information about the format of the input to the ROI port when the ROI is a rectangle or a line, see the Draw Shapes block reference page.
Note: For rectangular ROIs, use the ROI portion to process parameter to specify whether to calculate the statistical value for the entire ROI or just the ROI perimeter. 
Use the Output parameter to specify the
block output. The block can output separate statistical values for
each ROI or the statistical value for all specified ROIs. This parameter
is not available if, for the ROI type parameter,
you select Binary mask
.
If, for the ROI type parameter, you select Rectangles
or Lines
,
the Output flag indicating if ROI is within image bounds check
box appears in the dialog box. If you select this check box, the Flag
port appears on the block. The following tables describe the Flag
port output based on the block parameters.
Output = Individual statistics for each ROI
Flag Port Output  Description 

0  ROI is completely outside the input image. 
1  ROI is completely or partially inside the input image. 
Output = Single statistic for all ROIs
Flag Port Output  Description 

0  All ROIs are completely outside the input image. 
1  At least one ROI is completely or partially inside the input image. 
If the ROI is partially outside the image, the block only computes the statistical values for the portion of the ROI that is within the image.
If, for the ROI type parameter, you select Label
matrix
, the Output flag indicating if input
label numbers are valid check box appears in the dialog
box. If you select this check box, the Flag port appears on the block.
The following tables describe the Flag port output based on the block
parameters.
Output = Individual statistics for each ROI
Flag Port Output  Description 

0  Label number is not in the label matrix. 
1  Label number is in the label matrix. 
Output = Single statistic for all ROIs
Flag Port Output  Description 

0  None of the label numbers are in the label matrix. 
1  At least one of the label numbers is in the label matrix. 
The following diagram shows the data types used within the Mean block for fixedpoint signals.
You can set the accumulator and output data types in the block dialog, as discussed in Dialog Box.
The Main pane of the Mean block dialog appears as follows.
Enables running operation when selected.
Specify the reset event that causes the block to reset the running mean. The sample time of the input to the Rst port must be a positive integer multiple of the input sample time. This parameter appears only when you select the Running mean check box. For more information, see Resetting the Running Mean.
Specify whether to find the mean value along rows, columns, entire input, or the dimension specified in the Dimension parameter. For more information, see Basic Operation.
Specify the dimension (onebased value) of the input signal,
over which the mean 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 mean value over parameter
is set to Specified dimension
.
Select this check box to calculate the statistical value within
a particular region of each image. This parameter is only available
when the Find the mean value over parameter is
set to Entire input
, and the block is not
in running mode.
Specify the type of ROI you want to use. Your choices are Rectangles
, Lines
, Label
matrix
, or Binary mask
.
Specify whether you want to calculate the statistical value
for the entire ROI or just the ROI perimeter. This parameter is only
visible if, for the ROI type parameter, you specify Rectangles
.
Specify the block output. The block can output a vector of separate
statistical values for each ROI or a scalar value that represents
the statistical value for all the specified ROIs. This parameter is
not available if, for the ROI type parameter,
you select Binary mask
.
Output flag indicating if ROI is within image bounds
Output flag indicating if label numbers are valid
When you select either of these check boxes, the Flag port appears on the block. For a description of the Flag port output, see the tables in ROI Processing.
The Output flag indicating if ROI is within image
bounds check box is only visible when you select Rectangles
or Lines
as
the ROI type.
The Output flag indicating if label numbers are valid check
box is only visible when you select Label matrix
for
the ROI type parameter.
The Data Types pane of the Mean block dialog appears as follows.
Select the Rounding Modes for fixedpoint operations.
Select the Overflow mode for fixedpoint operations.
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 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 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
2D Maximum  Computer Vision System Toolbox™ 
Computer Vision System Toolbox  
2D Minimum  Computer Vision System Toolbox 
2D Standard Deviation  Computer Vision System Toolbox 
mean  MATLAB 