Computer Vision System Toolbox™ Reference PDF
Computer Vision System Toolbox™ Reference PDF
Reference
R2014a
How to Contact MathWorks
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
April 2011 Online only Revised for Version 4.0 (Release 2011a)
September 2011 Online only Revised for Version 4.1 (Release 2011b)
March 2012 Online only Revised for Version 5.0 (Release 2012a)
September 2012 Online only Revised for Version 5.1 (Release R2012b)
March 2013 Online only Revised for Version 5.2 (Release R2013a)
September 2013 Online only Revised for Version 5.3 (Release R2013b)
March 2014 Online only Revised for Version 6.0 (Release R2014a)
Contents
Alphabetical List
2
Functions Alphabetical
3
v
vi Contents
1
Library Statistics
visionstatistics
( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( A(m + i, n + j))
m =0 n =0
Complex
Port Input/Output Supported Data Types Values
Supported
Input Vector or matrix of • Double-precision floating point Yes
intensity values or a
• Single-precision floating point
scalar, vector, or matrix
that represents one plane • Fixed point
of the RGB video stream
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Output Autocorrelation of the Same as Input port Yes
input matrix
If the data type of the input is floating point, the output of the block has
the same data type.
1-2
2-D Autocorrelation
You can set the product output, accumulator, and output data types in
the block mask as discussed in “Dialog Box” on page 1-4.
The output of the multiplier is in the product output data type if at
least one of the inputs to the multiplier is real. If both of the inputs
to the multiplier are complex, the result of the multiplication is in
the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”.
1-3
2-D Autocorrelation
Dialog The Main pane of the 2-D Autocorrelation dialog box appears as shown
Box in the following figure.
The Data Types pane of the 2-D Autocorrelation dialog box appears
as shown in the following figure.
1-4
2-D Autocorrelation
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
1-5
2-D Autocorrelation
Product output
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-3 and “Multiplication Data Types” for
illustrations depicting the use of the product output data type
in this block:
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox™
software is 0.
Accumulator
Use this parameter to specify how to designate the accumulator
word and fraction lengths. Refer to “Fixed-Point Data Types”
on page 1-3 and “Multiplication Data Types” for illustrations
depicting the use of the accumulator data type in this block.
The accumulator data type is only used when both inputs to the
multiplier are complex.
• When you select Same as product output, these
characteristics match those of the product output.
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the accumulator, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the accumulator. The bias
of all signals in the Computer Vision System Toolbox software
is 0.
1-6
2-D Autocorrelation
Output
Choose how to specify the output word length and fraction length.
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. The bias of all
signals in the Computer Vision System Toolbox software is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink® documentation.
1-7
2-D Convolution
Library Filtering
visionfilter
Description
( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) * B(i − m, j − n)
m =0 n =0
Complex
Port Input/Output Supported Data Types Values
Supported
I1 Matrix of intensity • Double-precision floating point Yes
values or a matrix that
• Single-precision floating point
represents one plane of
the RGB video stream • Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
I2 Matrix of intensity Same as I1 port Yes
values or a matrix that
1-8
2-D Convolution
Complex
Port Input/Output Supported Data Types Values
Supported
If the data type of the input is floating point, the output of the block has
the same data type.
The dimensions of the output are dictated by the Output size
parameter. Assume that the input at port I1 has dimensions (Ma, Na)
and the input at port I2 has dimensions (Mb, Nb). If, for the Output
size parameter, you choose Full, the output is the full two-dimensional
convolution with dimensions (Ma+Mb-1, Na+Nb-1). If, for the Output
size parameter, you choose Same as input port I1, the output is the
central part of the convolution with the same dimensions as the input at
port I1. If, for the Output size parameter, you choose Valid, the output
is only those parts of the convolution that are computed without the
zero-padded edges of any input. This output has dimensions (Ma-Mb+1,
Na-Nb+1). However, if all(size(I1)<size(I2)), the block errors out.
If you select the Output normalized convolution
check box, the block’s output is divided by
sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))), where I1p is the
portion of the I1 matrix that aligns with the I2 matrix. See “Example 2”
on page 1-12 for more information.
1-9
2-D Convolution
You can set the product output, accumulator, and output data types in
the block mask as discussed in “Dialog Box” on page 1-15.
The output of the multiplier is in the product output data type if at
least one of the inputs to the multiplier is real. If both of the inputs
to the multiplier are complex, the result of the multiplication is in
the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”.
Examples Example 1
Suppose I1, the first input matrix, has dimensions (4,3) and I2, the
second input matrix, has dimensions (2,2). If, for the Output size
parameter, you choose Full, the block uses the following equations to
determine the number of rows and columns of the output matrix:
1-10
2-D Convolution
If, for the Output size parameter, you choose Same as input port
I1, the output is the central part of Cfull with the same dimensions as
the input at port I1, (4,3). However, since a 4-by-3 matrix cannot be
extracted from the exact center of Cfull , the block leaves more rows and
columns on the top and left side of the Cfull matrix and outputs:
If, for the Output size parameter, you choose Valid, the block uses the
following equations to determine the number of rows and columns of
the output matrix:
1-11
2-D Convolution
Example 2
In convolution, the value of an output element is computed as a
weighted sum of neighboring elements.
For example, suppose the first input matrix represents an image and
is defined as
I1 = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
I2 = [8 1 6
3 5 7
4 9 2]
The following figure shows how to compute the (1,1) output element
(zero-based indexing) using these steps:
1-12
2-D Convolution
1 Rotate the second input matrix, I2, 180 degrees about its center
element.
2 Slide the center element of I2 so that it lies on top of the (0,0) element
of I1.
1-13
2-D Convolution
2 9 4
7 5 3
Alignment of center
element of I2
6 1 8
17 24 1 8 15
4 6 13 20 22
Alignment of I2 matrix
10 12 19 21 3
11 18 25 2 9
1-14
2-D Convolution
Dialog The Main pane of the 2-D Convolution dialog box appears as shown in
Box the following figure.
1-15
2-D Convolution
Output size
This parameter controls the size of the output scalar, vector, or
matrix produced as a result of the convolution between the two
inputs. If you choose Full, the output has dimensions (Ma+Mb-1,
Na+Nb-1). If you choose Same as input port I1, the output has
the same dimensions as the input at port I1. If you choose Valid,
output has dimensions (Ma-Mb+1, Na-Nb+1).
Output normalized convolution
If you select this check box, the block’s output is normalized.
The Data Types pane of the 2-D Convolution dialog box appears as
shown in the following figure.
1-16
2-D Convolution
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
1-17
2-D Convolution
Product output
Use this parameter to specify how to designate the product output
word and fraction lengths. Refer to “Fixed-Point Data Types”
on page 1-9 and “Multiplication Data Types” for illustrations
depicting the use of the product output data type in this block:
• When you select Same as first input, these characteristics
match those of the first input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter
the word length, in bits, and the slope of the product output.
The bias of all signals in theComputer Vision System Toolbox
software is 0.
Accumulator
Use this parameter to specify how to designate the accumulator
word and fraction lengths. Refer to “Fixed-Point Data Types”
on page 1-9 and “Multiplication Data Types” for illustrations
depicting the use of the accumulator data type in this block.
The accumulator data type is only used when both inputs to the
multiplier are complex:
1-18
2-D Convolution
1-19
2-D Correlation
Library Statistics
visionstatistics
1-20
2-D Correlation
Description
1-21
( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( B(m + i, n + j))
m =0 n =0
Complex
Port Input/Output Supported Data Types Values
Supported
I1 Vector or matrix of • Double-precision floating point Yes
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
I2 Scalar, vector, or matrix Same as I1 port Yes
of intensity values or a
scalar, vector, or matrix
that represents one plane
of the RGB video stream
Output Convolution of the input Same as I1 port Yes
matrices
If the data type of the input is floating point, the output of the block is
the same data type.
The dimensions of the output are dictated by the Output size
parameter and the sizes of the inputs at ports I1 and I2. For example,
assume that the input at port I1 has dimensions (Ma, Na) and the input
at port I2 has dimensions (Mb, Nb). If, for the Output size parameter,
you choose Full, the output is the full two-dimensional cross-correlation
with dimensions (Ma+Mb-1, Na+Nb-1). If, for the Output size
parameter, you choose Same as input port I1, the output is the
central part of the cross-correlation with the same dimensions as the
input at port I1. If, for the Output size parameter, you choose Valid,
1-22
2-D Correlation
the output is only those parts of the cross-correlation that are computed
without the zero-padded edges of any input. This output has dimensions
(Ma-Mb+1, Na-Nb+1). However, if all(size(I1)<size(I2)), the block
errors out.
If you select the Normalized output check box, the block’s output
is divided by sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))), where
I1p is the portion of the I1 matrix that aligns with the I2 matrix. See
“Example 2” on page 1-26 for more information.
Note When you select the Normalized output check box, the block
input cannot be fixed point.
You can set the product output, accumulator, and output data types in
the block mask as discussed in “Dialog Box” on page 1-29.
The output of the multiplier is in the product output data type if at
least one of the inputs to the multiplier is real. If both of the inputs
to the multiplier are complex, the result of the multiplication is in
the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”.
1-23
2-D Correlation
Examples Example 1
Suppose I1, the first input matrix, has dimensions (4,3). I2, the second
input matrix, has dimensions (2,2). If, for the Output size parameter,
you choose Full, the block uses the following equations to determine
the number of rows and columns of the output matrix:
If, for the Output size parameter, you choose Same as input port
I1, the output is the central part of Cfull with the same dimensions as
the input at port I1, (4,3). However, since a 4-by-3 matrix cannot be
extracted from the exact center of Cfull , the block leaves more rows and
columns on the top and left side of the Cfull matrix and outputs:
1-24
2-D Correlation
If, for the Output size parameter, you choose Valid, the block uses the
following equations to determine the number of rows and columns of
the output matrix:
1-25
2-D Correlation
Example 2
In cross-correlation, the value of an output element is computed as a
weighted sum of neighboring elements.
For example, suppose the first input matrix represents an image and
is defined as
I1 = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9]
I2 = [8 1 6
3 5 7
4 9 2]
The following figure shows how to compute the (2,4) output element
(zero-based indexing) using these steps:
1 Slide the center element of I2 so that lies on top of the (1,3) element
of I1.
1-26
2-D Correlation
Values of I2 matrix
8 1 6
3 5 7
Alignment of I2 matrix
4 9 2
17 24 1 8 15
4 6 13 20 22
Alignment of center
10 12 19 21 3 element of I2
11 18 25 2 9
1-27
2-D Correlation
1-28
2-D Correlation
Dialog The Main pane of the 2-D Correlation dialog box appears as shown in
Box the following figure.
1-29
2-D Correlation
Output size
This parameter controls the size of the output scalar, vector, or
matrix produced as a result of the cross-correlation between
the two inputs. If you choose Full, the output has dimensions
(Ma+Mb-1, Na+Nb-1). If you choose Same as input port I1, the
output has the same dimensions as the input at port I1. If you
choose Valid, output has dimensions (Ma-Mb+1, Na-Nb+1).
Normalized output
If you select this check box, the block’s output is normalized.
The Data Types pane of the 2-D Correlation dialog box appears as
shown in the following figure.
1-30
2-D Correlation
1-31
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
2-D Correlation
Overflow mode
Select the Overflow mode for fixed-point operations.
Product output
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-23 and “Multiplication Data Types” for
illustrations depicting the use of the product output data type
in this block:
• When you select Same as first input, these characteristics
match those of the first input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
software is 0.
Accumulator
Use this parameter to specify how to designate the accumulator
word and fraction lengths. Refer to “Fixed-Point Data Types”
on page 1-23 and“Multiplication Data Types” for illustrations
1-32
2-D Correlation
1-33
2-D Correlation
1-34
2-D DCT
Library Transforms
visiontransforms
Description The 2-D DCT block calculates the two-dimensional discrete cosine
transform of the input signal. The equation for the two-dimensional
DCT is
M −1 N −1
2 (2 x + 1)mπ (2 y + 1)nπ
F (m, n) =
MN
C(m)C(n) ∑ ∑ f ( x, y) cos
2M
cos
2N
x =0 y =0
Complex
Port Input/Output Supported Data Types Values
Supported
Input Vector or matrix of • Double-precision floating point No
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
If the data type of the input signal is floating point, the output of the
block is the same data type.
1-35
2-D DCT
Use the Sine and cosine computation parameter to specify how the
block computes the sine and cosine terms in the DCT algorithm. If
you select Trigonometric fcn, the block computes the sine and cosine
values during the simulation. If you select Table lookup, the block
computes and stores the trigonometric values before the simulation
starts. In this case, the block requires extra memory.
1-36
2-D DCT
1-37
2-D DCT
The output of the multiplier is in the product output data type when
at least one of the inputs to the multiplier is real. When both inputs
to the multiplier are complex, the result of the multiplication is in
the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”. You can set the sine
table, product output, accumulator, and output data types in the block
mask as discussed in the next section.
Dialog The Main pane of the 2-D DCT dialog box appears as shown in the
Box following figure.
1-38
2-D DCT
The Data Types pane of the 2-D DCT dialog box appears as shown in
the following figure.
Rounding mode
Select the “Rounding Modes” for fixed-point operations. The sine
table values do not obey this parameter; they always round to
Nearest.
Overflow mode
Select the Overflow mode for fixed-point operations. The sine
table values do not obey this parameter; instead, they are always
saturated.
1-39
2-D DCT
The sine table values do not obey the Rounding mode and
Overflow mode parameters; instead, they are always saturated
and rounded to Nearest.
Product output data type
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-36 and “Multiplication Data Types” for
illustrations depicting the use of the product output data type in
this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-36 for illustrations depicting the use of the accumulator
data type in this block. You can set this parameter to:
1-40
2-D DCT
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on
page 1-36 for illustrations depicting the use of the output data
type in this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule.
When you select Inherit: Inherit via internal rule, the
block calculates the output word length and fraction length
automatically. The internal rule first calculates an ideal output
word length and fraction length using the following equations:
Using these ideal results, the internal rule then selects word
lengths and fraction lengths that are appropriate for your
hardware. For more information, see “Inherit via Internal
Rule”.
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
1-41
2-D DCT
See “Specify Data Types Using Data Type Assistant” for more
information.
Lock scaling against changes by the autoscaling tool
Select this parameter to prevent any fixed-point scaling you
specify in this block mask from being overridden by the
autoscaling tool in the Fixed-Point Tool. For more information,
see fxptdlg, a reference page on the Fixed-Point Tool in the
Simulink documentation.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
References [1] Chen, W.H, C.H. Smith, and S.C. Fralick, “A fast computational
algorithm for the discrete cosine transform,” IEEE Trans. Commun.,
vol. COM-25, pp. 1004-1009. 1977.
[2] Wang, Z. “Fast algorithms for the discrete W transform and for
the discrete Fourier transform,” IEEE Trans. Acoust., Speech, Signal
Processing, vol. ASSP-32, pp. 803-816, Aug. 1984.
1-42
2-D FFT
Library Transforms
visiontransforms
Description The 2-D FFT block computes the fast Fourier transform (FFT). The
block does the computation of a two-dimensional M-by-N input matrix
in two steps. First it computes the one-dimensional FFT along one
dimension (row or column). Then it computes the FFT of the output of
the first step along the other dimension (column or row).
The output of the 2-D FFT block is equivalent to the MATLAB® fft2
function:
M −1 N −1 2πmx 2πny
−j −j
F (m, n) = ∑ ∑ f ( x, y) e M e N
x =0 y =0
where 0 ≤ m ≤ M − 1 and 0 ≤ n ≤ N − 1 .
1-43
2-D FFT
The output of this block has the same dimensions as the input. If
the input signal has a floating-point data type, the data type of the
output signal uses the same floating-point data type. Otherwise, the
output can be any fixed-point data type. The block computes scaled
and unscaled versions of the FFT.
The input to this block can be floating-point or fixed-point, real or
complex, and conjugate symmetric. The block uses one of two possible
FFT implementations. You can select an implementation based on the
FFTW library [1], [2], or an implementation based on a collection of
Radix-2 algorithms. You can select Auto to allow the block to choose
the implementation.
Port Description
Complex
Port Description Supported Data Types Values
Supported
Input Vector or matrix of • Double-precision Yes
intensity values floating point
• Single-precision
floating point
• Fixed point
• 8-, 16-, 32-bit signed
integer
• 8-, 16-, 32-bit unsigned
integer
FFTW Implementation
The FFTW implementation provides an optimized FFT calculation
including support for power-of-two and non-power-of-two transform
1-44
2-D FFT
Radix-2 Implementation
The Radix-2 implementation supports bit-reversed processing, fixed or
floating-point data, and allows the block to provide portable C-code
generation using the “Simulink Coder™”. The dimensions of the input
matrix, M and N, must be powers of two. To work with other input
sizes, use the Image Pad block to pad or truncate these dimensions to
powers of two, or if possible choose the FFTW implementation.
With Radix-2 selected, the block implements one or more of the
following algorithms:
• Butterfly operation
• Double-signal algorithm
• Half-length algorithm
• Radix-2 decimation-in-time (DIT) algorithm
• Radix-2 decimation-in-frequency (DIF) algorithm
Radix-2 DIF
1-45
2-D FFT
Radix-2 DIF
2πk
j
e K
1-46
2-D FFT
1-47
2-D FFT
1-48
2-D FFT
Dialog The Main pane of the 2-D FFT dialog box appears as shown in the
Box following figure.
1-49
2-D FFT
FFT implementation
Set this parameter to FFTW [1], [2] to support an arbitrary length
input signal. The block restricts generated code with FFTW
implementation to host computers capable of running MATLAB.
Set this parameter to Auto to let the block choose the FFT
implementation. For non-power-of-two transform lengths, the
block restricts generated code to MATLAB host computers.
Output in bit-reversed order
Designate the order of the output channel elements relative to
the ordering of the input elements. When you select this check
box, the output channel elements appear in bit-reversed order
relative to the input ordering. If you clear this check box, the
output channel elements appear in linear order relative to the
input ordering.
The Data Types pane of the 2-D FFT dialog box appears as shown in
the following figure.
1-50
2-D FFT
1-51
2-D FFT
Rounding mode
Select the “Rounding Modes” for fixed-point operations. The sine
table values do not obey this parameter; instead, they always
round to Nearest.
Overflow mode
Select the Overflow mode for fixed-point operations. The sine
table values do not obey this parameter; instead, they are always
saturated.
Sine table data type
Choose how you specify the word length of the values of the sine
table. The fraction length of the sine table values always equals
the word length minus one. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit: Same
word length as input
• An expression that evaluates to a valid data type, for example,
fixdt(1,16)
The sine table values do not obey the Rounding mode and
Overflow mode parameters; instead, they are always saturated
and rounded to Nearest.
Product output data type
Specify the product output data type. See Fixed-Point Data Types
on page 47 and “Multiplication Data Types” for illustrations
depicting the use of the product output data type in this block.
You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
1-52
2-D FFT
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. See Fixed-Point Data Types
on page 47 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:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See Fixed-Point Data Types on page
47 for illustrations depicting the use of the output data type in
this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule.
When you select Inherit: Inherit via internal rule, the
block calculates the output word length and fraction length
automatically. The internal rule first calculates an ideal output
word length and fraction length using the following equations:
— When you select the Divide butterfly outputs by two
check box, the ideal output word and fraction lengths are the
same as the input word and fraction lengths.
1-53
2-D FFT
Using these ideal results, the internal rule then selects word
lengths and fraction lengths that are appropriate for your
hardware. For more information, see “Inherit via Internal
Rule”.
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-54
2-D FFT
2 Find the mirror image of each binary entry, and write it beside the
original binary representation.
If, on the 2-D FFT block parameters dialog box, you select the Output
in bit-reversed order check box, the block bit-reverses the order of
both the columns and the rows. The next diagram illustrates the linear
and bit-reversed outputs of the 2-D FFT block. The output values are
the same, but they appear in different order.
1-55
2-D FFT
0 1 2 3 4 5 6 7
Bit-reversed row
and column indices
1-56
2-D FFT
1-57
2-D FFT (To Be Removed)
Library Transforms
Description
Note The 2-D FFT block is obsolete. It may be removed in a future
version of the Computer Vision System Toolbox software. Use the
replacement block 2-D FFT.
1-58
2-D FIR Filter
Library Filtering
visionfilter
Description The 2-D Finite Impulse Response (FIR) filter block filters the input
matrix I using the coefficient matrix H or the coefficient vectors HH
and HV.
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of • Double-precision floating point Yes
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
H Matrix of filter coefficients Same as I port. Yes
HH Vector of filter coefficients Same as I port. The input to ports Yes
HH and HV must be the same
data type.
HV Vector of filter coefficients Same as I port. The input to ports Yes
HH and HV must be the same
data type.
PVal Scalar value that Input must have the same data Yes
represents the constant type as the input to I port.
pad value
Output Scalar, vector, or matrix Same as I port. Yes
of filtered values
1-59
2-D FIR Filter
If the input has a floating-point data type, then the output uses the
same data type. Otherwise, the output can be any fixed-point data type.
Select the Separable filter coefficients check box if your filter
coefficients are separable. Using separable filter coefficients reduces
the amount of calculations the block must perform to compute the
output. For example, suppose your input image is M-by-N and your
filter coefficient matrix is x-by-y. For a nonseparable filter with the
Output size parameter set to Same as input port I, it would take
x⋅ y⋅ M ⋅ N
multiply-accumulate (MAC) operations for the block to calculate the
output. For a separable filter, it would only take
( x + y) ⋅ M ⋅ N
MAC operations. If you do not know whether or not your filter
coefficients are separable, use the isfilterseparable function.
Here is an example of the function syntax, [S, HCOL, HROW] =
isfilterseparable(H). The isfilterseparable function takes the
filter kernel, H, and returns S, HCOL and HROW. Here, S is a Boolean
variable that is 1 if the filter is separable and 0 if it is not. HCOL is a
vector of vertical filter coefficients, and HROW is a vector of horizontal
filter coefficients.
Use the Coefficient source parameter to specify how to define your
filter coefficients. If you select the Separable filter coefficients check
box and then select a Coefficient source of Specify via dialog, the
Vertical coefficients (across height) and Horizontal coefficients
(across width) parameters appear in the dialog box. You can use these
parameters to enter vectors of vertical and horizontal filter coefficients,
respectively.
You can also use the variables HCOL and HROW, the output of the
isfilterseparable function, for these parameters. If you select the
Separable filter coefficients check box and then select a Coefficient
source of Input port, ports HV and HH appear on the block. Use
these ports to specify vectors of vertical and horizontal filter coefficients.
1-60
2-D FIR Filter
If you clear the Separable filter coefficients check box and select
a Coefficient source of Specify via dialog, the Coefficients
parameter appears in the dialog box. Use this parameter to enter your
matrix of filter coefficients.
If you clear the Separable filter coefficients check box and select a
Coefficient source of Input port, port H appears on the block. Use
this port to specify your filter coefficient matrix.
The block outputs the result of the filtering operation at the Output
port. The Output size parameter and the sizes of the inputs at ports I
and H dictate the dimensions of the output. For example, assume that
the input at port I has dimensions (Mi, Ni) and the input at port H has
dimensions (Mh, Nh). If you select anOutput size of Full, the output
has dimensions (Mi+Mh-1, Ni+Nh-1). If you select an Output size of
Same as input port I, the output has the same dimensions as the
input at port I. If you select an Output size of Valid, the block filters
the input image only where the coefficient matrix fits entirely within
it, so no padding is required. The output has dimensions (Mi-Mh+1,
Ni-Nh+1). However, if all(size(I)<size(H)), the block errors out.
Use the Padding options parameter to specify how to pad the
boundary of your input matrix. To pad your matrix with a constant
value, select Constant. To pad your input matrix by repeating its border
values, select Replicate. To pad your input matrix with its mirror
image, select Symmetric. To pad your input matrix using a circular
repetition of its elements, select Circular. For more information on
padding, see the Image Pad block reference page.
If, for the Padding options parameter, you select Constant, the
Pad value source parameter appears in the dialog box. If you select
Specify via dialog, the Pad value parameter appears in the dialog
box. Use this parameter to enter the constant value with which to pad
your matrix. If you select Pad value source ofInput port, the PVal
port appears on the block. Use this port to specify the constant value
with which to pad your matrix. The pad value must be real if the input
image is real. You will get an error message if the pad value is complex
when the input image is real.
1-61
2-D FIR Filter
( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) * H (i − m, j − n)
m =0 n =0
( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( H (m + i, n + j))
m =0 n =0
1-62
2-D FIR Filter
You can set the coefficient, product output, accumulator, and output
data types in the block mask as discussed in “Dialog Box” on page 1-63.
The output of the multiplier is in the product output data type if at
least one of the inputs to the multiplier is real. If both of the inputs
to the multiplier are complex, the result of the multiplication is in
the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”.
Dialog The Main pane of the 2-D FIR Filter dialog box appears as shown in
Box the following figure.
1-63
2-D FIR Filter
1-64
2-D FIR Filter
values. Select Symmetricto pad your input matrix with its mirror
image. Select Circular to pad your input matrix using a circular
repetition of its elements. This parameter appears if you select an
Output size of Full or Same as input port I.
Pad value source
Use this parameter to specify how to define your constant
boundary value. Select Specify via dialog to enter your value
in the block parameters dialog box. Select Input port to specify
your constant value using the PVal port. This parameter appears
if you select a Padding options of Constant.
Pad value
Enter the constant value with which to pad your matrix. This
parameter is visible if, for the Pad value source parameter, you
select Specify via dialog. Tunable. The pad value must be real
if the input image is real. You will get an error message if the pad
value is complex when the input image is real.
Filtering based on
Specify the algorithm by which the block filters the input matrix.
You can select Convolution or Correlation.
The Data Types pane of the 2-D FIR Filter dialog box appears as
shown in the following figure.
1-65
2-D FIR Filter
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Coefficients
Choose how to specify the word length and the fraction length
of the filter coefficients.
• When you select Inherit: Same word length as input,
the word length of the filter coefficients match that of the
input to the block. In this mode, the block automatically sets
1-66
2-D FIR Filter
The filter coefficients do not obey the Rounding mode and the
Overflow mode parameters; instead, they always saturated and
rounded to Nearest.
See “Specify Data Types Using Data Type Assistant” for more
information.
Product output
Use this parameter to specify how to designate the product output
word and fraction lengths. Refer to “Fixed-Point Data Types”
on page 1-62 and “Multiplication Data Types” for illustrations
depicting the use of the product output data type in this block:
• When you select Inherit: Same as input, these
characteristics match those of the input to the block.
• When you select fixdt([],16,0), you can enter the word
length and the fraction length of the product output, in bits.
1-67
2-D FIR Filter
• When you select <data type expression>, you can enter the
data type expression.
If you set the Coefficent source (on the Main tab) to Input port
the Product Output will inherit its sign according to the inputs.
If either or both input I1 and I2 are signed, the Product Output
will be signed. Otherwise, the Product Output is unsigned. The
following table shows all cases.
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator
Use this parameter to specify how to designate the accumulator
word and fraction lengths. Refer to “Fixed-Point Data Types” on
page 1-62 and “Multiplication Data Types” in the DSP System
Toolbox™ documentation for illustrations depicting the use of the
accumulator data type in this block. The accumulator data type is
only used when both inputs to the multiplier are complex:
• When you select Inherit: Same as input, these
characteristics match those of the input to the block.
• When you select Inherit: Same as product output, these
characteristics match those of the product output.
1-68
2-D FIR Filter
See “Specify Data Types Using Data Type Assistant” for more
information.
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Inherit: Same as input, these
characteristics match those of the input to the block.
• When you select fixdt([],16,0), you can enter the word
length and the fraction length of the output, in bits.
You can choose to set signedness of the output to Auto, Signed
or Unsigned.
• When you select <data type expression>, you can enter the
a data type expression.
See “Specify Data Types Using Data Type Assistant” for more
information.
1-69
2-D FIR Filter
1-70
2-D Histogram
Library Statistics
visionstatistics
Description The 2-D Histogram block computes the frequency distribution of the
elements in the input. You must use the Find the histogram over
parameter to specify whether the block computes the histogram for
Each column of the input or of the Entire input. The Running
histogram check box allows you to select between basic operation and
running operation, as described below.
The block distributes the elements of the input into the number of
discrete bins specified by the Number of bins parameter, n.
The 2-D Histogram block sorts all complex input values into bins
according to their magnitude.
The histogram value for a given bin represents the frequency of
occurrence of the input values bracketed by that bin. You specify
the upper boundary of the highest-valued bin in the Upper limit of
histogram parameter, BM, and the lower boundary of the lowest-valued
bin in the Lower limit of histogram parameter, Bm. The bins have
equal width of
BM Bm
n
1
Bm k k 0, 1, 2,..., n 1
2
Input values that fall on the border between two bins are placed into
the lower valued bin; that is, each bin includes its upper boundary.
For example, a bin of width 4 centered on the value 5 contains the
1-71
2-D Histogram
input value 7, but not the input value 3. Input values greater than
the Upper limit of histogram parameter or less than Lower limit
of histogram parameter are placed into the highest valued or lowest
valued bin, respectively.
The values you enter for the Upper limit of histogram and Lower
limit of histogram parameters must be real-valued scalars. NaN and
inf are not valid values for the Upper limit of histogram and Lower
limit of histogram parameters.
Basic Operation
When the Running histogram check box is not selected, the 2-D
Histogram block computes the frequency distribution of the current
input.
When you set the Find the histogram over parameter to Each
column, the 2-D Histogram block computes a histogram for each column
of the M-by-N matrix independently. The block outputs an n-by-N
matrix, where n is the Number of bins you specify. The jth column of
the output matrix contains the histogram for the data in the jth column
of the M-by-N input matrix.
When you set the Find the histogram over parameter to Entire
input, the 2-D Histogram block computes the frequency distribution
for the entire input vector, matrix or N-D array. The block outputs an
n-by-1 vector, where n is the Number of bins you specify.
Running Operation
When you select the Running histogram check box, the 2–D
Histogram block computes the frequency distribution of both the past
and present data for successive inputs. The block resets the histogram
(by emptying all of the bins) when it detects a reset event at the optional
Rst port. See “Resetting the Running Histogram” on page 1-73 for more
information on how to trigger a reset.
When you set the Find the histogram over parameter to Each
column, the 2-D Histogram block computes a running histogram for
each column of the M-by-N matrix. The block outputs an n-by-N matrix,
where n is the Number of bins you specify. The jth column of the
1-72
2-D Histogram
output matrix contains the running histogram for the jth column of
the M-by-N input matrix.
When you set the Find the histogram over parameter to Entire
input, the 2-D Histogram block computes a running histogram for the
data in the first dimension of the input. The block outputs an n-by-1
vector, where n is the Number of bins you specify.
Note When the 2-D Histogram block is used in running mode and
the input data type is non-floating point, the output of the histogram
is stored as a uint32 data type. The largest number that can be
represented by this data type is 232-1. If the range of the uint32 data
type is exceeded, the output data will wrap back to 0.
• 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)
1-73
2-D Histogram
• 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)
1-74
2-D Histogram
Dialog The Main pane of the 2-D Histogram block dialog appears as follows.
Box
1-75
2-D Histogram
1-76
2-D Histogram
Normalized
When selected, the output vector, v, is normalized such that
sum(v) = 1.
The Data Types pane of the 2-D Histogram block dialog appears as
follows.
1-77
2-D Histogram
Note The fixed-point parameters listed are only used for fixed-point
complex inputs, which are distributed by squared magnitude.
1-78
2-D Histogram
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Product output data type
Specify the product output data type. See “Multiplication Data
Types” for illustrations depicting the use of the product output
data type. You can set it to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt([],16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt([],16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
1-79
2-D Histogram
1-80
2-D Histogram (To Be Removed)
Library Statistics
Description
Note The 2-D Histogram block is obsolete. It may be removed in a
future version of the Computer Vision System Toolbox software. Use
the replacement block Histogram.
1-81
2-D IDCT
Library Transforms
visiontransforms
M −1 N −1
2 (2 x + 1)mπ (2 y + 1)nπ
f ( x, y) =
MN
∑ ∑ C(m)C(n) F (m, n) cos 2M
cos
2N
m =0 n =0
C(m), C(n) = 1
where F(m,n) is the DCT of the signal f(x,y) and 2 for
m, n = 0 and C(m), C(n) = 1 otherwise.
The number of rows and columns of the input signal must be powers
of two. The output of this block has dimensions the same dimensions
as the input.
Complex
Port Input/Output Supported Data Types Values
Supported
Input Vector or matrix of • Double-precision floating No
intensity values point
• Single-precision floating
point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned
integer
1-82
2-D IDCT
If the data type of the input signal is floating point, the output of the
block is the same data type.
Use the Sine and cosine computation parameter to specify how the
block computes the sine and cosine terms in the IDCT algorithm. If
you select Trigonometric fcn, the block computes the sine and cosine
values during the simulation. If you select Table lookup, the block
computes and stores the trigonometric values before the simulation
starts. In this case, the block requires extra memory.
1-83
2-D IDCT
1-84
2-D IDCT
The output of the multiplier is in the product output data type when
at least one of the inputs to the multiplier is real. When both of the
inputs to the multiplier are complex, the result of the multiplication is
in the accumulator data type. For details on the complex multiplication
performed, refer to “Multiplication Data Types”. You can set the sine
table, product output, accumulator, and output data types in the block
mask as discussed in the next section.
Dialog The Main pane of the 2-D IDCT dialog box appears as shown in the
Box following figure.
1-85
2-D IDCT
you select Table lookup, the block computes and stores the
trigonometric values before the simulation starts. In this case, the
block requires extra memory.
The Data Types pane of the 2-D IDCT dialog box appears as shown in
the following figure.
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations. The sine
table values do not obey this parameter; instead, they are always
saturated.
1-86
2-D IDCT
The sine table values do not obey the Rounding mode and
Overflow mode parameters; instead, they are always saturated
and rounded to Nearest.
Product output data type
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-83 and “Multiplication Data Types” for
illustrations depicting the use of the product output data type in
this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-83 for illustrations depicting the use of the accumulator
data type in this block. You can set this parameter to:
1-87
2-D IDCT
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on
page 1-83 for illustrations depicting the use of the output data
type in this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule.
When you select Inherit: Inherit via internal rule, the
block calculates the output word length and fraction length
automatically. The internal rule first calculates an ideal output
word length and fraction length using the following equations:
Using these ideal results, the internal rule then selects word
lengths and fraction lengths that are appropriate for your
hardware. For more information, see “Inherit via Internal
Rule”.
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
1-88
2-D IDCT
See “Specify Data Types Using Data Type Assistant” for more
information.
Lock scaling against changes by the autoscaling tool
Select this parameter to prevent any fixed-point scaling you
specify in this block mask from being overridden by the
autoscaling tool in the Fixed-Point Tool. For more information,
see fxptdlg, a reference page on the Fixed-Point Tool in the
Simulink documentation.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
References [1] Chen, W.H, C.H. Smith, and S.C. Fralick, “A fast computational
algorithm for the discrete cosine transform,”IEEE Trans. Commun.,
vol. COM-25, pp. 1004-1009. 1977.
[2] Wang, Z. “Fast algorithms for the discrete W transform and for
the discrete Fourier transform,” IEEE Trans. Acoust., Speech, Signal
Processing, vol. ASSP-32, pp. 803-816, Aug. 1984.
1-89
2-D IFFT
Library Transforms
visiontransforms
Description The 2-D IFFT block computes the inverse fast Fourier transform
(IFFT) of an M-by-N input matrix in two steps. First, it computes the
one-dimensional IFFT along one dimension (row or column). Next,
it computes the IFFT of the output of the first step along the other
dimension (column or row).
The output of the IFFT block is equivalent to the MATLAB ifft2
function:
M −1 N −1 2πmx 2πny
1 j j
f ( x, y) =
MN
∑ ∑ F (m, n)e M e N
m =0 n =0
where 0 ≤ x ≤ M − 1 and 0 ≤ y ≤ N − 1 .
The output of this block has the same dimensions as the input. If
the input signal has a floating-point data type, the data type of the
output signal uses the same floating-point data type. Otherwise, the
output can be any fixed-point data type. The block computes scaled
and unscaled versions of the IFFT.
The input to this block can be floating-point or fixed-point, real or
complex, and conjugate symmetric. The block uses one of two possible
FFT implementations. You can select an implementation based on the
FFTW library [1], [2], or an implementation based on a collection of
Radix-2 algorithms. You can select Auto to allow the block to choose
the implementation.
1-90
2-D IFFT
Port Description
Complex
Port Description Supported Data Types Values
Supported
Input Vector or matrix of • Double-precision Yes
intensity values floating point
• Single-precision
floating point
• Fixed point
• 8-, 16-, 32-bit signed
integer
• 8-, 16-, 32-bit unsigned
integer
FFTW Implementation
The FFTW implementation provides an optimized FFT calculation
including support for power-of-two and non-power-of-two transform
lengths in both simulation and code generation. Generated code
using the FFTW implementation will be restricted to MATLAB host
computers. The data type must be floating-point. Refer to “Simulink
Coder” for more details on generating code.
Radix-2 Implementation
The Radix-2 implementation supports bit-reversed processing, fixed or
floating-point data, and allows the block to provide portable C-code
generation using the “Simulink Coder”. The dimensions of the input
matrix, M and N, must be powers of two. To work with other input
sizes, use the Image Pad block to pad or truncate these dimensions to
powers of two, or if possible choose the FFTW implementation.
1-91
2-D IFFT
• Butterfly operation
• Double-signal algorithm
• Half-length algorithm
• Radix-2 decimation-in-time (DIT) algorithm
• Radix-2 decimation-in-frequency (DIF) algorithm
Radix-2 DIF
1-92
2-D IFFT
Radix-2 DIF
2πk
j
e K
1-93
2-D IFFT
output, and output data types displayed in the diagrams in the IFFT
dialog box as discussed in “Dialog Box” on page 1-96.
Inputs to the IFFT block are first cast to the output data type and stored
in the output buffer. Each butterfly stage then processes signals in the
accumulator data type, with the final output of the butterfly being cast
back into the output data type. The block multiplies in a twiddle factor
before each butterfly stage in a decimation-in-time IFFT and after each
butterfly stage in a decimation-in-frequency IFFT.
1-94
2-D IFFT
1-95
2-D IFFT
Dialog The Main pane of the 2-D IFFT dialog box appears as shown in the
Box following figure.
1-96
2-D IFFT
1-97
2-D IFFT
FFT implementation
Set this parameter to FFTW [1], [2] to support an arbitrary length
input signal. The block restricts generated code with FFTW
implementation to MATLAB host computers.
Set this parameter to Auto to let the block choose the FFT
implementation. For non-power-of-two transform lengths, the
block restricts generated code to MATLAB host computers.
Input is in bit-reversed order
Select or clear this check box to designate the order of the input
channel elements. Select this check box when the input should
appear in reversed order, and clear it when the input should
appear in linear order. The block yields invalid outputs when you
do not set this parameter correctly. This check box only appears
when you set the FFT implementation parameter to Radix-2
or Auto.
The FFT block yields conjugate symmetric output when you input
real-valued data. Taking the IFFT of a conjugate symmetric input
1-98
2-D IFFT
If the IFFT block inputs conjugate symmetric data and you do not
select this check box, the IFFT block outputs a complex-valued
signal with small imaginary parts. The block outputs invalid data
if you select this option with non conjugate symmetric input data.
Divide output by product of FFT length in each input dimension
Select this check box to compute the scaled IFFT. The block
computes scaled and unscaled versions of the IFFT. If you select
this option, the block computes the scaled version of the IFFT.
The unscaled IFFT is defined by the following equation:
M −1 N −1 2πmx 2πny
j j
f ( x, y) = ∑ ∑ F (m, n)e M e N
m =0 n =0
where 0 ≤ x ≤ M − 1 and 0 ≤ y ≤ N − 1 .
1
version by .
MN
The Data Types pane of the 2-D IFFT dialog box appears as shown in
the following figure.
1-99
2-D IFFT
1-100
2-D IFFT
Rounding mode
Select the “Rounding Modes” for fixed-point operations. The sine
table values do not obey this parameter; instead, they always
round to Nearest.
Overflow mode
Select the Overflow mode for fixed-point operations. The sine
table values do not obey this parameter; instead, they are always
saturated.
Sine table data type
Choose how you specify the word length of the values of the sine
table. The fraction length of the sine table values always equals
the word length minus one. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit: Same
word length as input
• An expression that evaluates to a valid data type, for example,
fixdt(1,16)
The sine table values do not obey the Rounding mode and
Overflow mode parameters; instead, they are always saturated
and rounded to Nearest.
Product output data type
Specify the product output data type. See Fixed-Point Data Types
on page 93 and “Multiplication Data Types” for illustrations
depicting the use of the product output data type in this block.
You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
1-101
2-D IFFT
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. SeeFixed-Point Data Types on
page 93 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:
Inherit via internal rule
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See Fixed-Point Data Types on page
93 for illustrations depicting the use of the output data type in
this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit:
Inherit via internal rule.
When you select Inherit: Inherit via internal rule, the
block calculates the output word length and fraction length
automatically. The internal rule first calculates an ideal output
word length and fraction length using the following equations:
— When you select the Divide butterfly outputs by two
check box, the ideal output word and fraction lengths are the
same as the input word and fraction lengths.
1-102
2-D IFFT
Using these ideal results, the internal rule then selects word
lengths and fraction lengths that are appropriate for your
hardware. For more information, see “Inherit via Internal
Rule”.
• An expression that evaluates to a valid data type, for example,
fixdt(1,16,0)
See “Specify Data Types Using Data Type Assistant” for more
information.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-103
2-D IFFT
1-104
2-D IFFT (To Be Removed)
Library Transforms
viptransforms
Description
Note The 2-D IFFT block is obsolete. It may be removed in a future
version of the Computer Vision System Toolbox software. Use the
replacement block 2-D IFFT.
1-105
2-D Maximum
Library Statistics
visionstatistics
Description The 2-D Maximum block identifies the value and/or position of the
smallest element in each row or column of the input, or along a specified
dimension of the input. The 2-D Maximum block can also track the
maximum values in a sequence of inputs over a period of time.
The 2-D Maximum block supports real and complex floating-point,
fixed-point, and Boolean inputs. Real fixed-point inputs can be either
signed or unsigned, while complex fixed-point inputs must be signed.
The output data type of the maximum values match the data type of
the input. The block outputs double index values, when the input is
double, and uint32 otherwise.
Port Descriptions
1-106
2-D Maximum
• Single-precision
floating point
• Boolean
• 8-, 16-, and 32-bit
signed integers
• 8-, 16-, and 32-bit
unsigned integers
1-107
2-D Maximum
Value Mode
When you set the Mode parameter to Value, the block computes the
maximum 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 sample
time, and outputs the array y. Each element in y is the maximum
value in the corresponding column, row, vector, or entire input. The
output y depends on the setting of the Find the maximum value
over parameter. For example, consider a 3-dimensional input signal
of size M-by-N-by-P:
For complex inputs, the block selects the value in each row or column
of the input, along vectors of a specified dimension of the input, or of
1-108
2-D Maximum
the entire input that has the maximum magnitude squared as shown
2 2
below. For complex value u a bi , the magnitude squared is a b .
Index Mode
When you set the Mode parameter to Index, the block computes the
maximum value in each row or column of the input, along vectors of a
specified dimension of the input, or of the entire input, and outputs the
index array I. Each element in I is an integer indexing the maximum
value in the corresponding column, row, vector, or entire input. The
output I depends on the setting of the Find the maximum value
over parameter. For example, consider a 3-dimensional input signal
of size M-by-N-by-P:
1-109
2-D Maximum
When a maximum value occurs more than once, the computed index
corresponds to the first occurrence. For example, when the input is
the column vector [3 2 1 2 3]', the computed one-based index of the
maximum value is 1 rather than 5 when Each column is selected.
When inputs to the block are double-precision values, the index values
are double-precision values. Otherwise, the index values are 32-bit
unsigned integer values.
Running Mode
When you set the Mode parameter to Running, the block tracks the
maximum value of each channel in a time sequence of M-by-N inputs.
In this mode, the block treats each element as a channel.
1-110
2-D Maximum
• 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)
Rising edge
Rising edge
• 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)
1-111
2-D Maximum
ROI Processing
To calculate the statistical value within a particular region of interest
(ROI) of the input, select the Enable ROI processing check box. This
applies to any mode other than running mode and when you set the
Find the maximum value over parameter to Entire input and you
select the Enable ROI processing check box. ROI processing applies
only for 2-D inputs.
You can specify a rectangle, line, label matrix, or binary mask ROI type.
Use the binary mask to specify which pixels to highlight or select.
Use the label matrix to label regions. Pixels set to 0 represent the
background. Pixels set to 1 represent the first object, pixels set to 2,
1-112
2-D Maximum
represent the second object, and so on. 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 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. For more information about the format of the
input to the ROI port when you set the ROI to a rectangle or a line, see
the Draw Shapes block reference page.
ROI Output Statistics
Output = Individual statistics for each ROI
Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.
Flag Description
Port
Output
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.
1-113
2-D Maximum
Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.
Flag Description
Port
Output
0 None of the label numbers are in the label matrix.
1 At least one of the label numbers is in the label matrix.
1-114
2-D Maximum
Dialog The Main pane of the Maximum block dialog appears as follows.
Box
Mode
Specify the block’s mode of operation:
• Value and Index — Output both the value and the index
location.
1-115
2-D Maximum
For the Value, Index, and Value and Index modes, the 2-D
Maximum block produces identical results as the MATLAB max
function when it is called as [y I] = max(u,[],D), where u and
y are the input and output, respectively, D is the dimension, and
I is the index.
Find the maximum value over
Specify whether the block should find the maximum of the entire
input each row, each column, or dimensions specified by the
Dimension parameter.
Reset port
Specify the reset event that causes the block to reset the running
maximum. The rate of the reset signal must be a positive integer
multiple of the rate of the data signal input. This parameter
appears only when you set the Mode parameter to Running. For
information about the possible values of this parameter, see
“Resetting the Running Maximum” on page 1-110.
Dimension
Specify the dimension (one-based value) of the input signal, over
which the maximum is computed. The value of this parameter
cannot exceed the number of dimensions in the input signal. This
parameter applies only when you set the Find the maximum
value over parameter to Specified dimension.
Enable ROI processing
Select this check box to calculate the statistical value within a
particular region of each image. This parameter applies only
1-116
2-D Maximum
when you set the Find the maximum value over parameter to
Entire input, and the block is not in running mode.
ROI type
Specify the type of ROI you want to use. Your choices are
Rectangles, Lines, Label matrix, or Binary mask.
When you set this parameter to Label matrix, the Label and
Label Numbers ports appear on the block and 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.
1-117
2-D Maximum
The Data Types pane of the Maximum block dialog appears as follows.
1-118
2-D Maximum
Note The parameters on the Data Types pane are only used for
complex fixed-point inputs. The sum of the squares of the real and
imaginary parts of such an input are formed before a comparison is
made, as described in “Value Mode” on page 1-108. The results of the
squares of the real and imaginary parts are placed into the product
output data type. The result of the sum of the squares is placed into
the accumulator data type. These parameters are ignored for other
types of inputs.
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Product output data type
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-114 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)
See “Specify Data Types Using Data Type Assistant” for more
information.
1-119
2-D Maximum
See “Specify Data Types Using Data Type Assistant” for more
information.
Lock data type settings against changes by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask.
Examples
The ex_vision_2dmaximum example finds the maximum value within
two ROIs. The model outputs the maximum values and their one-based
[x y] coordinate locations.
1-120
2-D Maximum
1-121
2-D Maximum (To Be Removed)
Library vipobslib
Description
Note This 2-D Maximum block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated 2-D Maximum block that
uses the one-based, [x y] coordinate system.
1-122
2-D Mean
Library Statistics
visionstatistics
Description The 2-D 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 2-D 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 Description
1-123
2-D Mean
Binary Mask:
• Boolean
Label • 8-, 16-, and 32-bit unsigned integers
Label • 8-, 16-, and 32-bit unsigned integers
Numbers
Output • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Flag • Boolean
Basic Operation
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
1-124
2-D Mean
1-125
2-D Mean
Running Operation
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.
1-126
2-D Mean
Rising edge
Rising edge
• 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)
1-127
2-D Mean
ROI Processing
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 2-D inputs.
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.
1-128
2-D Mean
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.
Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.
Flag Description
Port
Output
0 All ROIs are completely outside the input image.
1 At least one ROI is completely or partially inside the
input image.
1-129
2-D Mean
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.
Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.
Flag Description
Port
Output
0 None of the label numbers are in the label matrix.
1 At least one of the label numbers is in the label matrix.
1-130
2-D Mean
You can set the accumulator and output data types in the block dialog,
as discussed in “Dialog Box” on page 1-131.
Dialog The Main pane of the Mean block dialog appears as follows.
Box
1-131
2-D Mean
Running mean
Enables running operation when selected.
Reset port
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” on page
1-126.
1-132
2-D Mean
1-133
2-D Mean
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” on page 1-128.
The Data Types pane of the Mean block dialog appears as follows.
1-134
2-D Mean
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-130 for illustrations depicting the use of the accumulator
data type in this block. You can set this parameter to:
1-135
2-D Mean
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on
page 1-130 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)
See “Specify Data Types Using Data Type Assistant” for more
information.
Minimum
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 fixed-point data types
1-136
2-D Mean
Maximum
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 fixed-point data types
Example
The ex_vision_2dmean calculates the mean value within two ROIs.
1-137
2-D Mean (To Be Removed)
Library Statistics
Description
Note This 2-D Mean block will be removed in a future release. It uses
the zero-based, [row column] coordinate system. It is recommended that
you replace this block with the updated 2-D Mean block that uses the
one-based, [x y] coordinate system.
1-138
2-D Median
Library Statistics
visionstatistics
Description The 2-D 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:
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 3-dimensional input signal of size M-by-N-by-P:
1-139
2-D Median
The accumulator and output data types and scalings are used for
fixed-point signals when M is even. The result of the sum performed
while calculating the average of the two central rows of the input matrix
1-140
2-D Median
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
fixed-point 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 fixed-point 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.
Dialog The Main pane of the 2–D Median block dialog appears as follows.
Box
1-141
2-D Median
Sort algorithm
Specify whether to sort the elements of the input using a Quick
sort or an Insertion sort algorithm.
Find the median value over
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.
Dimension
Specify the dimension (one-based 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
1-142
2-D Median
parameter is only visible when the Find the median value over
parameter is set to Specified dimension.
The Data Types pane of the 2-D Median block dialog appears as follows.
1-143
2-D Median
Rounding mode
Select the Rounding mode for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Product output data type
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-140 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)
See “Specify Data Types Using Data Type Assistant” for more
information.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-140 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)
1-144
2-D Median
See “Specify Data Types Using Data Type Assistant” for more
information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on
page 1-140 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)
See “Specify Data Types Using Data Type Assistant” for more
information.
Minimum
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 fixed-point data types
Maximum
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 fixed-point data types
1-145
2-D Median
1-146
2-D Median
1-147
2-D Minimum
Library Statistics
visionstatistics
Description The 2-D Minimum block identifies the value and/or position of the
smallest element in each row or column of the input, or along a specified
dimension of the input. The 2-D Minimum block can also track the
minimum values in a sequence of inputs over a period of time.
The 2-D Minimum block supports real and complex floating-point,
fixed-point, and Boolean inputs. Real fixed-point inputs can be either
signed or unsigned, while complex fixed-point inputs must be signed.
The output data type of the minimum values match the data type of
the input. The block outputs double index values, when the input is
double, and uint32 otherwise.
Port Description
Complex
Port Input/Output Supported Data Types Values
Supported
Input Scalar, vector or matrix of • Double-precision floating point Yes
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Rst Scalar value Boolean No
1-148
2-D Minimum
Complex
Port Input/Output Supported Data Types Values
Supported
Val Minimum value output Same as Input port Yes
based on the “Value Mode”
on page 1-149
Idx One-based output location of Same as Input port No
the minimum value based
on the “Index Mode” on page
1-150
Value Mode
When you set the Mode parameter to Value, the block computes the
minimum value in each row, column, entire input, or over a specified
dimension. The block outputs each element as the minimum value in the
corresponding column, row, vector, or entire input. The output depends
on the setting of the Find the minimum value over parameter. For
example, consider a 3-dimensional input signal of size M-by-N-by-P:
1-149
2-D Minimum
For complex inputs, the block selects the value in each row or column of
the input, along vectors of a specified dimension of the input, or of the
entire input that has the minimum magnitude squared as shown below.
2 2
For complex value u a bi , the magnitude squared is a b .
Index Mode
When you set the Mode parameter to Index, the block computes the
minimum value in each row or column of the input, along vectors of a
specified dimension of the input, or of the entire input, and outputs the
index array I. Each element in I is an integer indexing the minimum
value in the corresponding column, row, vector, or entire input. The
output I depends on the setting of the Find the minimum value
over parameter. For example, consider a 3-dimensional input signal
of size M-by-N-by-P:
1-150
2-D Minimum
When a minimum value occurs more than once, the computed index
corresponds to the first occurrence. For example, when the input is the
column vector [-1 2 3 2 -1]', the computed one-based index of the
minimum value is 1 rather than 5 when Each column is selected.
1-151
2-D Minimum
Running Mode
When you set the Mode parameter to Running, the block tracks the
minimum value of each channel in a time sequence of M-by-N inputs.
In this mode, the block treats each element as a channel.
Rising edge
Rising edge
• 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
1-152
2-D Minimum
ROI Processing
To calculate the statistical value within a particular region of interest
(ROI) of the input, select the Enable ROI processing check box. This
applies to any mode other than the running mode and when you set the
Find the minimum value over parameter to Entire input and you
select the Enable ROI processing check box. ROI processing applies
only for 2-D inputs.
You can specify a rectangle, line, label matrix, or binary mask ROI type.
1-153
2-D Minimum
Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.
Flag Description
Port
Output
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.
1-154
2-D Minimum
Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.
Flag Description
Port
Output
0 None of the label numbers are in the label matrix.
1 At least one of the label numbers is in the label matrix.
1-155
2-D Minimum
Dialog The Main pane of the 2-D Minimum dialog box appears as shown in
Box the following figure.
Mode
Specify the block’s mode of operation:
• Value and Index — Output both the value and the index
location.
1-156
2-D Minimum
For the Value, Index, and Value and Index modes, the 2-D
Minimum block produces identical results as the MATLAB min
function when it is called as [y I] = min(u,[],D), where u and
y are the input and output, respectively, D is the dimension, and
I is the index.
Find the minimum value over
Specify whether the block should find the minimum of the entire
input each row, each column, or dimensions specified by the
Dimension parameter.
Reset port
Specify the reset event that causes the block to reset the running
minimum. The rate of the reset signal must be a positive integer
multiple of the rate of the data signal input. This parameter
appears only when you set the Mode parameter to Running. For
information about the possible values of this parameter, see
“Resetting the Running Minimum” on page 1-152.
Dimension
Specify the dimension (one-based value) of the input signal, over
which the minimum is computed. The value of this parameter
cannot exceed the number of dimensions in the input signal. This
parameter applies only when you set the Find the minimum
value over parameter to Specified dimension.
Enable ROI processing
Select this check box to calculate the statistical value within a
particular region of each image. This parameter applies only
1-157
2-D Minimum
when you set the Find the minimum value over parameter to
Entire input, and the block is not in running mode.
ROI type
Specify the type of ROI you want to use. Your choices are
Rectangles, Lines, Label matrix, or Binary mask.
When you set this parameter to Label matrix, the Label and
Label Numbers ports appear on the block and 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.
1-158
2-D Minimum
1-159
2-D Minimum
Note The parameters on the Data Types pane are only used for
complex fixed-point inputs. The sum of the squares of the real and
imaginary parts of such an input are formed before a comparison is
made, as described in “Value Mode” on page 1-149. The results of the
squares of the real and imaginary parts are placed into the product
output data type. The result of the sum of the squares is placed into
the accumulator data type. These parameters are ignored for other
types of inputs.
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
Product output data type
Specify the product output data type. See “Fixed-Point Data
Types” on page 1-155 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)
See “Specify Data Types Using Data Type Assistant” for more
information.
1-160
2-D Minimum
See “Specify Data Types Using Data Type Assistant” for more
information.
Examples
1-161
2-D Minimum
1-162
2-D Minimum (To Be Removed)
Library vipobslib
Description
Note This 2-D Minimum block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated 2-D Minimum block that
uses the one-based, [x y] coordinate system.
1-163
2-D Standard Deviation
Library Statistics
visionstatistics
Description The Standard Deviation block computes the standard deviation of each
row or column of the input, along vectors of a specified dimension of the
input, or of the entire input. The Standard Deviation block can also
track the standard deviation of a sequence of inputs over a period of
time. The Running standard deviation parameter selects between
basic operation and running operation.
Port Description
1-164
2-D Standard Deviation
Binary Mask:
• Boolean
Label • 8-, 16-, and 32-bit unsigned integers
Label • 8-, 16-, and 32-bit unsigned integers
Numbers
Output • Double-precision floating point
• Single-precision floating point
Flag • Boolean
Basic Operation
When you do not select the Running standard deviation check box,
the block computes the standard deviation of 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, and outputs the array y.
Each element in y contains the standard deviation of the corresponding
column, row, vector, or entire input. The output y depends on the
setting of the Find the standard deviation value over parameter.
For example, consider a 3-dimensional input signal of size M-by-N-by-P:
1-165
2-D Standard Deviation
For purely real or purely imaginary inputs, the standard deviation of the
jth column of an M-by-N input matrix is the square root of its variance:
M
2
∑ uij − j
i=1
yj = j = 1≤ j≤ N
M −1
1-166
2-D Standard Deviation
For complex inputs, the output is the total standard deviation, which
equals the square root of the total variance, or the square root of the
sum of the variances of the real and imaginary parts. The standard
deviation of each column in an M-by-N input matrix is given by:
j = 2j,Re + 2j,Im
Note The total standard deviation does not equal the sum of the real
and imaginary standard deviations.
Running Operation
When you select the Running standard deviation check box, the
block tracks the standard deviation of successive inputs to the block. In
this mode, the block treats each element as a channel.
1-167
2-D Standard Deviation
• 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)
Rising edge
Rising edge
1-168
2-D Standard Deviation
1-169
2-D Standard Deviation
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.
Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.
Flag Description
Port
Output
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.
1-170
2-D Standard Deviation
Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.
Flag Description
Port
Output
0 None of the label numbers are in the label matrix.
1 At least one of the label numbers is in the label matrix.
1-171
2-D Standard Deviation
Dialog
Box
1-172
2-D Standard Deviation
Dimension
Specify the dimension (one-based value) of the input signal,
over which the standard deviation 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
standard deviation value over parameter is set to Specified
dimension.
Enable ROI Processing
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 standard deviation value over parameter
is set to Entire input, and the block is not in running mode.
ROI type
Specify the type of ROI you want to use. Your choices are
Rectangles, Lines, Label matrix, or Binary mask.
ROI portion to process
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.
Output
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
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” on page 1-169.
1-173
2-D Standard Deviation
Example
The ex_vision_2dstd calculates the standard deviation value within
two ROIs.
1-174
2-D Standard Deviation (To Be Removed)
Library Statistics
Description
1-175
2-D Variance
Library Statistics
visionstatistics
Description The 2-D Variance block computes the unbiased variance of each row
or column of the input, along vectors of a specified dimension of the
input, or of the entire input. The 2-D Variance block can also track the
variance of a sequence of inputs over a period of time. The Running
variance parameter selects between basic operation and running
operation.
Port Description
1-176
2-D Variance
Binary Mask:
• Boolean
Label • 8-, 16-, and 32-bit unsigned integers
Label • 8-, 16-, and 32-bit unsigned integers
Numbers
Output • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Flag • Boolean
Basic Operation
When you do not select the Running variance check box, the block
computes the variance of 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, and outputs the array y. Each element in y is
the variance of the corresponding column, row, vector, or entire input.
The output y depends on the setting of the Find the variance value
1-177
2-D Variance
1-178
2-D Variance
2
M N
M N
uij
i1 j 1
uij
2
i1 j 1
M*N
y 2
M * N 1
1-179
2-D Variance
2 Re2 Im 2
Running Operation
When you select the Running variance check box, the block tracks
the variance of successive inputs to the block. In this mode, the block
treats each element as a channel.
1-180
2-D Variance
• 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)
Rising edge
Rising edge
ROI Processing
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 variance value over
1-181
2-D Variance
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.
1-182
2-D Variance
Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.
Flag Description
Port
Output
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.
Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.
1-183
2-D Variance
Flag Description
Port
Output
0 None of the label numbers are in the label matrix.
1 At least one of the label numbers is in the label matrix.
2
uij
2
uij Accumulator or
Input-squared
∑ ∑ uij
Input product Accumulator 2
data type MAGNITUDE data type
ADDER
data type 2 ∑ ∑ uij
SQUARED ∑ ∑ uij −
M*N
2
∑ ∑ uij Accumulator
uij ∑ ∑ uij Accumulator or data type
Input-sum-squared SUBTRACTOR yi
Input Accumulator product
data type data type MAGNITUDE data type
ADDER Output
SQUARED data type
DIVIDER
DIVIDER
Accumulator
data type
Accumulator 2
data type ∑ ∑ uij
M*N M*N M * N −1
1-184
2-D Variance
Dialog The Main pane of the Variance block dialog appears as follows.
Box
1-185
2-D Variance
Running variance
Enables running operation when selected.
1-186
2-D Variance
Reset port
Specify the reset event that causes the block to reset the running
variance. 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 variance
check box. For more information, see “Resetting the Running
Variance” on page 1-180
Find the variance value over
Specify whether to find the variance along rows, columns, entire
input, or the dimension specified in the Dimension parameter.
For more information, see “Basic Operation” on page 1-177.
Dimension
Specify the dimension (one-based value) of the input signal, over
which the variance 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 variance value
over parameter is set to Specified dimension.
Enable ROI Processing
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 variance value over parameter is set to
Entire input, and the block is not in running mode.
ROI type
Specify the type of ROI you want to use. Your choices are
Rectangles, Lines, Label matrix, or Binary mask.
1-187
2-D Variance
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” on page 1-181.
The Data Types pane of the Variance block dialog appears as follows.
1-188
2-D Variance
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
1-189
2-D Variance
Input-squared product
Use this parameter to specify how to designate the input-squared
product word and fraction lengths:
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the input-squared
product, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the input-squared product.
This block requires power-of-two slope and a bias of zero.
Input-sum-squared product
Use this parameter to specify how to designate the
input-sum-squared product word and fraction lengths:
• When you select Same as input-squared product, these
characteristics match those of the input-squared product.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the input-sum-squared
product, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the input-sum-squared
product. This block requires power-of-two slope and a bias of
zero.
Accumulator
Use this parameter to specify the accumulator word and fraction
lengths resulting from a complex-complex multiplication in the
block:
1-190
2-D Variance
1-191
2-D Variance
Example
The ex_vision_2dvar calculates the variance value within two ROIs.
1-192
2-D Variance (To Be Removed)
Library Statistics
Description
Note This 2-D Variance block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated 2-D Variance block that
uses the one-based, [x y] coordinate system.
1-193
Apply Geometric Transformation
Port Description
Image M-by-N or M-by-N-by-P input matrix. M: Number of rows in the image.
N: Number of columns in the image.
P: Number of color planes in the image.
TForm When you set the Transformation matrix source parameter to Input port,
the TForm input port accepts:
Q: Number of transformations.
When you specify multiple transforms in a single matrix, each transform is
applied separately to the original image. If the individual transforms produce
an overlapping area, the result of the transform in the last row of the matrix is
overlaid on top.
ROI When you set the ROI source parameter to Input port, the ROI input port
accepts:
• 4-element vector rectangle ROI.
• 2L-element vector polygon ROI.
1-194
Apply Geometric Transformation
Port Description
Transformations
The size of the transformation matrix will dictate the transformation
type.
Affine Transformation
⎧ xˆ = xh1 + yh2 + h3
⎨
⎩ yˆ = xh4 + yh5 + h6
where h1, h2, ... h6 are transformation coefficients.
If you use one transformation, the transformation coefficients must be
arranged as a 3-by-2 matrix as in:
h1 h4
H h2 h5
h3 h6
or in a 1-by-6 vector as in H h1 h2 h3 h4 h5 h6 .
If you use more than one transformation, the transformation coefficients
must be arranged as a Q-by-6 matrix, where each row has the
1-195
Apply Geometric Transformation
⎧ ˆ xh1 + yh2 + h3
⎪ x = xh + yh + h
⎪ 7 8 9
⎨
xh
⎪ yˆ = 4 + yh 5 + h6
⎪⎩ xh7 + yh8 + h9
where h1, h2, ... h9 are transformation coefficients.
If you use one transformation, the transformation coefficients must be
arranged as a 3-by-3 matrix as in:
h1 h4 h7
H h2 h5 h8
h3 h6 h9
1-196
Apply Geometric Transformation
Dialog Box
The Main pane of the Apply Geometric Transformation dialog box
appears as shown in the following figure.
1-197
Apply Geometric Transformation
1-198
Apply Geometric Transformation
1-199
Apply Geometric Transformation
Number of
Transformation Region of Interest
Matrices
One You can apply the transformation on the entire image, single ROI or
transformation multiple ROIs.
matrix
Multiple • You can apply multiple transformation matrices on one ROI or on
transformation the entire image. The transformations are done in the order they
matrices are entered in the TForm.
• You can apply multiple transformation matrices on multiple
ROIs. Each transformation matrix is applied to one ROI. The first
transformation matrix specified is applied to the first ROI specified.
The second transformation matrix is applied to the second ROI
specified, and so on. The number of transformation matrices must
be equal to the number of ROIs.
ROI source
Specify the source for the region of interest (ROI), either Specify via
dialog or Input port. This appears when you set the Process pixels
in parameter to either Rectangle ROI, or Polygon ROI.
Location and size of rectangle ROI [x y width height]
Specify a 4-element vector or an R-by-4 matrix , (where R represents the
number of ROIs). This parameter appears when you set the Process
pixels in parameter to Rectangle ROI.
Specify the rectangle by its top-left corner and size in width and height.
If you specify one ROI, it must be a 4-element vector of format [x y width
height]. If you specify more than one ROI, it must be an R-by-4 matrix,
such that each row’s format is [x y width height].
Vertices of polygon ROI [x1 y1 x2 y2 ... xL yL]
Specify a 2L-element vector or an R-by-2L matrix, (where R represents
the number of ROIs and L is the number of vertices in a polygon). This
parameter appears when you set the Process pixels in parameter
to Polygon ROI.
1-200
Apply Geometric Transformation
1-201
Apply Geometric Transformation
1 Add two Constant blocks for the input image and the transformation
matrix. Set the Constant value parameters for the constant blocks
as follows:
• for the input image, "checker_board", and
• for the transformation matrix,[1 0 0; .4 1 0; 0 0 1]
2 Add two Video Viewer blocks, connecting one directly to the input
image output port, and the other one to the Apply Geometric
Transformation output port.
1-202
Apply Geometric Transformation
4 Add two Video Viewer blocks, connecting one directly to the Constant
block containing the input image. The other, to the Apply Geometric
Transformation output port.
References [1] George Wolberg, “Digital Image Warping”, IEEE Computer Society
Press, 3rd edition, 1994.
Richard Hartley and Andrew Zisserman, “Multiple View Geometry in
Computer Vision“, Cambridge University Press, 2nd edition, 2003.
Supported
Data
Types
1-203
Apply Geometric Transformation
1-204
Apply Geometric Transformation (To Be Removed)
Description
Note This Apply Geometric Transformation block will be removed
in a future release. It uses the zero-based, [row column] coordinate
system. It is recommended that you replace this block with the updated
Apply Geometric Transformation block that uses the one-based, [x y]
coordinate system.
1-205
Autothreshold
Library Conversions
visionconversions
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating No
values point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
BW Scalar, vector, or matrix that Boolean No
represents a binary image
Th Threshold value Same as I port No
EMetric Effectiveness metric Same as I port No
1-206
Autothreshold
If you clear the Scale threshold check box, the block uses the
threshold value computed by Otsu’s method to convert intensity images
1-207
Autothreshold
into binary images. If you select the Scale threshold check box, the
Threshold scaling factor appears in the dialog box. Enter a scalar
value. The block multiplies this scalar value with the threshold value
computed by Otsu’s method and uses the result as the new threshold
value.
In this diagram, DT means data type. You can set the product,
accumulator, quotient, and effectiveness metric data types in the block
mask.
1-208
Autothreshold
Dialog The Main pane of the Autothreshold dialog box appears as shown in
Box the following figure.
Thresholding operator
Specify the condition the block places on the input matrix values.
If you select > or <=, the block outputs 0 or 1 depending on
1-209
Autothreshold
1-210
Autothreshold
The Data Types pane pane of the Autothreshold dialog box appears as
follows. You can use the default fixed-point parameters if your input
has a word length less than or equal to 16.
Rounding mode
Select the rounding mode for fixed-point operations. This
parameter does not apply to the Cast to input DT step shown in
1-211
Autothreshold
1-212
Autothreshold
Accumulator 1, 2, 3, 4
1-213
Autothreshold
Quotient
Choose how to specify the word length and fraction length of the
quotient data type:
• When you select Specify word length, you can enter the
word length of the quotient values in bits. The block sets the
fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the quotient, in bits.
• When you select Slope and bias scaling, you can enter the
word length in bits and the slope of the quotient. The bias of all
signals in the Computer Vision System Toolbox software is 0.
Eff Metric
Choose how to specify the word length and fraction length of the
effectiveness metric data type. This parameter is only visible if,
on the Main tab, you select the Output effectiveness metric
check box.
• When you select Specify word length, you can enter the word
length of the effectiveness metric values, in bits. The block sets
the fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the effectiveness metric
in bits.
• When you select Slope and bias scaling, you can enter the
word length in bits and the slope of the effectiveness metric.
The bias of all signals in the Computer Vision System Toolbox
software is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-214
Autothreshold
ex_vision_autothreshold
1-215
Blob Analysis
Library Statistics
visionstatistics
Description Use the Blob Analysis block to calculate statistics for labeled regions
in a binary image. The block returns quantities such as the centroid,
bounding box, label matrix, and blob count. The Blob Analysis block
supports input and output variable size signals.
For information on pixel and spatial coordinate system definitions, see
“Expressing Image Locations” in the Image Processing Toolbox User
Guide. Use the Selector block from the Simulink, to select certain blobs
based on their statistics.
Port Descriptions
1-216
Blob Analysis
Dialog Box
The Main pane of the Blob Analysis dialog box appears as shown in the
following figure. Use the check boxes to specify the statistics values
you want the block to output. For a full description of each of these
statistics, see the regionprops function reference page in the Image
Processing Toolbox documentation.
1-217
Blob Analysis
Area
Select this check box to output a vector that represents the
number of pixels in labeled regions
1-218
Blob Analysis
Centroid
Select this check box to output an M-by-2 matrix of [x y] centroid
coordinates. The rows represent the coordinates of the centroid of
each region, where M represents the number of blobs.
Example: Suppose there are two blobs, where the row and column
coordinates of their centroids are x1, y1 and x2, y2, respectively.
The block outputs:
x1 y1
x y2
2
at the Centroid port.
Bounding box
Select this check box to output an M-by-4 matrix of [x y width
height] bounding boxes. The rows represent the coordinates of
each bounding box, where M represents the number of blobs.
Example: Suppose there are two blobs, where x and y define the
location of the upper-left corner of the bounding box, and w,
h define the width and height of the bounding box. The block
outputs
x1 y1 w1 h1
x y2 w2 h2
2
at the BBox port.
Major axis length
Select this check box to output a vector with the following
characteristics:
• Represents the lengths of the major axes of ellipses
• Has the same normalized second central moments as the
labeled regions
1-219
Blob Analysis
π π
− and
2 2
Eccentricity
Select this check box to output a vector that represents the
eccentricities of ellipses that have the same second moments as
the region
Equivalent diameter squared
Select this check box to output a vector that represents the
equivalent diameters squared
Extent
Select this check box to output a vector that represents the results
of dividing the areas of the blobs by the area of their bounding
boxes
Perimeter
Select this check box to output an N-by-1 vector of the perimeter
lengths, in pixels, of each blob, where N is the number of blobs.
Statistics output data type
Specify the data type of the outputs at the Centroid, MajorAxis,
MinorAxis, Orientation, Eccentricity, Equivalent diameter
squared, and Extent ports. If you select Fixed-point, the
block cannot calculate the major axis, minor axis, orientation, or
eccentricity and the associated check boxes become unavailable.
1-220
Blob Analysis
Connectivity
Define which pixels connect to each other. If you want to connect
pixels located on the top, bottom, left, and right, select 4. If you
want to connect pixels to the other pixels on the top, bottom, left,
right, and diagonally, select 8. For more information about this
parameter, see the Label block reference page.
The block calculates the distance between the center of each pixel
(marked by the black dots) and estimates the perimeter to be 22.
The next figure illustrates how the block calculates the perimeter
of a blob when you set the Connectivity parameter to 8.
1-221
Blob Analysis
The block takes a different path around the blob and estimates
the perimeter to be 18 + 2 2 .
Output label matrix
Select this check box, to output the label matrix at the Label port.
The pixels equal to 0 represent the background. The pixels equal
to 1 represent the first object. The pixels equal to 2 represent the
second object, and so on.
The Blob Properties pane of the Blob Analysis dialog box appears
as shown in the following figure.
1-222
Blob Analysis
1-223
Blob Analysis
on both the value of this parameter, and on the size of the input
image. The number of blobs the block outputs may be limited
by the input image size.
Warn if maximum number of blobs is exceeded
Select this check box to output a warning when the number of
blobs in an image is greater than the value of Maximum number
of blobs parameter.
Output number of blobs found
Select this check box to output a scalar value that represents the
actual number of connected regions in each image at the Count
port.
Specify maximum blob area in pixels
Select this check box to enter the minimum blob area in the edit
box that appears beside the check box. The blob gets a label if
the number of pixels meets the minimum size specified. The
maximum allowable value is the maximum of uint32 data type.
This parameter is tunable.
Exclude blobs touching image border
Select this check box to exclude a labeled blob that contains at
least one border pixel.
Output blob statistics as a variable-size signal
Select this check box to output blob statistics as a variable-size
signal. Selecting this check box means that you do not need to
specify fill values.
Fill empty spaces in outputs outputs
Select this check box to fill empty spaces in the statistical vectors
with the values you specify in the Fill values parameter.
The Fill empty spaces in outputs check box does not appear
when you select the Output blob statistics as a variable-size
signal check box.
1-224
Blob Analysis
Fill values
If you enter a scalar value, the block fills all the empty spaces in
the statistical vectors with this value. If you enter a vector, it
must have the same length as the number of selected statistics.
The block uses each vector element to fill a different statistics
vector. If the empty spaces do not affect your computation, you
can deselect the Fill empty spaces in outputs check box. As a
best practice, leave this check box selected.
The Fill values parameter is not visible when you select the
Output blob statistics as a variable-size signal check box.
The Fixed-Point Data Types pane of the Blob Analysis dialog box
appears as shown in the following figure.
The parameters on the Fixed-point tab apply only when you set the
Statistics output data type parameter to Specify via Fixed-point
tab.
1-225
Blob Analysis
Rounding mode
Select the rounding mode Floor, Ceiling, Nearest or Zero for
fixed-point operations.
1-226
Blob Analysis
Overflow mode
Select the overflow mode, Wrap or Saturate for fixed-point
operations.
Product output
When you select Binary point scaling, you can enter the Word
length and the Fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the
Word length in bits, and the Slope of the product output. All
signals in the Computer Vision System Toolbox software have
a bias of 0.
The block places the output of the multiplier into the Product
output data type and scaling. The computation of the equivalent
diameter squared uses the product output data type. During this
computation, the block multiplies the blob area (stored in the
accumulator) by the 4/pi factor. This factor has a word length that
equals the value of Equivalent diameter squared output data
type Word length. The value of the Fraction length equals its
word length minus two. Use this parameter to specify how to
designate this product output word and fraction lengths.
Accumulator
When you select Same as product output the characteristics
match the characteristics of the product output.
When you select Binary point scaling, you can enter the Word
length and the Fraction length of the accumulator, in bits.
When you select Slope and bias scaling, you can enter the
Word length, in bits, and the Slope of the Accumulator. All
1-227
Blob Analysis
1-228
Blob Analysis
The Fill empty spaces in outputs check box is not visible when
you select the Output blob statistics as a variable-size signal
check box.
Perimeter output
Choose how to specify the Word length and Fraction length of
the output at the Perimeter port:
1-229
Blob Analysis
1-230
Blob Analysis (To Be Removed)
Library Statistics
Description
Note This Blob Analysis block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated Blob Analysis block that
uses the one-based, [x y] coordinate system.
1-231
Block Matching
Description The Block Matching block estimates motion between two images or
two video frames using “blocks” of pixels. The Block Matching block
matches the block of pixels in frame k to a block of pixels in frame k+1
by moving the block of pixels over a search region.
Suppose the input to the block is frame k. The Block Matching block
performs the following steps:
1 The block subdivides this frame using the values you enter for the
Block size [height width] and Overlap [r c] parameters. In the
following example, the Overlap [r c] parameter is [0 0].
2 For each subdivision or block in frame k+1, the Block Matching block
establishes a search region based on the value you enter for the
Maximum displacement [r c] parameter.
3 The block searches for the new block location using either the
Exhaustive or Three-step search method.
1-232
Block Matching
Center pixel
Block
STEP 2: Establish the search region in frame k+1. STEP 3: Search for the new block location in frame k+1.
1-233
Block Matching
Complex
Port Output Supported Data Types Values
Supported
I/I1 Scalar, vector, or matrix • Double-precision floating point No
of intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned
integer
I2 Scalar, vector, or matrix Same as I port No
of intensity values
|V|^2 Matrix of velocity Same as I port No
magnitudes
V Matrix of velocity Same as I port Yes
components in complex
form
• If you select Exhaustive, the block selects the location of the block
of pixels in frame k+1 by moving the block over the search region 1
pixel at a time. This process is computationally expensive.
• If you select Three-step, the block searches for the block of pixels
in frame k+1 that best matches the block of pixels in frame k using
a steadily decreasing step size. The block begins with a step size
1-234
Block Matching
Use the Block matching criteria parameter to specify how the block
measures the similarity of the block of pixels in frame k to the block of
pixels in frame k+1. If you select Mean square error (MSE), the Block
Matching block estimates the displacement of the center pixel of the
block as the (d1 , d2 ) values that minimize the following MSE equation:
1
MSE(d1 , d2 ) = ∑ ∑[ s(n1 , n2 , k) − s(n1 + d1 , n2 + d2 , k + 1)]2
N1 × N 2 (n ,n ), ∈B
1 2
1
MAD(d1 , d2 ) = ∑ ∑| s(n1 , n2 , k) − s(n1 + d1 , n2 + d2 , k + 1)|
N1 × N 2 (n ,n ), ∈B
1 2
1-235
Block Matching
move from image to image or frame to frame. The block uses this value
to determine the size of the search region.
Use the Velocity output parameter to specify the block’s output. If you
select Magnitude-squared, the block outputs the optical flow matrix
where each element is of the form u2+v2. If you select Horizontal and
vertical components in complex form, the block outputs the optical
flow matrix where each element is of the form u + jv . The real part of
each value is the horizontal velocity component and the imaginary part
of each value is the vertical velocity component.
Fixed-Point The following diagram shows the data types used in the Block Matching
Data block for fixed-point signals.
Types
1-236
Block Matching
The result of each addition remains The result of each multiplication remains
in the accumulator data type. in the product data type.
Accumulator
data type
CAST ADDER
Input Accumulator
Accumulator data type
data type data type
You can set the accumulator and output data types in the block mask
as discussed in the next section.
1-237
Block Matching
Dialog The Main pane of the Block Matching dialog box appears as shown in
Box the following figure.
1-238
Block Matching
The Data Types pane of the Block Matching dialog box appears as
shown in the following figure.
1-239
Block Matching
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Product output
1-240
Block Matching
1-241
Block Matching
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Binary point scaling, you can enter the
word length of the output, in bits. The fractional length is
always 0.
• When you select Slope and bias scaling, you can enter the
word length, in bits, of the output. The bias of all signals in the
Computer Vision System Toolbox software is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-242
Block Processing
Library Utilities
visionutilities
Subsystem
The blocks inside the subsystem dictate the frame status of the input
and output signals, whether single channel or multichannel signals are
supported, and which data types are supported by this block.
1-243
Block Processing
1-244
Block Processing
Dialog The Block Processing dialog box appears as shown in the following
Box figure.
Number of inputs
Enter the number of input ports on the Block Processing block.
Add port to supply subsystem parameters
Add an input port to the block to supply subsystem parameters.
Number of outputs
Enter the number of output ports on the Block Processing block.
1-245
Block Processing
Block size
Specify the size of each submatrix in cell array format. Each
vector in the cell array corresponds to one input.
Overlap
Specify the overlap of each submatrix in cell array format. Each
vector in the cell array corresponds to the overlap of one input.
Traverse order
Determines how the block extracts submatrices from the input
matrix. If you select Row-wise, the block extracts submatrices
by moving across the rows. If you select Column-wise, the block
extracts submatrices by moving down the columns.
Open Subsystem
Click this button to open the block’s subsystem. Click-and-drag
blocks into this subsystem to define the processing operation(s)
the block performs on the submatrices.
1-246
Bottom-hat
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of • Double-precision floating point No
intensity values
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Nhood Matrix or vector of ones Boolean No
and zeros that represents
the neighborhood values
Output Scalar, vector, or matrix Same as I port No
that represents the
filtered image
If your input image is a binary image, for the Input image type
parameter, select Binary. If your input image is an intensity image,
select Intensity.
1-247
Bottom-hat
Dialog The Bottom-hat dialog box appears as shown in the following figure.
Box
1-248
Bottom-hat
1-249
Chroma Resampling
Library Conversions
visionconversions
Complex
Port Input/Output Supported Data Types Values
Supported
Cb Matrix that • Double-precision floating point No
represents one
• Single-precision floating point
chrominance
component of an • 8-bit unsigned integer
image
Cr Matrix that Same as Cb port No
represents one
chrominance
component of an
image
The data type of the output signals is the same as the data type of the
input signals.
1-250
Chroma Resampling
Y pixel
Cb and Cr pixel
Downsampling
If, for the Resampling parameter, you select 4:4:4 to 4:2:2,
4:4:4 to 4:2:0 (MPEG1), 4:4:4 to 4:2:0 (MPEG2),
4:4:4 to 4:1:1, 4:2:2 to 4:2:0 (MPEG1), or
4:2:2 to 4:2:0 (MPEG2), the block performs a downsampling
operation. When the block downsamples from one format to another, it
can bandlimit the input signal by applying a lowpass filter to prevent
aliasing.
If, for the Antialiasing filter parameter, you select Default, the block
uses a built-in lowpass filter to prevent aliasing.
If, for the Resampling parameter, you select 4:4:4 to 4:2:2,
4:4:4 to 4:2:0 (MPEG1), 4:4:4 to 4:2:0 (MPEG2), or
4:4:4 to 4:1:1 and, for the Antialiasing filter parameter, you select
1-251
Chroma Resampling
Upsampling
If, for the Resampling parameter, you select 4:2:2 to 4:4:4,
4:2:0 (MPEG1) to 4:2:2, 4:2:0 (MPEG1) to 4:4:4,
4:2:0 (MPEG2) to 4:2:2, 4:2:0 (MPEG2) to 4:4:4, or
4:1:1 to 4:4:4, the block performs an upsampling operation.
When the block upsamples from one format to another, it uses
interpolation to approximate the missing chrominance values. If, for
the Interpolation parameter, you select Linear, the block uses linear
interpolation to calculate the missing values. If, for the Interpolation
parameter, you select Pixel replication, the block replicates the
chrominance values of the neighboring pixels to create the upsampled
image.
1-252
Chroma Resampling
When you use the row-major functionality, you must consider the
following issues:
• When you select this check box, the signal dimensions of the Chroma
Resampling block’s input are swapped.
• All the Computer Vision System Toolbox blocks can be used to
process data that is in the row-major format, but you need to know
the image dimensions when you develop your algorithms.
For example, if you use the 2-D FIR Filter block, you need to verify
that your filter coefficients are transposed. If you are using the
Rotate block, you need to use negative rotation angles, etc.
• Only three blocks have the Input image is transposed (data
order is row major) check box. They are the Chroma Resampling,
Deinterlacing, and Insert Text blocks. You need to select this check
box to enable row-major functionality in these blocks. All other blocks
must be properly configured to process data in row-major format.
1-253
Chroma Resampling
Step 1:
Create block diagram Algorithm
blocks
Step 2:
Replace source, transpose, and
Embedded sink blocks with target source Embedded
target source and sink blocks that produce target sink
block data in row-major format block
See the DM642 EVM Video ADC and DM642 EVM Video DAC reference
pages.
1-254
Chroma Resampling
Dialog The Chroma Resampling dialog box appears as shown in the following
Box figure.
Resampling
Specify the resampling format.
Antialiasing filter
Specify the lowpass filter that the block uses to prevent aliasing.
If you select Default, the block uses a built-in lowpass filter. If
you select User-defined, the Horizontal filter coefficients
and/or Vertical filter coefficients parameters appear on the
dialog box. If you select None, the block does not filter the input
signal. This parameter is visible when you are downsampling
the chrominance values.
Horizontal filter coefficients
Enter the filter coefficients to apply to your input signal.
This parameter is visible if, for the Resampling parameter,
you select 4:4:4 to 4:2:2, 4:4:4 to 4:2:0 (MPEG1),
4:4:4 to 4:2:0 (MPEG2), or 4:4:4 to 4:1:1 and, for the
Antialiasing filter parameter, you select User-defined.
Vertical filter coefficients
Enter the filter coefficients to apply to your input signal. This
parameter is visible if, for the Resampling parameter, you
1-255
Chroma Resampling
References [1] Haskell, Barry G., Atul Puri, and Arun N. Netravali. Digital Video:
An Introduction to MPEG-2. New York: Chapman & Hall, 1996.
[3] Wang, Yao, Jorn Ostermann, Ya-Qin Zhang. Video Processing and
Communications. Upper Saddle River, NJ: Prentice Hall, 2002.
1-256
Chroma Resampling
1-257
Closing
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating point No
values
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
Nhood Matrix or vector of ones and Boolean No
zeros that represents the
neighborhood values
Output Vector or matrix of intensity Same as I port No
values that represents the
closed image
The output signal has the same data type as the input to the I port.
1-258
Closing
Dialog The Closing dialog box appears as shown in the following figure.
Box
1-259
Closing
References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.
1-260
Color Space Conversion
Library Conversions
visionconversions
Description The Color Space Conversion block converts color information between
color spaces. Use the Conversion parameter to specify the color spaces
you are converting between. Your choices are R'G'B' to Y'CbCr,
Y'CbCr to R'G'B', R'G'B' to intensity, R'G'B' to HSV, HSV to
R'G'B', sR'G'B' to XYZ, XYZ to sR'G'B', sR'G'B' to L*a*b*, and
L*a*b* to sR'G'B'.
Complex
Port Input/Output Supported Data Types Values
Supported
Input / M-by-N-by-P color video signal • Double-precision floating No
Output where P is the number of color point
planes
• Single-precision floating point
• 8-bit unsigned integer
R’ Matrix that represents one Same as the Input port No
plane of the input RGB video
stream
G’ Matrix that represents one Same as the Input port No
plane of the input RGB video
stream
B’ Matrix that represents one Same as the Input port No
plane of the input RGB video
stream
Y’ Matrix that represents the luma Same as the Input port No
portion of an image
1-261
Color Space Conversion
Complex
Port Input/Output Supported Data Types Values
Supported
Cb Matrix that represents one Same as the Input port No
chrominance component of an
image
Cr Matrix that represents one Same as the Input port No
chrominance component of an
image
I’ Matrix of intensity values Same as the Input port No
H Matrix that represents the hue • Double-precision floating No
component of an image point
• Single-precision floating point
S Matrix that represents Same as the H port No
represent the saturation
component of an image
V Matrix that represents the Same as the H port No
value (brightness) component of
an image
X Matrix that represents the X Same as the H port No
component of an image
Y Matrix that represents the Y Same as the H port No
component of an image
Z Matrix that represents the Z Same as the H port No
component of an image
L* Matrix that represents the Same as the H port No
luminance portion of an image
a* Matrix that represents the a* Same as the H port No
component of an image
b* Matrix that represents the b* Same as the H port No
component of an image
1-262
Color Space Conversion
The data type of the output signal is the same as the data type of the
input signal.
Use the Image signal parameter to specify how to input and output
a color video signal. If you select One multidimensional signal, the
block accepts an M-by-N-by-P color video signal, where P is the number
of color planes, at one port. If you select Separate color signals,
additional ports appear on the block. Each port accepts one M-by-N
plane of an RGB video stream.
Note The prime notation indicates that the signals are gamma
corrected.
⎡ Y ′ ⎤ ⎡ 16 ⎤ ⎡ R′ ⎤
⎢Cb⎥ = ⎢128 ⎥ + A × ⎢ G ′ ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢⎣ Cr ⎥⎦ ⎢⎣128 ⎥⎦ ⎢⎣ B′ ⎥⎦
⎡ R′ ⎤ ⎛ ⎡ Y ′ ⎤ ⎡ 16 ⎤ ⎞
⎢ G ′ ⎥ = B × ⎜ ⎢Cb⎥ − ⎢128 ⎥ ⎟
⎢ ⎥ ⎜⎢ ⎥ ⎢ ⎥⎟
⎢⎣ B′ ⎥⎦ ⎜ ⎢ Cr ⎥ ⎢128 ⎥ ⎟
⎝⎣ ⎦ ⎣ ⎦⎠
The values in the A and B matrices are based on your choices for the
Use conversion specified by and Scanning standard parameters.
The following table summarizes the possible values:
1-263
Color Space Conversion
B ⎡1.16438356 0 1.79274107 ⎤
⎢1.16438356 -0.21324861 -0.53290933⎥
⎢ ⎥
1.1643836 0 1.5960268 ⎣⎢1.1643
38356 2.11240179 0 ⎥⎦
1.1643836 0 1.5960268
1.1643836 0.39176229 0.81296765 1.1643836 0.39176229 0.81296765
1.1643836 2.0172321 0 1.1643836 2.0172321 0
Conversion R’B’G’ to Intensity
The conversion from the R’B’G’ color space to intensity is defined by the
following equation:
⎡ R′ ⎤
intensity = [0.299 0.587 0.114 ] ⎢⎢ G ′ ⎥⎥
⎢⎣ B′ ⎥⎦
1-264
Color Space Conversion
⎧ ⎛ G ′ − B′ ⎞
⎪ ⎜ MAX − MIN ⎟ / 6, if R′ = MAX
⎪ ⎝ ⎠
⎪⎛ B′ − R′ ⎞
H = ⎨⎜ 2 + ⎟ / 6, if G ′ = MAX
⎪⎝ MAX − MIN ⎠
⎪⎛ R′ − G ′ ⎞
⎪⎜ 4 + ⎟ / 6, if B′ = MAX
⎩⎝ MAX − MIN ⎠
MAX − MIN
S=
MAX
V = MAX
Hi = ⎢⎣6 H ⎥⎦
f = 6 H − Hi
p =1− S
q = 1 − fS
t = 1 − (1 − f ) S
if Hi = 0, Rtmp = 1, Gtmp = t, Btmp = p
if Hi = 1, Rtmp = q, Gtmp = 1, Btmp = p
if Hi = 2, Rtmp = p, Gtmp = 1, Btmp = t
if Hi = 3, Rtmp = p, Gtmp = q, Btmp = 1
if Hi = 4, Rtmp = t, Gtmp = p, Btmp = 1
if Hi = 5, Rtmp = 1, Gtmp = p, Btmp = q
u = V / max( Rtmp , Gtmp , Btmp )
R′ = uRtmp
G ′ = uGtmp
B′ = uBtmp
For more information about the HSV color space, see “HSV Color Space”
in the Image Processing Toolbox documentation.
1-265
Color Space Conversion
If ′
RsRGB ′
, GsRGB ′
, BsRGB ≤ 0.03928
′
RsRGB = RsRGB / 12.92
′ GB / 12.92
GsRGB = GsR
′
BsRGB = BsRGB / 12.92
′
otherwise, if RsRGB ′
, GsRGB ′ B > 0.03928
, BsRG
2 .4
( R′ + 0.055)
RsRGB = ⎡ sRGB ⎤
⎢⎣ 1.055⎥⎦
2 .4
(G ′ + 0.055)
GsRGB = ⎡ sRGB ⎤
⎢⎣ 1.055⎥⎦
2 .4
( B′ + 0.055)
BsRGB = ⎡ sRGB ⎤
⎣⎢ 1.055⎦⎥
Then the block converts the sRGB values to XYZ values using the
following equation:
−1
⎡ RsRGB ⎤ ⎡0.41239079926596 0.35758433938388 0.18048078840183 ⎤ ⎡X⎤
⎢G ⎥ ⎢ ⎥ × ⎢⎢ Y ⎥⎥
⎢ sRGB ⎥ = ⎢0.21263900587151 0.71516867876776 0.07219231536073 ⎥
⎢⎣ BsRGB ⎥⎦ ⎢⎣0.01933081871559 0.11919477979463 0.95053215224966 ⎥⎦ ⎣⎢ Z ⎦⎥
1-266
Color Space Conversion
Then the block applies gamma correction to obtain the sR’G’B’ values.
This process is described by the following equations:
1-267
Color Space Conversion
a* = 500( f ( X X n ) − f (Y Yn ))
b* = 200( f (Y Yn ) − f ( Z Zn )),
where f (t) = t1 3 , for t > 0.008856
f (t) = 7.787t + 16 166, otherwise
X = X n ( P + a * 500)3
Y = Yn P 3
Z = Zn ( P − b * 200)3 ,
where P = (L
L * +16) / 116
1-268
Color Space Conversion
Dialog The Color Space Conversion dialog box appears as shown in the
Box following figure.
Conversion
Specify the color spaces you are converting between. Your
choices are R'G'B' to Y'CbCr, Y'CbCr to R'G'B', R'G'B' to
intensity, R'G'B' to HSV, HSV to R'G'B', sR'G'B' to XYZ,
XYZ to sR'G'B', sR'G'B' to L*a*b*, and L*a*b* to sR'G'B'.
Use conversion specified by
Specify the standard to use to convert your values between the
R’G’B’ and Y’CbCr color spaces. Your choices are Rec. 601
(SDTV) or Rec. 709 (HDTV). This parameter is only available
1-269
Color Space Conversion
[5] Berns, Roy S. Principles of Color Technology, 3rd ed. New York:
John Wiley & Sons, 2000.
1-270
Color Space Conversion
1-271
Compositing
Purpose Combine pixel values of two images, overlay one image over another,
or highlight selected pixels
Description
You can use the Compositing block to combine two images. Each pixel
of the output image is a linear combination of the pixels in each input
image. This process is defined by the following equation:
You can define the amount by which to scale each pixel value before
combining them using the opacity factor, X, where , 0 ≤ X ≤ 1 .
You can use the Compositing block to overlay one image over another
image. The masking factor and the location determine which pixels are
overwritten. Masking factors can be 0 or 1, where 0 corresponds to not
overwriting pixels and 1 corresponds to overwriting pixels.
You can also use this block to highlight selected pixels in the input
image. The block uses a binary input image at the Mask port, to specify
which pixels to highlight.
1-272
Compositing
You can set the product output, accumulator, and output data types in
the block mask as discussed in the next section.
Dialog The Main pane of the Compositing dialog box appears as shown in
Box the following figure.
1-273
Compositing
1-274
Compositing
Operation
Specify the operation you want the block to perform. If you choose
Blend, the block linearly combines the pixels of one image with
another image. If you choose Binary mask, the block overwrites
the pixel values of one image with the pixel values of another
image. If you choose Highlight selected pixels, the block uses
the binary image input at the Mask port. Using this image, the
block then determines which pixels are set to the maximum value
supported by their data type.
Blend
If, for the Operation parameter, you choose Blend, the Opacity
factor(s) source parameter appears on the dialog box. Use this
parameter to indicate where to specify the opacity factor(s).
• If you choose Specify via dialog, the Opacity factor(s)
parameter appears on the dialog box. Use this parameter to
define the amount by which the block scales each pixel values
for input image at the Image2 port before combining them
with the pixel values of the input image at Image1 port. You
can enter a scalar value used for all pixels or a matrix of values
that is the same size as the input image at the Image2 port.
• If you choose Input port, the Factor port appears on the
block. The input to this port must be a scalar or matrix of
values as described for the Opacity factor(s) parameter. If
the input to the Image1 and Image2 ports is floating point,
the input to this port must be the same floating-point data type.
Binary mask
If, for the Operation parameter, you choose Binary mask, the
Mask source parameter appears on the dialog box. Use this
parameter to indicate where to specify the masking factor(s).
• If you choose Specify via dialog, the Mask parameter
appears on the dialog box. Use this parameter and the location
source of the image to define which pixels are overwritten. You
1-275
Compositing
1-276
Compositing
factor for each pixel. This parameter is visible if, for the Mask
source parameter, you choose Specify via dialog. Tunable.
Location source
Use this parameter to specify where to enter the location of the
upper-left corner of the image input at input port Image2. You
can choose either Specify via dialog or Input port.
When you choose Specify via dialog, you can set the Location
[x y] parameter.
When you choose Input port, the Location port appears on the
block. The input to this port must be a two-element vector as
described for the Location [x y] parameter.
Location [x y]
Enter a two-element vector that specifies the row and column
position of the upper-left corner of the image input at Image2
port. The position is relative to the upper-left corner of the
image input at Image1 port. This parameter is visible if, for the
Location source parameter, you choose Specify via dialog.
Tunable.
Positive values move the image down and to the right; negative
values move the image up and to the left. If the first element is
greater than the number of rows in the Image1 matrix, the value
is clipped to the total number of rows. If the second element is
greater than the number of columns in the input Image1 matrix,
the value is clipped to the total number of columns.
The Data Types pane of the Compositing dialog box appears as follows.
These parameters apply only when the Operation parameter is set to
Blend.
1-277
Compositing
1-278
Compositing
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Opacity factor
Choose how to specify the word length and fraction length of the
opacity factor:
• When you select Same word length as input, these
characteristics match those of the input to the block.
• When you select Specify word length, enter the word length
of the opacity factor.
• When you select Binary point scaling, you can enter the
word length of the opacity factor, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, of the opacity factor. The bias of all signals
in the Computer Vision System Toolbox software is 0.
Product output
As the previous figure shows, the block places the output of the
multiplier into the product output data type and scaling. Use this
parameter to specify how to designate this product output word
and fraction lengths.
• When you select Same as first input, these characteristics
match those of the input to the block.
1-279
Compositing
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
software is 0.
Accumulator
1-280
Compositing
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Same as first input, these characteristics
match those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. The bias of all
signals in the Computer Vision System Toolbox software is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
Supported
Data
Types
Complex
Port Input/Output Supported Data Types Values
Supported
Image 1 M-by-N matrix of intensity • Double-precision floating No
values or an M-by-N-by-P color point
video signal where P is the
• Single-precision floating point
number of color planes
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed
integer
1-281
Compositing
Complex
Port Input/Output Supported Data Types Values
Supported
1-282
Compositing
Complex
Port Input/Output Supported Data Types Values
Supported
Location Two-element vector [x y], that • Double-precision floating No
specifies the position of the point. (Only supported
upper-left corner of the image if the input to the Image
input at port I2 1 and Image 2 ports is a
floating-point data type.)
• Single-precision floating
point. (Only supported
if the input to the Image
1 and Image 2 ports is a
floating-point data type.)
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
Output Vector or matrix of intensity or Same as Image 1 port No
color values
1-283
Compositing (To Be Removed)
Purpose Combine pixel values of two images, overlay one image over another,
or highlight selected pixels
Description
1-284
Contrast Adjustment
Number of pixels
1500
These values are
scaled to lower
output limit.
Pixel value
50 100 150 200 250
Number of pixels
1000
Pixel value
25 50 75 100 125
1-285
Contrast Adjustment
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of • Double-precision floating point No
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Output Scalar, vector, or matrix Same as I port No
of intensity values or a
scalar, vector, or matrix
that represents one plane
of the RGB video stream
1-286
Contrast Adjustment
If you select Full input data range [min max], uses the
minimum input value as the lower input limit and the maximum
input value as the upper input limit.
If you select User-defined, the Range [low high] parameter
associated with this option appears. Enter a two-element vector of
scalar values, where the first element corresponds to the lower input
limit and the second element corresponds to the upper input limit.
If you select Range determined by saturating outlier pixels,
the Percentage of pixels to saturate [low high] (in %), Specify
number of histogram bins (used to calculate the range when
outliers are eliminated), and Number of histogram bins
parameters appear on the block. The block uses these parameter
values to calculate the input limits in this three-step process:
3 Find the lower input limit such that the percentage of pixels with
values smaller than the lower limit is at most the value of the first
element of the Percentage of pixels to saturate [low high] (in
%) parameter. Similarly, find the upper input limit such that the
percentage of pixels with values greater than the upper limit is at
least the value of the second element of the parameter.
Output limits
Use the Adjust pixel values to parameter to specify the upper and
lower output limits.
If you select Full data type range, the block uses the minimum
value of the input data type as the lower output limit and the
maximum value of the input data type as the upper out
1-287
Contrast Adjustment
If any input pixel has a NAN value, the block maps the pixels with valid
numerical values according to the user-specified method. It maps the
NAN pixels to the lower limit of the Adjust pixels values to parameter.
Examples
See “Adjust the Contrast of Intensity Images” in the Computer Vision
System Toolbox User’s Guide.
1-288
Contrast Adjustment
Dialog The Contrast Adjustment dialog box appears as shown in the following
Box figure.
1-289
Contrast Adjustment
1-290
Contrast Adjustment
The Data Types pane of the Contrast Adjustment dialog box appears
as shown in the following figure.
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
1-291
Contrast Adjustment
Product 1
The product output type when the block calculates the ratio
between the input data range and the number of histogram bins.
Accumulator
data type
MULTIPLIER
sfix8_En7 Product output
data type
When you select Binary point scaling, you can enter the word
length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The bias
of all signals in the Computer Vision System Toolbox software is 0.
Product 2
The product output type when the block calculates the bin location
of each input value.
Accumulator
data type
MULTIPLIER
sfix8_En7 Product output
data type
1-292
Contrast Adjustment
When you select Binary point scaling, you can enter the word
length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The bias
of all signals in the Computer Vision System Toolbox software is 0.
This parameter is visible if, for the Adjust pixel values from
parameter, you select Range determined by saturating
outlier pixels.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-293
Corner Detection
Description
The Corner Detection block finds corners in an image using the Harris
corner detection (by Harris & Stephens), minimum eigenvalue (by Shi
& Tomasi), or local intensity comparison (Features from Accelerated
Segment Test, FAST by Rosten & Drummond) method. The block finds
the corners in the image based on the pixels that have the largest corner
metric values.
For the most accurate results, use the “Minimum Eigenvalue Method”
on page 1-295. For the fastest computation, use the “Local Intensity
Comparison” on page 1-296. For the trade-off between accuracy and
computation, use the “Harris Corner Detection Method” on page 1-296.
Port Description
1-294
Corner Detection
⎡ A C⎤
M=⎢ ⎥
⎣ C B⎦
A = ( I x )2 ⊗ w
B = ( I y )2 ⊗ w
C = ( I x I y )2 ⊗ w
where I x and I y are the gradients of the input image, I, in the x and y
direction, respectively. The ⊗ symbol denotes a convolution operation.
1-295
Corner Detection
R = AB − C 2 − k( A + B)2
1-296
Corner Detection
Surrounding
pixel j
Pixel under
consideration
Angle
1-297
Corner Detection
⎛ ⎞
R = max ⎜ ∑ I p − I j − T, ∑ I p − I j − T, ⎟
⎜ ⎟
⎝ j: I j ≥ I p + T j: I j ≤ I p − T ⎠
1-298
Corner Detection
1-299
Corner Detection
1-300
Corner Detection
Dialog The Corner Detection dialog box appears as shown in the following
Box figure.
1-301
Corner Detection
1-302
Corner Detection
Method
Specify the method to use to find the corner values. Your
choices are Harris corner detection (Harris & Stephens),
Minimum eigenvalue (Shi & Tomasi), and Local intensity
comparison (Rosten & Drummond).
Sensitivity factor (0<k<0.25)
Specify the sensitivity factor, k. The smaller the value of k
the more likely the algorithm is to detect sharp corners. This
parameter is visible if you set the Method parameter to Harris
corner detection (Harris & Stephens). This parameter is
tunable.
Coefficients for separable smoothing filter
Specify a vector of filter coefficients for the smoothing filter.
This parameter is visible if you set the Method parameter to
Harris corner detection (Harris & Stephens) or Minimum
eigenvalue (Shi & Tomasi).
Intensity comparison threshold
Specify the threshold value used to find valid surrounding pixels.
This parameter is visible if you set the Method parameter to
Local intensity comparison (Rosten & Drummond). This
parameter is tunable.
Maximum angle to be considered a corner (in degrees)
Specify the maximum corner angle. This parameter is visible if
you set the Method parameter to Local intensity comparison
(Rosten & Drummond). This parameter is tunable for Simulation
only.
Output
Specify the block output. Your choices are Corner location,
Corner location and metric matrix, and Metric matrix.
The block outputs the corner locations in an M-by-2 matrix of [x
y] coordinates, where M represents the number of corners. The
block outputs the corner metric value in a matrix, the same size
as the input image.
1-303
Corner Detection
The block repeats this process until it finds all the corners in
the image or it finds the number of corners you specified in the
Maximum number of corners parameter.
1-304
Corner Detection
The Data Types pane of the Corner Detection dialog box appears as
shown in the following figure.
1-305
Corner Detection
1-306
Corner Detection
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Coefficients
Choose how to specify the word length and the fraction length
of the coefficients:
• When you select Same word length as input, the word length
of the coefficients match that of the input to the block. In this
mode, the fraction length of the coefficients is automatically
set to the binary-point only scaling that provides you with the
best precision possible given the value and word length of the
coefficients.
• When you select Specify word length, you can enter the word
length of the coefficients, in bits. The block automatically sets
the fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the coefficients, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the coefficients. The bias
of all signals in the Computer Vision System Toolbox software
is 0.
Product output
As shown in the following figure, the output of the multiplier is
placed into the product output data type and scaling.
1-307
Corner Detection
ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type
1-308
Corner Detection
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the accumulator. The bias
of all signals in the Computer Vision System Toolbox software
is 0.
Memory
Choose how to specify the memory word length and fraction
length:
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. This block
requires power-of-two slope and a bias of 0.
Metric output
Choose how to specify the metric output word length and fraction
length:
• When you select Same as accumulator, these characteristics
match those of the accumulator.
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. This block
requires power-of-two slope and a bias of 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-309
Corner Detection
See Also Find Local Maxima Computer Vision System Toolbox software
Estimate Geometric Computer Vision System Toolbox software
Transformation
1-310
Corner Detection (To Be Removed)
Description
1-311
Deinterlacing
Description The Deinterlacing block takes the input signal, which is the combination
of the top and bottom fields of the interlaced video, and converts it into
deinterlaced video using line repetition, linear interpolation, or vertical
temporal median filtering.
Note This block supports intensity and color images on its ports.
Complex
Port Input/Output Supported Data Types Values
Supported
Input Combination of top and • Double-precision floating point No
bottom fields of interlaced
• Single-precision floating point
video
• Fixed point
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned
integer
Output Frames of deinterlaced Same as Input port No
video
1-312
Deinterlacing
Line Repetition
Row 1 A B C Row 1
Row 2 Row 2 D E F
Row 3 G H I Row 3
Row 4 Row 4 J K L
Row 5 M N O Row 5
Row 6 Row 6 P Q R
Row 1 A B C Row 1 A B C
Row 2 D E F Row 2 A B C
Row 3 G H I Row 3 G H I
Row 4 J K L Row 4 G H I
Row 5 M N O Row 5 M N O
Row 6 P Q R Row 6 M N O
The following figure illustrates the block’s behavior if you select Linear
interpolation.
1-313
Deinterlacing
Linear Interpolation
Row 1 A B C Row 1
Row 2 Row 2 D E F
Row 3 G H I Row 3
Row 4 Row 4 J K L
Row 5 M N O Row 5
Row 6 Row 6 P Q R
Row 1 A B C Row 1 A B C
Row 3 G H I Row 3 G H I
Row 5 M N O Row 5 M N O
Row 6 P Q R Row 6 M N O
1-314
Deinterlacing
Row 1 A B C Row 1
Row 2 Row 2 D E F
Row 3 G H I Row 3
Row 4 Row 4 J K L
Row 5 M N O Row 5
Row 6 Row 6 P Q R
Row 1 A B C Row 1 A B C
Row 3 G H I Row 3 G H I
Row 5 M N O Row 5 M N O
Row 6 P Q R Row 6 M N O
1-315
Deinterlacing
When you use the row-major functionality, you must consider the
following issues:
• When you select this check box, the first two signal dimensions of the
Deinterlacing block’s input are swapped.
• All the Computer Vision System Toolbox blocks can be used to
process data that is in the row-major format, but you need to know
the image dimensions when you develop your algorithms.
For example, if you use the 2-D FIR Filter block, you need to verify
that your filter coefficients are transposed. If you are using the
Rotate block, you need to use negative rotation angles, etc.
• Only three blocks have the Input image is transposed (data
order is row major) check box. They are the Chroma Resampling,
Deinterlacing, and Insert Text blocks. You need to select this check
box to enable row-major functionality in these blocks. All other blocks
must be properly configured to process data in row-major format.
1-316
Deinterlacing
Step 1:
Create block diagram Algorithm
blocks
Step 2:
Replace source, transpose, and
Embedded sink blocks with target source Embedded
target source and sink blocks that produce target sink
block data in row-major format block
See the DM642 EVM Video ADC and DM642 EVM Video DAC reference
pages.
Example
The following example shows you how to use the Deinterlacing block to
remove motion artifacts from an image.
ex_deinterlace
1-317
Deinterlacing
The original image that contains the motion artifacts appears in the
Input Image window.
1-318
Deinterlacing
1-319
Deinterlacing
1-320
Deinterlacing
Accumulator Accumulator
data type data type Output
data type
Input data type RIGHT SHIFT CAST
ADDER
CAST
Accumulator
data type
You can set the product output, accumulator, and output data types in
the block mask as discussed in the next section.
Dialog The Main pane of the Deinterlacing dialog box appears as shown in
Box the following figure.
Deinterlacing method
Specify how the block deinterlaces the video. Your choices
are Line repetition, Linear interpolation, or Vertical
temporal median filtering.
Input image is transposed (data order is row major)
When you select this check box, the block assumes that the input
buffer contains data elements from the first row first, then data
1-321
Deinterlacing
elements from the second row second, and so on through the last
row.
The Data Types pane of the Deinterlacing dialog box appears as shown
in the following figure.
Note The parameters on the Data Types pane are only available if,
for the Deinterlacing method, you select Linear interpolation.
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
1-322
Deinterlacing
Accumulator
ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type
1-323
Deinterlacing
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. This block
requires power-of-two slope and a bias of 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-324
Demosaic
Library Conversions
visionconversions
Description
B G B G
G R G R
B G B G
G R G R
The Demosaic block takes in images in Bayer’s format and outputs RGB
images. The block performs this operation using a gradient-corrected
linear interpolation algorithm or a bilinear interpolation algorithm.
1-325
Demosaic
Complex
Port Input/Output Supported Data Types Values
Supported
I Matrix of intensity values • Double-precision floating point No
• Single-precision floating point
• If, for the Interpolation
algorithm parameter, • Fixed point
you select Bilinear,
• 8-, 16-, and 32-bit signed integer
the number of rows and
columns must be greater • 8-, 16-, and 32-bit unsigned
than or equal to 3. integer
• If, for the Interpolation
algorithm
parameter, you select
Gradient-corrected
linear, the number of
rows and columns must
be greater than or equal
to 5.
R, G, B Matrix that represents one Same as I port No
plane of the input RGB
video stream. Outputs from
the R, G, or B ports have
the same data type.
Image M-by-N matrix of intensity Same as I port No
values or an M-by-N-by-P
color video signal where P is
the number of color planes.
1-326
Demosaic
Input
data type Output
data type
MULTIPLIER CAST ADDER CAST
Accumulator or Accumulator
Input Product output Accumulator data type
data type data type data type
You can set the product output and accumulator data types in the block
mask as discussed in the next section.
1-327
Demosaic
Dialog The Main pane of the Demosaic dialog box appears as shown in the
Box following figure.
Interpolation algorithm
Specify the algorithm the block uses to calculate the missing color
information. Your choices are Bilinear or Gradient-corrected
linear.
Sensor alignment
Select the sequence of R, G and B pixels that correspond to the
2-by-2 block of pixels in the top left corner of the image. You
specify the sequence in left-to-right, top-to-bottom order.
Output image signal
Specify how to output a color video signal. If you select One
multidimensional signal, the block outputs an M-by-N-by-P
color video signal, where P is the number of color planes, at one
port. If you select Separate color signals, additional ports
1-328
Demosaic
The Data Types pane of the Demosaic dialog box appears as shown in
the following figure.
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
1-329
Demosaic
Product output
Accumulator
data type
MULTIPLIER
sfix8_En7 Product output
data type
As depicted in the previous figure, the output of the multiplier is
placed into the product output data type and scaling. Use this
parameter to specify how to designate this product output word
and fraction lengths:
When you select Binary point scaling, you can enter the word
length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The bias
of all signals in the Computer Vision System Toolbox blocks is 0.
Accumulator
ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type
1-330
Demosaic
References [1] Malvar, Henrique S., Li-wei He, and Ross Cutler, “High-Quality
Linear Interpolation for Demosaicing of Bayer-Patterned Color Images,”
Microsoft Research, One Microsoft Way, Redmond, WA 98052
1-331
Dilation
Description The Dilation block rotates the neighborhood or structuring element 180
degrees. Then it slides the neighborhood or structuring element over
an image, finds the local maxima, and creates the output matrix from
these maximum values. If the neighborhood or structuring element has
a center element, the block places the maxima there, as illustrated in
the following figure.
1-332
Dilation
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating point No
values
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned
integer
Nhood Matrix or vector of ones and Boolean No
zeros that represents the
neighborhood values
Output Vector or matrix of intensity Same as I port No
values that represents the
dilated image
The output signal has the same data type as the input to the I port.
Use the Neighborhood or structuring element source parameter to
specify how to enter your neighborhood or structuring element values.
If you select Specify via dialog, the Neighborhood or structuring
element parameter appears in the dialog box. If you select Input
port, the Nhood port appears on the block. Use this port to enter your
neighborhood values as a matrix or vector of 1s and 0s. You can only
specify a structuring element using the dialog box.
Use the Neighborhood or structuring element parameter to define
the neighborhood or structuring element that the block applies to the
image. Specify a neighborhood by entering a matrix or vector of 1s and
0s. Specify a structuring element with the strel function from the
Image Processing Toolbox. If the structuring element is decomposable
into smaller elements, the block executes at higher speeds due to the
1-333
Dilation
Dialog The Dilation dialog box appears as shown in the following figure.
Box
1-334
Dilation
References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.
1-335
Draw Markers
Description The Draw Markers block can draw multiple circles, x-marks, plus signs,
stars, or squares on images by overwriting pixel values. Overwriting
the pixel values embeds the shapes.
This block uses Bresenham’s circle drawing algorithm to draw circles
and Bresenham’s line drawing algorithm to draw all other markers.
Port Description
Complex
Port Input/Output Supported Data Types Values
Supported
Image M-by-N matrix of intensity values • Double-precision floating No
or an M-by-N-by-P color values point
where P is the number of color
• Single-precision floating
planes
point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
R, G, B Scalar, vector, or matrix that Same as Image port No
represents one plane of the input
RGB video stream. Inputs to the
R, G, and B ports must have the
same dimensions and data type.
1-336
Draw Markers
Complex
Port Input/Output Supported Data Types Values
Supported
Pts M-by-2 matrix of [x y] coordinates, • Double-precision floating No
point
x1 y1 • Single-precision floating
x y2
2 point
• 8-, 16-, and 32-bit signed
xM yM integer
where M is the total number • 8-, 16-, and 32-bit unsigned
of markers and each [x y] pair integer
defines the center of a marker.
If the input to the Image port
is an integer, fixed point, or
boolean data type, the input to
the Pts port must also be an
integer data type.
ROI Four-element vector of integers • Double-precision floating No
[x y width height] that define point
a rectangular area in which to
• Single-precision floating
draw the markers. The first two
point
elements represent the one-based
[x y] coordinates of the upper-left • 8-, 16-, and 32-bit signed
corner of the area. The second two integer
elements represent the width and
• 8-, 16-, and 32-bit unsigned
height of the area.
integer
Clr P-element vector or M-by-P matrix Same as Image port No
where P is the number of color
planes.
Output Scalar, vector, or matrix of pixel Same as Image port No
values that contain the marker(s)
1-337
Draw Markers
The output signal is the same size and data type as the inputs to the
Image, R, G, and B ports.
Dialog The Draw Markers dialog box appears as shown in the following figure.
Box
1-338
Draw Markers
Marker shape
Specify the type of marker(s) to draw. Your choices are Circle,
X-mark, Plus, Star, or Square.
1-339
Draw Markers
When you select Circle, X-mark, or Star, and you select the
Use antialiasing check box, the block performs a smoothing
algorithm. The algorithm is similar to the poly2mask function to
determine which subpixels to draw.
Marker size
Enter a scalar value that represents the size of the marker, in
pixels.
When you select the Filled check box, the Fill color source,
Fill color and Opacity factor (between 0 and 1) parameters
appear in the dialog box.
Fill color source
Specify source for fill color value. You can select Specify via
dialog or Input port. This parameter appears when you select
the Filled check box. When you select Input port, the color
input port clr appears on the block.
Fill color
If you select Black, the marker is black. If you select White, the
marker is white. If you select User-specified value, the Color
value(s) parameter appears in the dialog box. This parameter is
visible if you select the Filled check box.
Border color source
Specify source for the border color value to either Specify via
dialog or Input port. Border color options are visible when the
fill shapes options are not selected. This parameter is visible if
1-340
Draw Markers
you select the Filled check box. When you select Input port, the
color input port clr appears on the block.
Border color
Specify the appearance of the shape’s border. If you select Black,
the border is black. If you select White, the border is white. If you
select User-specified value, the Color value(s) parameter
appears in the dialog box. This parameter is visible if you clear
the Fill shapes check box.
Color value(s)
Specify an intensity or color value for the marker’s border or fill.
This parameter appears when you set the Border color or Fill
color parameters, to User-specified value. Tunable.
The following table describes what to enter for the color value
based on the block input and the number of shapes you are
drawing.
1-341
Draw Markers
Draw markers in
Specify the area in which to draw the markers. When you select
Entire image, you can draw markers in the entire image. When
you select Specify region of interest via port, the ROI
port appears on the block. Enter a four-element vector, [x y
width height], where [x y] are the coordinates of the upper-left
corner of the area.
Use antialiasing
Perform a smoothing algorithm on the marker. This parameter is
visible if, for the Marker shape parameter, you select Circle,
X-mark, or Star.
Image signal
Specify how to input and output a color video signal. When you
select One multidimensional signal, the block accepts an
M-by-N-by-P color video signal, where P is the number of color
planes, at one port. When you select Separate color signals,
additional ports appear on the block. Each port accepts one
M-by-N plane of an RGB video stream.
1-342
Draw Markers
1-343
Draw Markers (To Be Removed)
Description
Note This Draw Markers block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated Draw Markers block that
uses the one-based, [x y] coordinate system.
1-344
Draw Shapes
Description The Draw Shapes block draws multiple rectangles, lines, polygons, or
circles on images by overwriting pixel values. As a result, the shapes
are embedded on the output image.
This block uses Bresenham’s line drawing algorithm to draw lines,
polygons, and rectangles. It uses Bresenham’s circle drawing algorithm
to draw circles.
The output signal is the same size and data type as the inputs to the
Image, R, G, and B ports.
You can set the shape fill or border color via the input port or via the
input dialog. Use the color input or color parameter to determine the
appearance of the rectangle(s), line(s), polygon(s), or circle(s).
Port Description
Complex
Supported Data
Port Input/Output Values
Types
Supported
1-345
Draw Shapes
Complex
Supported Data
Port Input/Output Values
Types
Supported
1-346
Draw Shapes
Complex
Supported Data
Port Input/Output Values
Types
Supported
1-347
Draw Shapes
Drawing Rectangles
The Draw Shapes block lets you draw one or more rectangles. Set the
Shape parameter to Rectangles, and then follow the instructions
in the table to specify the input to the Pts port to obtain the desired
number of rectangles.
1-348
Draw Shapes
x1 y1 width1 height1
x y2 width2 height2
2
xM yM widthM heightM
where each row of the matrix
corresponds to a different rectangle
and is of the same form as the vector
for a single rectangle.
1-349
Draw Shapes
1-350
Draw Shapes
1-351
Draw Shapes
If you select the Use antialiasing check box, the block applies an edge
smoothing algorithm.
For examples of how to use the Draw Shapes block to draw a line, see
“Detect Lines in Images” and “Measure Angle Between Lines”.
Drawing Polygons
The Draw Shapes block lets you draw one or more polygons. Set the
Shape parameter to Polygons, and then follow the instructions in the
table to specify the input to the Pts port to obtain the desired number
of polygons.
1-352
Draw Shapes
1-353
Draw Shapes
Drawing Circles
The Draw Shapes block lets you draw one or more circles. Set the Shape
parameter to Circles, and then follow the instructions in the table to
specify the input to the Pts port to obtain the desired number of circles.
1-354
Draw Shapes
x1 y1 radius1
x y2 radius2
2
xM yM radiusM
where each row of the matrix
corresponds to a different circle and
is of the same form as the vector for a
single circle.
1-355
Draw Shapes
Dialog
Box
1-356
Draw Shapes
Shape
Specify the type of shape(s) to draw. Your choices are Rectangles,
Lines, Polygons, or Circles.
When you select this check box, the Fill color source, Fill color
and Opacity factor (between 0 and 1) parameters appear in
the dialog box.
Note If you are generating code and you select the Fill shapes
check box, the word length of the block input(s) cannot exceed
16 bits.
When you do not select the Fill shapes check box, the Border
color source, and Border color parameters are available.
Fill color source
Specify source for fill color value to either Specify via dialog
or Input port. This parameter appears when you select the Fill
shapes check box. When you select Input port, the color input
port clr appears on the block.
Fill color
Specify the fill color for shape. You can specify either Black, White,
or User-specified value. When you select User-specified
value, the Color value(s) parameter appears in the dialog box.
This parameter is visible if you select the Fill shapes check box.
1-357
Draw Shapes
The following table describes what to enter for the color value
based on the block input and the number of shapes you are
drawing.
1-358
Draw Shapes
Draw shapes in
Specify the type of area in which to draw shapes. You can define
one of the following:
• Entire image, enables you to draw shapes in the entire image.
• Specify region of interest via port. When you select
this option, the ROI port appears on the block. Enter a
four-element vector of integer values, [x y width height],
where [x y] are the coordinates of the upper-left corner of the
area.
Note If you specify values that are outside the image, the
block sets the values to the image boundaries.
1-359
Draw Shapes
Use antialiasing
Perform a smoothing algorithm on the line, polygon, or circle.
This parameter is visible if, for the Shape parameter, you select
Lines, Polygons, or Circles.
Image signal
Specify how to input and output a color video signal. Select one of
the following:
• One multidimensional signal, the block accepts an
M-by-N-by-P color video signal, where P is the number of color
planes, at one port.
• Separate color signals, additional ports appear on the
block. Each port accepts one M-by-N plane of an RGB video
stream.
1-360
Draw Shapes (To Be Removed)
Description
Note This Draw Shapes block will be removed in a future release. It
uses the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated Draw Shapes block that
uses the one-based, [x y] coordinate system.
1-361
Edge Detection
Purpose Find edges of objects in images using Sobel, Prewitt, Roberts, or Canny
method
Description If, for the Method parameter, you select Sobel, Prewitt, or Roberts,
the Edge Detection block finds the edges in an input image by
approximating the gradient magnitude of the image. The block
convolves the input matrix with the Sobel, Prewitt, or Roberts kernel.
The block outputs two gradient components of the image, which are
the result of this convolution operation. Alternatively, the block can
perform a thresholding operation on the gradient magnitudes and
output a binary image, which is a matrix of Boolean values. If a pixel
value is 1, it is an edge.
If, for the Method parameter, you select Canny, the Edge Detection
block finds edges by looking for the local maxima of the gradient of
the input image. It calculates the gradient using the derivative of the
Gaussian filter. The Canny method uses two thresholds to detect strong
and weak edges. It includes the weak edges in the output only if they
are connected to strong edges. As a result, the method is more robust to
noise, and more likely to detect true weak edges.
Complex
Port Input/Output Supported Data Types Values
Supported
I Matrix of intensity • Double-precision floating point No
values
• Single-precision floating point
• Fixed point (not supported for the
Canny method)
• 8-, 16-, 32-bit signed integer (not
supported for the Canny method)
1-362
Edge Detection
Complex
Port Input/Output Supported Data Types Values
Supported
The output of the Gv, Gh, G45, and G135 ports is the same data type
as the input to the I port. The input to the Th port must be the same
data type as the input to the I port.
Use the Method parameter to specify which algorithm to use to find
edges. You can select Sobel, Prewitt, Roberts, or Canny to find edges
using the Sobel, Prewitt, Roberts, or Canny method.
Sobel, Prewitt, and Roberts Methods
Use the Output type parameter to select the format of the output. If
you select Binary image, the block outputs a Boolean matrix at the
Edge port. The nonzero elements of this matrix correspond to the edge
pixels and the zero elements correspond to the background pixels. If
you select Gradient components and, for the Method parameter, you
1-363
Edge Detection
1-364
Edge Detection
Canny Method
Select the User-defined threshold check box to define the low and
high threshold values. If you clear this check box, the block computes
the threshold values for you.
Use the Threshold source parameter to specify how to enter your
threshold values. If you select Specify via dialog, the Threshold
[low high] parameter appears in the dialog box. Enter the threshold
values. If a pixel’s magnitude in the gradient image, which is formed
by convolving the input image with the derivative of the Gaussian
filter, exceeds the high threshold, then the pixel corresponds to a strong
edge. Any pixel connected to a strong edge and having a magnitude
greater than the low threshold corresponds to a weak edge. If, for the
Threshold source parameter, you choose Input port, use input port
Th to specify a two-element vector of threshold values. These values
must have the same data type as the input data.
The Edge Detection block computes the automatic threshold values
using an approximation of the number of weak and nonedge image
pixels. Enter this approximation for the Approximate percentage of
weak edge and nonedge pixels (used to automatically calculate
threshold values) parameter.
Use the Standard deviation of Gaussian filter parameter to define
the Gaussian filter whose derivative is convolved with the input image.
1-365
Edge Detection
The block squares the threshold and compares it to the sum of the
squared gradients to avoid using square roots.
Threshold:
MULTIPLIER CAST
Product output Accumulator
Input data type
data type data type
Gradients:
MULTIPLIER CAST
Product output Accumulator
Accumulator data type
data type data type
ADDER
Accumulator
data type
MULTIPLIER CAST
Product output Accumulator
Accumulator data type data type
data type
1-366
Edge Detection
You can set the product output and accumulator data types in the block
mask as discussed in the next section.
Dialog The Main pane of the Edge Detection dialog box appears as shown in
Box the following figure.
Method
Select the method by which to perform edge detection. Your
choices are Sobel, Prewitt, Roberts, or Canny.
Output type
Select the desired form of the output. If you select Binary
image, the block outputs a matrix that is filled with ones,
which correspond to edges, and zeros, which correspond to the
background. If you select Gradient components and, for the
Method parameter, you select Sobel or Prewitt, the block
outputs the gradient components that correspond to the horizontal
1-367
Edge Detection
1-368
Edge Detection
The Data Types pane of the Edge Detection dialog box appears
as shown in the following figure.
1-369
Edge Detection
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
1-370
Edge Detection
Product output
I data type
MULTIPLIER
Product output
Internal coefficients data type
data type
MULTIPLIER
Product output
Accumulator data type
data type
Here, the internal coefficients are the Sobel, Prewitt, or Roberts
masks. As depicted in the previous figure, the output of the
multiplier is placed into the product output data type and scaling.
Use this parameter to specify how to designate this product
output word and fraction lengths.
• When you select Same as first input, these characteristics
match those of the first input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
1-371
Edge Detection
Accumulator
1-372
Edge Detection
[2] Pratt, William K. Digital Image Processing, 2nd ed. New York: John
Wiley & Sons, 1991.
1-373
Erosion
Description The Erosion block slides the neighborhood or structuring element over
an image, finds the local minima, and creates the output matrix from
these minimum values. If the neighborhood or structuring element has
a center element, the block places the minima there, as illustrated in
the following figure.
1-374
Erosion
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating point No
values
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned
integer
Nhood Matrix or vector of 1s and Boolean No
0s that represents the
neighborhood values
Output Vector or matrix of intensity Same as I port No
values that represents the
eroded image
The output signal is the same data type as the input to the I port.
Use the Neighborhood or structuring element source parameter to
specify how to enter your neighborhood or structuring element values.
If you select Specify via dialog, the Neighborhood or structuring
element parameter appears in the dialog box. If you select Input
port, the Nhood port appears on the block. Use this port to enter your
neighborhood values as a matrix or vector of 1s and 0s. You can only
specify a structuring element using the dialog box.
Use the Neighborhood or structuring element parameter to define
the neighborhood or structuring element that the block applies to the
image. Specify a neighborhood by entering a matrix or vector of 1s and
0s. Specify a structuring element with the strel function from the
Image Processing Toolbox. If the structuring element is decomposable
into smaller elements, the block executes at higher speeds due to the
1-375
Erosion
Dialog The Erosion dialog box appears as shown in the following figure.
Box
1-376
Erosion
References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.
1-377
Estimate Geometric Transformation
Description
Complex
Port Input/Output Supported Data Types Values
Supported
Pts1/Pts2 M-by-2 Matrix of • Double No
one-based [x y]
• Single
point coordinates,
where M represents • 8, 16, 32-bit signed integer
the number of
• 8, 16, 32-bit unsigned integer
points.
Num Scalar value that • 8, 16, 32-bit signed integer No
represents the
• 8, 16, 32-bit unsigned integer
number of valid
points in Pts1 and
Pts 2.
1-378
Estimate Geometric Transformation
Complex
Port Input/Output Supported Data Types Values
Supported
TForm 3-by-2 or 3-by-3 • Double No
transformation
• Single
matrix.
Inlier M-by-1 vector Boolean No
indicating which
points have been
used to calculate
TForm.
Ports Pts1 and Pts2 are the points on two images that have the same
data type. The block outputs the same data type for the transformation
matrix
When Pts1 and Pts2 are single or double, the output transformation
matrix will also have single or double data type. When Pts1 and
Pts2 images are built-in integers, the option is available to set the
transformation matrix data type to either Single or Double. The TForm
output provides the transformation matrix. The Inlier output port
provides the Inlier points on which the transformation matrix is based.
This output appears when you select the Output Boolean signal
indicating which point pairs are inliers checkbox.
points, pia (image a, Pts1) and pib (image b, Pts 2) is an inlier only
when the distance between pib and the projection of pia based on the
transformation matrix falls within the specified threshold. The distance
metric used in the RANSAC algorithm is as follows:
Num
d= ∑ min( D( pib , ψ( pia : H )), t)
i=1
1-379
Estimate Geometric Transformation
The Least Median Squares algorithm assumes at least 50% of the point
pairs can be mapped by a transformation matrix. The algorithm does
not need to explicitly specify the distance threshold. Instead, it uses the
median distance between all input point pairs. The distance metric
used in the Least Median of Squares algorithm is as follows:
Transformations
The Estimate Geometric Transformation block supports
Nonreflective similarity, affine, and projective transformation
types, which are described in this section.
Nonreflective similarity transformation supports translation,
rotation, and isotropic scaling. It has four degrees of freedom and
requires two pairs of points.
1-380
Estimate Geometric Transformation
h1 h2
H h2 h1
The transformation matrix is: h3 h4
h1 h4
The transformation matrix is: H h2 h5
h3 h6
The projection of a point x y by H is: xˆ yˆ x y 1 H
Projective transformation supports tilting in addition to all
transformations that the affine transformation supports.
h1 h4 h7
The transformation matrix is : h h2 h5 h8
h3 h6 h9
1-381
Estimate Geometric Transformation
Distance Measurement
For computational simplicity and efficiency, this block uses algebraic
T
distance. The algebraic distance for a pair of points, ⎡ x a ya ⎤ on
⎣ ⎦
image a, and xb yb on image b , according to transformation H, is
defined as follows;
For projective transformation:
1
D( pib , ψ( pia : H )) = ((ua − wa xb )2 + (va − wa yb )2 ) 2 , where
uˆ a vˆ a w
ˆ a x a y a 1 H
For Nonreflective similarity or affine transformation:
1
D( pib , ψ( pia : H )) = (( x a − xb )2 + ( y a − yb )2 ) 2
,
where xˆ a yˆ a x a y a 1 H
Algorithm
The block performs a comparison and repeats it K number of times
between successive transformation matrices. If you select the Find
and exclude outliers option, the RANSAC and Least Median Squares
(LMS) algorithms become available. These algorithms calculate and
compare a distance metric. The transformation matrix that produces
the smaller distance metric becomes the new transformation matrix
that the next comparison uses. A final transformation matrix is
resolved when either:
1-382
Estimate Geometric Transformation
1-383
Estimate Geometric Transformation
log(1 p)
K
log(1 qs )
where
1-384
Estimate Geometric Transformation
1-385
Estimate Geometric Transformation
Dialog Box
1-386
Estimate Geometric Transformation
Transformation Type
Specify transformation type, either Nonreflective similarity,
affine, or projective transformation. If you select projective
transformation, you can also specify a scalar algebraic distance
threshold for determining inliers. If you select either affine
or projective transformation, you can specify the distance
threshold for determining inliers in pixels. See “Transformations”
on page 1-380 for a more detailed discussion. The default value
is projective.
Find and exclude outliers
When selected, the block finds and excludes outliers from the
input points and uses only the inlier points to calculate the
transformation matrix. When this option is not selected, all input
points are used to calculate the transformation matrix.
Method
Select either the RANdom SAmple Consensus (RANSAC) or the
Least Median of Squares algorithm to find outliers. See
“RANSAC and Least Median Squares Algorithms” on page 1-379
for a more detailed discussion. This parameter appears when you
select the Find and exclude outliers check box.
Algebraic distance threshold for determining inliers
Specify a scalar threshold value for determining inliers. The
threshold controls the upper limit used to find the algebraic
distance in the RANSAC algorithm. This parameter appears
when you set the Method parameter to Random Sample
Consensus (RANSAC) and the Transformation type parameter
to projective. The default value is 1.5.
Distance threshold for determining inliers (in pixels)
Specify the upper limit distance a point can differ from the
projection location of its associating point. This parameter
appears when you set the Method parameter to Random
Sample Consensus (RANSAC) and you set the value of the
Transformation type parameter to Nonreflective similarity
or affine. The default value is 1.5.
1-387
Estimate Geometric Transformation
1-388
Estimate Geometric Transformation
1-389
Estimate Geometric Transformation
1-390
Estimate Geometric Transformation
Video Mosaicking
To see an example of the Estimate Geometric Transformation block
used in a model with other blocks, see the “Video Mosaicking” example.
1-391
Estimate Geometric Transformation
1-392
Estimate Geometric Transformation (To Be Removed)
Description
1-393
Find Local Maxima
Library Statistics
visionstatistics
Description The Find Local Maxima block finds the local maxima within an input
matrix. It does so by comparing the maximum value in the matrix to
a user-specified threshold. The block considers a value to be a valid
local maximum when the maximum value is greater than or equal to
the specified threshold. The determination of the local maxima is based
on the neighborhood, an area around and including the maximum
value. After finding the local maxima, the block sets all the matrix
values in the neighborhood, including the maximum value, to 0. This
step ensures that subsequent searches do not include this maximum.
The size of the neighborhood must be appropriate for the data set.
That is, the threshold must eliminate enough of the values around the
maximum so that false peaks are not discovered. The process repeats
until the block either finds all valid maximas or the number of local
maximas equal the Maximum number of local maxima value. The
block outputs one-based [x y] coordinates of the maxima. The data to all
input ports must be the same data type.
If the input to this block is a Hough matrix output from the Hough
Transform block, select the Input is Hough matrix spanning full
theta range check box. If you select this check box, the block assumes
that the Hough port input is antisymmetric about the rho axis and
theta ranges from -pi/2 to pi/2 radians. If the block finds a local maxima
near the boundary, and the neighborhood lies outside the Hough
matrix, then the block detects only one local maximum. It ignores the
corresponding antisymmetric maximum.
1-394
Find Local Maxima
Dialog The Find Local Maxima dialog box appears as shown in the following
Box figure.
1-395
Find Local Maxima
1-396
Find Local Maxima
applies when you clear the Output variable size signal check
box.
Examples See “Detect Lines in Images” and “Measure Angle Between Lines” in
the Computer Vision System Toolbox User’s Guide.
Supported The block outputs the one-based [x y] coordinates of the maxima at the
Data Idx port and the number of valid local maxima found at the Count port.
Types
Complex
Port Input/Output Supported Data Types Values
Supported
I/Hough Matrix in which you • Double-precision floating point No
want to find the maxima.
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Th Scalar value that Same as I/Hough port No
represents the value
the maxima should meet
or exceed.
Idx An M-by-2 matrix No
of one-based [x y] • Double-precision floating point
coordinates, where M
• Single-precision floating point
represents the number
of local maximas found. • 8-, 16-, and 32-bit unsigned integer
Count Scalar value that Same as Idx port No
represents the number
of maxima that meet
or exceed the threshold
value.
1-397
Find Local Maxima
1-398
Find Local Maxima (To Be Removed)
Library Statistics
Description
Note This Find Local Maxima block will be removed in a future
release. It uses the zero-based, [row column] coordinate system. It is
recommended that you replace this block with the updated Find Local
Maxima block that uses the one-based, [x y] coordinate system.
1-399
Frame Rate Display
Library Sinks
visionsinks
Description The Frame Rate Display block calculates and displays the average
update rate of the input signal. This rate is in relation to the wall clock
time. For example, if the block displays 30, the model is updating the
input signal 30 times every second. You can use this block to check the
video frame rate of your simulation. During code generation, Simulink
Coder does not generate code for this block.
Note This block supports intensity and color images on its port.
Complex
Port Input Supported Data Types Values
Supported
Input M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P
• Single-precision floating point
color video signal where
P is the number of color • Fixed point
planes
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Use the Calculate and display rate every parameter to control how
often the block updates the display. When this parameter is greater
than 1, the block displays the average update rate for the specified
number of video frames. For example, if you enter 10, the block
calculates the amount of time it takes for the model to pass 10 video
frames to the block. It divides this time by 10 and displays this average
video frame rate on the block.
1-400
Frame Rate Display
Note If you do not connect the Frame Rate Display block to a signal
line, the block displays the base (fastest) rate of the Simulink model.
Dialog The Frame Rate Display dialog box appears as shown in the following
Box figure.
1-401
From Multimedia File
Purpose Read video frames and audio samples from compressed multimedia file
Library Sources
visionsources
Description
The From Multimedia File block reads audio samples, video frames, or
both from a multimedia file. The block imports data from the file into a
Simulink model.
Note This block supports code generation for the host computer
that has file I/O available. You cannot use this block with Real-Time
Windows Target™ software because that product does not support file
I/O.
The generated code for this block relies on prebuilt library files. You can
run this code outside the MATLAB environment, or redeploy it, but be
sure to account for these extra library files when doing so. The packNGo
function creates a single zip file containing all of the pieces required to
run or rebuild this code. See packNGo for more information.
To run an executable file that was generated from a model containing
this block, you may need to add precompiled shared library files to
your system path. See “Simulink Coder”, “Simulink Shared Library
Dependencies”, and “Accelerating Simulink Models” for details.
This block allows you to read WMA/WMV streams to disk or across a
network connection. Similarly, the To Multimedia File block allows you
to write WMA/WMV streams to disk or across a network connection. If
you want to play an MP3/MP4 file in Simulink, but you do not have the
1-402
From Multimedia File
codecs, you can re-encode the file as WMA/WMV, which are supported
by the Computer Vision System Toolbox.
Video:
MPEG (.mpeg)
MPEG-2 (.mp2)
MPEG-1.mpg
1-403
From Multimedia File
Note MJ2 files with bit depth higher than 8-bits is not supported by
vision.VideoFileReader. Use VideoReader and VideoWriter for
higher bit depths.
Ports The output ports of the From Multimedia File block change according to
the content of the multimedia file. If the file contains only video frames,
1-404
From Multimedia File
the Image, intensity I, or R,G,B ports appear on the block. If the file
contains only audio samples, the Audio port appears on the block. If
the file contains both audio and video, you can select the data to emit.
The following table describes available ports.
Port Description
Image M-by-N-by-P color video signal where P is the number of color planes.
I M-by-N matrix of intensity values.
R, G, B Matrix that represents one plane of the RGB video stream. Outputs
from the R, G, or B ports must have same dimensions.
Audio Vector of audio data.
Y, Cb, Cr Matrix that represents one frame of the YCbCr video stream. The Y,
Cb, Cr ports produce the following outputs:
Y: M x N
N
Cb: M x 2
N
Cr: M x 2
Sample The sample rate that the block uses depends on the audio and video
Rates sample rate. While the FMMF block operates at a single rate in
Simulink, the underlying audio and video streams can produce different
rates. In some cases, when the block outputs both audio and video,
makes a small adjustment to the video rate.
1-405
From Multimedia File
ceil( AudioSampleRate )
FPS
Sample Sample time = AudioSampleRate .
Time AudioSampleRate
Calculations When audio sample time, FPS is noninteger, the
Used for 1
Video and equation cannot reduce to FPS .
Audio
Files In this case, to prevent synchronization problems, the block drops
the corresponding video frame when the audio stream leads the video
1
stream by more than FPS .
In summary, the block outputs one video frame at each Simulink
time step. To calculate the number of audio samples to output at
each time step, the block divides the audio sample rate by the video
frame rate (fps). If the audio sample rate does not divide evenly by
the number of video frames per second, the block rounds the number
of audio samples up to the nearest whole number. If necessary, the
block periodically drops a video frame to maintain synchronization
for large files.
Dialog The Main pane of the From Multimedia File block dialog appears as
Box follows.
1-406
From Multimedia File
File name
Specify the name of the multimedia file from which to read. The
block determines the type of file (audio and video, audio only, or
video only) and provides the associated parameters.
If the location of the file does not appear on your MATLAB path,
use the Browse button to specify the full path. Otherwise, if the
1-407
From Multimedia File
location of this file appears on your MATLAB path, enter only the
file name. On Windows platforms, this parameter supports URLs
that point to MMS (Microsoft Media Server) streams.
Inherit sample time from file
Select the Inherit sample time from file check box if you want
the block sample time to be the same as the multimedia file. If you
clear this check box, enter the block sample time in the Desired
sample time parameter field. The file that the From Multimedia
File block references, determines the block default sample time.
You can also set the sample time for this block manually. If you
do not know the intended sample rate of the video, let the block
inherit the sample rate from the multimedia file.
Desired sample time
Specify the block sample time. This parameter becomes available
if you clear the Inherit sample time from file check box.
Number of times to play file
Enter a positive integer or inf to represent the number of times
to play the file.
Output end-of-file indicator
Use this check box to determine whether the output is the last
video frame or audio sample in the multimedia file. When you
select this check box, a Boolean output port labeled EOF appears
on the block. The output from the EOF port defaults to 1 when
the last video frame or audio sample is output from the block.
Otherwise, the output from the EOF port defaults to 0.
Multimedia outputs
Specify Video and audio, Video only, or Audio only output file
type. This parameter becomes available only when a video signal
has both audio and video.
Samples per audio channel
Specify number of samples per audio channel. This parameter
becomes available for files containing audio.
1-408
From Multimedia File
The Data Types pane of the To Multimedia File block dialog box
appears as follows.
1-409
From Multimedia File
1-410
From Multimedia File
Supported For source blocks to display video data properly, double- and
Data single-precision floating-point pixel values must be between 0 and 1.
Types For other data types, the pixel values must be between the minimum
and maximum values supported by their data type.
1-411
From Multimedia File
1-412
Gamma Correction
Library Conversions
visionconversions
Description Use the Gamma Correction block to apply or remove gamma correction
from an image or video stream. For input signals normalized between 0
and 1, the block performs gamma correction as defined by the following
equations. For integers and fixed-point data types, these equations are
generalized by applying scaling and offset values specific to the data
type:
1
SLS =
γ
( 1 γ −1)
− γBP + BP
BP
γSLS
FS = ( 1 γ −1)
BP
1
γ
CO = FS BP − SLS BP
SLS I , I Bp
I 1
F I C , I B
S O p
SLS is the slope of the straight line segment. BP is the break point
of the straight line segment, which corresponds to the Break point
parameter. FS is the slope matching factor, which matches the slope of
the linear segment to the slope of the power function segment. CO is the
segment offset, which ensures that the linear segment and the power
function segments connect. Some of these parameters are illustrated
by the following diagram.
1-413
Gamma Correction
I
, I SLS B p
SLS
I
I CO
F , I SLS B p
S
1-414
Gamma Correction
Break
Standard Slope Point Gamma
CIE L* 9.033 0.008856 3
Recommendation ITU-R BT.709-3, 4.5 0.018
Parameter Values for the HDTV 20
Standards for Production and 9
International Programme
Exchange
sRGB 12.92 0.00304 2.4
Note This block supports intensity and color images on its ports.
The properties of the input and output ports are summarized in the
following table:
Complex
Port Input/Output Supported Data Types Values
Supported
I M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P color
• Single-precision floating point
video signal where P is the
number of color planes • Fixed point (up to 16-bit word
length)
• 8- and 16-bit signed integer
• 8- and 16-bit unsigned integer
I’ M-by-N matrix of intensity Same as I port No
values or an M-by-N-by-P color
video signal where P is the
number of color planes
1-415
Gamma Correction
Dialog The Gamma Correction dialog box appears as shown in the following
Box figure.
Operation
Specify the block’s operation. Your choices are Gamma or De-gamma.
1-416
Gamma Correction
Gamma
If, for the Operation parameter, you select Gamma, enter the
desired gamma value of the output video stream. This value must
be greater than or equal to 1. If, for the Operation parameter,
you select De-gamma, enter the gamma value of the input video
stream.
Linear segment
Select this check box if you want the gamma curve to have a
linear portion near the origin.
Break point
Enter a scalar value that indicates the I-axis value of the end of
the linear segment. This parameter is visible if you select the
Linear segment check box.
References [1] Poynton, Charles. Digital Video and HDTV Algorithms and
Interfaces. San Francisco, CA: Morgan Kaufman Publishers, 2003.
1-417
Gaussian Pyramid
Library Transforms
visiontransforms
Note This block supports intensity and color images on its ports.
Complex
Port Output Supported Data Types Values
Supported
Input In Reduce mode, the input • Double-precision floating point No
can be an M-by-N matrix
• Single-precision floating point
of intensity values or an
M-by-N-by-P color video • Fixed point
signal where P is the
• 8-, 16-, 32-bit signed integer
number of color planes.
• 8-, 16-, 32-bit unsigned integer
In Expand mode, the input
can be a scalar, vector, or
M-by-N matrix of intensity
values or an M-by-N-by-P
color video signal where
P is the number of color
planes.
Output In Reduce mode, the Same as Input port No
output can be a scalar,
vector, or matrix that
1-418
Gaussian Pyramid
Complex
Port Output Supported Data Types Values
Supported
⎛M⎞ ⎛N⎞
ceil ⎜ ⎟ − by − ceil ⎜ ⎟
⎝ 2 ⎠ ⎝ 2⎠
You must repeat this calculation for each successive pyramid level. If
you have an M-by-N input image and you set the Operation parameter
to Expand, you can calculate the dimensions of the output image using
the following equation:
⎡( M − 1) 2l + 1⎤ − by − ⎡( N − 1) 2l + 1⎤
⎣ ⎦ ⎣ ⎦
In the previous equation, l is the scalar value from 1 to inf that you
enter for the Pyramid level parameter.
1-419
Gaussian Pyramid
Examples
The following example model shows how to construct a Laplacian
pyramid:
ex_laplacian
1-420
Gaussian Pyramid
1-421
Gaussian Pyramid
1-422
Gaussian Pyramid
1-423
Gaussian Pyramid
You can set the coefficients table, product output, accumulator, and
output data types in the block mask.
Dialog The Main pane of the Gaussian Pyramid dialog box appears as shown
Box in the following figure.
1-424
Gaussian Pyramid
Operation
Specify whether you want to reduce or expand the input image.
1-425
Gaussian Pyramid
Pyramid level
Specify the number of times the block upsamples or downsamples
each dimension of the image by a factor of 2.
Coefficient source
Determine how to specify the coefficients of the lowpass filter.
Your choices are Default separable filter [1/4-a/2 1/4 a
1/4 1/4-a/2] or Specify via dialog.
a
Enter a scalar value that defines the coefficients in the default
separable filter [1/4-a/2 1/4 a 1/4 1/4-a/2]. This parameter
is visible if, for the Coefficient source parameter, you select
Default separable filter [1/4-a/2 1/4 a 1/4 1/4-a/2].
Coefficients for separable filter
Enter a vector of separable filter coefficients. This parameter
is visible if, for the Coefficient source parameter, you select
Specify via dialog.
The Data Types pane of the Gaussian Pyramid dialog box appears
as shown in the following figure.
1-426
Gaussian Pyramid
Rounding mode
Select the rounding mode for fixed-point operations.
1-427
Gaussian Pyramid
Overflow mode
Select the overflow mode for fixed-point operations.
Coefficients
Choose how to specify the word length and the fraction length
of the coefficients:
• When you select Same word length as input, the word length
of the coefficients match that of the input to the block. In this
mode, the fraction length of the coefficients is automatically
set to the binary-point only scaling that provides you with the
best precision possible given the value and word length of the
coefficients.
• When you select Specify word length, you can enter the word
length of the coefficients, in bits. The block automatically sets
the fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the coefficients, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the coefficients. The bias of
all signals in the Computer Vision System Toolbox blocks is 0.
Product output
1-428
Gaussian Pyramid
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
Accumulator
1-429
Gaussian Pyramid
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. The bias of all
signals in the Computer Vision System Toolbox blocks is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-430
Histogram Equalization
Complex
Port Input/Output Supported Data Types Values
Supported
I Matrix of intensity values • Double-precision floating point No
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Hist Vector of integer values • Double-precision floating point No
that represents the
• Single-precision floating point
desired intensity values in
each bin • 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Output Matrix of intensity values Same as I port No
If the data type of input to the I port is floating point, the input to Hist
port must be the same data type. The output signal has the same data
type as the input signal.
1-431
Histogram Equalization
Note The vector input to the Hist port must be normalized such that
the sum of the values in all the bins is equal to the number of pixels
in the input image. The block does not error if the histogram is not
normalized.
Examples See “Adjust the Contrast of Intensity Images” and“Adjust the Contrast
of Color Images” in the Computer Vision System Toolbox User’s Guide.
1-432
Histogram Equalization
Target histogram
Designate the histogram you want the output image to have.
If you select Uniform, the block transforms the input image so
that the histogram of the output image is approximately flat. If
you select User-defined, you can specify the histogram of your
output image.
Number of bins
Enter the number of equally spaced bins you want the uniform
histogram to have. This parameter is visible if, for the Target
histogram parameter, you select Uniform.
Histogram source
Select how to specify your histogram. Your choices are Specify
via dialog and Input port. This parameter is visible if, for the
Target histogram parameter, you select User-defined.
Histogram
Enter the desired histogram of the output image. This parameter
is visible if, for the Target histogram parameter, you select
User-defined.
1-433
Histogram Equalization
1-434
Hough Lines
Purpose Find Cartesian coordinates of lines described by rho and theta pairs
Library Transforms
visiontransforms
Description
The Hough Lines block finds the points of intersection between the
reference image boundary lines and the line specified by a (rho, theta)
pair. The block outputs one-based [x y] coordinates for the points of
intersection. The boundary lines indicate the left and right vertical
boundaries and the top and bottom horizontal boundaries of the
reference image.
If the line specified by the (rho, theta) pair does not intersect two border
lines in the reference image, the block outputs the values, [(0,0),
(0,0)]. This output intersection value allows the next block in your
model to ignore the points. Generally, the Hough Lines block precedes a
block that draws a point or shape at the intersection.
The following figure shows the input and output coordinates for the
Hough Lines block.
1-435
Hough Lines
Port Description
Complex
Port Input/Output Supported Data Types Values
Supported
Theta Vector of theta values that • Double-precision floating point No
represent input lines
• Single-precision floating point
• Fixed point (signed, word length
less than or equal to 32)
• 8-, 16-, and 32-bit signed integer
Rho Vector of rho values that Same as Theta port No
represent input lines
1-436
Hough Lines
Complex
Port Input/Output Supported Data Types Values
Supported
Ref I Matrix that represents a • Double-precision floating point No
binary or intensity image or
• Single-precision floating point
matrix that represents one
plane of an RGB image • Fixed-point (signed and unsigned)
• Custom data types
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Pts M-by-4 matrix of intersection • 32-bit signed integer No
values, where M is the
number of input lines
Dialog The Main pane of the Hough Lines dialog box appears as shown in
Box the following figure.
1-437
Hough Lines
1-438
Hough Lines
The Data Types pane of the Hough Lines dialog box appears as shown
in the following figure.
1-439
Hough Lines
Rounding mode
Select the rounding mode for fixed-point operations.
1-440
Hough Lines
Overflow mode
Select the overflow mode for fixed-point operations.
Sine table
Choose how to specify the word length of the values of the sine
table. The fraction length of the sine table values always equals
the word length minus one:
When you select Specify word length, you can enter the word
length of the sine table.
The sine table values do not obey the Rounding mode and
Overflow mode parameters; they saturate and round to Nearest.
Product output
Use this parameter to specify how to designate this product
output word and fraction lengths:
When you select Binary point scaling, you can enter the word
length and the fraction length of the product output, in bits.
When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. All
signals in the Computer Vision System Toolbox blocks have a
bias of 0.
1-441
Hough Lines
When you select Binary point scaling, you can enter the Word
length and the Fraction length of the accumulator, in bits.
When you select Slope and bias scaling, you can enter the
Word length, in bits, and the Slope of the Accumulator. All
signals in the Computer Vision System Toolbox software have
a bias of 0.
Examples The following figure shows Line 1 intersecting the boundaries of the
reference image at [(x11, y11) (x12, y12)] and Line 2 intersecting the
boundaries at [(x21, y21) (x22, y22)]
1-442
Hough Lines
1-443
Hough Lines (To Be Removed)
Purpose Find Cartesian coordinates of lines described by rho and theta pairs
Library Transforms
Description
1-444
Hough Transform
Library Transforms
visiontransforms
Description Use the Hough Transform block to find lines in an image. The block
outputs the Hough space matrix and, optionally, the rho-axis and
theta-axis vectors. Peak values in the matrix represent potential lines
in the input image. Generally, the Hough Transform block precedes the
Hough Lines block which uses the output of this block to find lines in an
image. You can instead use a custom algorithm to locate peaks in the
Hough space matrix in order to identify potential lines.
Supported
Port Input/Output Supported Data Types Complex
Values
BW Matrix that represents a Boolean No
binary image
Hough Parameter space matrix • Double-precision floating point No
• Single-precision floating point
• Fixed point (unsigned, fraction
length equal to 0)
• 8-, 16-, 32-bit unsigned integer
Theta Vector of theta values • Double-precision floating point No
• Single-precision floating point
• Fixed point (signed)
• 8-, 16-, 32-bit signed integer
Rho Vector of rho values Same as Theta port No
1-445
Hough Transform
Dialog The Main pane of the Hough Transform dialog box appears as shown in
Boxes the following figure.
1-446
Hough Transform
The Data Types pane of the Hough Transform block dialog appears
as shown in the following figure. The Data Types pane will not show
fixed-point parameters when Output data type parameter is set to
double or single.
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
1-447
Hough Transform
Sine table
Choose how to specify the word length of the values of the sine
table:
• When you select Binary point scaling, you can enter the
word length of the sine table values, in bits.
• When you select Slope and bias scaling, you can enter the
word length of the sine table values, in bits.
The sine table values do not obey the Rounding mode and
Overflow mode parameters; they always saturate and round
to Nearest.
Rho
Choose how to specify the word length and the fraction length
of the rho values:
• When you select Binary point scaling, you can enter the
word length and the fraction length of the rho values, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the rho values. All signals
in Computer Vision System Toolbox blocks have a bias of 0.
Product output
. Use this parameter to specify how to designate the product
output word and fraction lengths:
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. All
signals in Computer Vision System Toolbox blocks have a bias
of 0.
1-448
Hough Transform
Accumulator
Use this parameter to specify how to designate this accumulator
word and fraction lengths:
• When you select Same as product output, these
characteristics match the characteristics of the product output.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the accumulator, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the accumulator. All
signals in Computer Vision System Toolbox blocks have a bias
of 0.
See “Multiplication Data Types” for illustrations depicting the
use of the accumulator data type in this block.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
Hough output
Choose how to specify the word length and fraction length of the
Hough output of the block:
• When you select Binary point scaling, you can enter the
word length of the Hough output, in bits. The fraction length
always has a value of 0.
• When you select Slope and bias scaling, you can enter the
word length, in bits, of the Hough output. The slope always has
a value of 0. All signals in Computer Vision System Toolbox
blocks have a bias of 0.
Theta output
Choose how to specify the word length and fraction length of the
theta output of the block:
1-449
Hough Transform
• When you select Binary point scaling, you can enter the
word length and the fraction length of the theta output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the theta output. All
signals in Computer Vision System Toolbox blocks have a bias
of 0.
The variable rho indicates the perpendicular distance from the origin
to the line.
The variable theta indicates the angle of inclination of the normal line
− ≤ < +
from the x-axis. The range of theta is 2 2 with a step-size
determined by the Theta resolution (radians) parameter. The SHT
measures the angle of the line clockwise with respect to the positive
x-axis.
The Hough Transform block creates an accumulator matrix. The (rho,
theta) pair represent the location of a cell in the accumulator matrix.
Every valid (logical true) pixel of the input binary image represented
by (R,C) produces a rho value for all theta values. The block quantizes
1-450
Hough Transform
the rho values to the nearest number in the rho vector. The rho vector
depends on the size of the input image and the user-specified rho
resolution. The block increments a counter (initially set to zero) in those
accumulator array cells represented by (rho, theta) pairs found for each
pixel. This process validates the point (R,C) to be on the line defined by
(rho, theta). The block repeats this process for each logical true pixel in
the image. The Hough block outputs the resulting accumulator matrix.
Examples See “Detect Lines in Images” and “Measure Angle Between Lines” in
the Computer Vision System Toolbox User Guide.
1-451
Image Complement
Library Conversions
visionconversions
Complex
Port Input/Output Supported Data Types Values
Supported
Input Vector or matrix of intensity values • Double-precision No
floating point
• Single-precision
floating point
• Boolean
• 8-, 16-, 32-bit signed
integer
• 8-, 16-, 32-bit unsigned
integer
Output Complement of a binary or intensity Same as Input port No
The dimensions, data type, complexity, and frame status of the input
and output signals are the same.
1-452
Image Complement
Dialog The Image Complement dialog box appears as shown in the following
Box figure.
1-453
Image Data Type Conversion
Purpose Convert and scale input image to specified output data type
Library Conversions
visionconversions
Description The Image Data Type Conversion block changes the data type of the
input to the user-specified data type and scales the values to the new
data type’s dynamic range. To convert between data types without
scaling, use the Simulink Data Type Conversion block.
When converting between floating-point data types, the block casts the
input into the output data type and clips values outside the range to
0 or 1. When converting to the Boolean data type, the block maps 0
values to 0 and all other values to one. When converting to or between
all other data types, the block casts the input into the output data type
and scales the data type values into the dynamic range of the output
data type. For double- and single-precision floating-point data types,
the dynamic range is between 0 and 1. For fixed-point data types, the
dynamic range is between the minimum and maximum values that can
be represented by the data type.
Note This block supports intensity and color images on its ports.
Complex
Port Input/Output Supported Data Types Values
Supported
Input M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P
• Single-precision floating point
color video signal where P is
the number of color planes • Fixed point (word length less than
or equal to 16)
• Boolean
• 8-, 16-bit signed integer
1-454
Image Data Type Conversion
Complex
Port Input/Output Supported Data Types Values
Supported
The dimensions, complexity, and frame status of the input and output
signals are the same.
Use the Output data type parameter to specify the data type of your
output signal values.
Dialog The Image Data Type Conversion dialog box appears as shown in the
Box following figure.
1-455
Image Data Type Conversion
Signed
Select this check box if you want the output fixed-point data to
be signed. This parameter is visible if, for the Output data type
parameter, you choose Fixed-point.
Word length
Use this parameter to specify the word length of your fixed-point
output. This parameter is visible if, for the Output data type
parameter, you choose Fixed-point.
Fraction length
Use this parameter to specify the fraction length of your
fixed-point output. This parameter is visible if, for the Output
data type parameter, you choose Fixed-point.
1-456
Image From File
Library Sources
visionsources
Description Use the Image From File block to import an image from a supported
image file. For a list of supported file formats, see the imread function
reference page in the MATLAB documentation. If the image is a
M-by-N array, the block outputs a binary or intensity image, where M
and N are the number of rows and columns in the image. If the image is
a M-by-N-by-P array, the block outputs a color image, where M and N
are the number of rows and columns in each color plane, P.
Complex
Port Output Supported Data Types Values
Supported
Image M-by-N matrix of intensity • Double-precision floating point Yes
values or an M-by-N-by-P
• Single-precision floating point
color video signal where P is
the number of color planes • Fixed point
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
R, G, Scalar, vector, or matrix that Same as I port Yes
B represents one plane of the
input RGB video stream.
Outputs from the R, G,
or B ports have the same
dimensions.
For the Computer Vision System Toolbox blocks to display video data
properly, double- and single-precision floating-point pixel values must
be between 0 and 1. If the input pixel values have a different data type
than the one you select using the Output data type parameter, the
1-457
Image From File
block scales the pixel values, adds an offset to the pixel values so that
they are within the dynamic range of their new data type, or both.
Use the File name parameter to specify the name of the graphics file
that contains the image to import into the Simulink modeling and
simulation software. If the file is not on the MATLAB path, use the
Browse button to locate the file. This parameter supports URL paths.
Use the Sample time parameter to set the sample period of the output
signal.
Use the Image signal parameter to specify how the block outputs a
color video signal. If you select One multidimensional signal, the
block outputs an M-by-N-by-P color video signal, where P is the number
of color planes, at one port. If you select Separate color signals,
additional ports appear on the block. Each port outputs one M-by-N
plane of an RGB video stream.
Use the Output port labels parameter to label your output ports. Use
the spacer character, |, as the delimiter. This parameter is visible if
you set the Image signal parameter to Separate color signals.
On the Data Types pane, use the Output data type parameter to
specify the data type of your output signal.
1-458
Image From File
Dialog The Main pane of the Image From File dialog box appears as shown in
Box the following figure.
File name
Specify the name of the graphics file that contains the image to
import into the Simulink environment.
Sample time
Enter the sample period of the output signal.
Image signal
Specify how the block outputs a color video signal. If you select One
multidimensional signal, the block outputs an M-by-N-by-P
color video signal, where P is the number of color planes, at one
port. If you select Separate color signals, additional ports
appear on the block. Each port outputs one M-by-N plane of an
RGB video stream.
1-459
Image From File
The Data Types pane of the Image From File dialog box appears as
shown in the following figure.
1-460
Image From File
Word length
Specify the word length, in bits, of the fixed-point output data
type. This parameter is only visible if, from the Output data
type list, you select Fixed-point.
Set fraction length in output to
Specify the scaling of the fixed-point output by either of the
following two methods:
• Choose Best precision to have the output scaling
automatically set such that the output signal has the best
possible precision.
• Choose User-defined to specify the output scaling in the
Fraction length parameter.
This parameter is only visible if, from the Output data type list,
you select Fixed-point or when you select User-defined.
Fraction length
For fixed-point output data types, specify the number of fractional
bits, or bits to the right of the binary point. This parameter is
only visible when you select Fixed-point or User-defined for
the Output data type parameter and User-defined for the Set
fraction length in output to parameter.
User-defined data type
Specify any built-in or fixed-point data type. You can specify
fixed-point data types using the sfix, ufix, sint, uint, sfrac,
and ufrac functions from the Fixed-Point Designer™ library.
This parameter is only visible when you select User-defined for
the Output data type parameter.
1-461
Image From File
1-462
Image From Workspace
Library Sources
visionsources
Description Use the Image From Workspace block to import an image from the
MATLAB workspace. If the image is a M-by-N workspace array,
the block outputs a binary or intensity image, where M and N are
the number of rows and columns in the image. If the image is a
M-by-N-by-P workspace array, the block outputs a color image, where
M and N are the number of rows and columns in each color plane, P.
Complex
Port Output Supported Data Types Values
Supported
Image M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P
• Single-precision floating point
color video signal where P is
the number of color planes • Fixed point
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
R, G, Scalar, vector, or matrix Same as I port No
B that represents one plane
of the RGB video stream.
Outputs from the R, G,
or B ports have the same
dimensions.
For the Computer Vision System Toolbox blocks to display video data
properly, double- and single-precision floating-point pixel values must
be between 0 and 1. If the input pixel values have a different data type
than the one you select using the Output data type parameter, the
1-463
Image From Workspace
block scales the pixel values, adds an offset to the pixel values so that
they are within the dynamic range of their new data type, or both.
Use the Value parameter to specify the MATLAB workspace variable
that contains the image you want to import into Simulink environment.
Use the Sample time parameter to set the sample period of the output
signal.
Use the Image signal parameter to specify how the block outputs a
color video signal. If you select One multidimensional signal, the
block outputs an M-by-N-by-P color video signal, where P is the number
of color planes, at one port. If you select Separate color signals,
additional ports appear on the block. Each port outputs one M-by-N
plane of an RGB video stream.
Use the Output port labels parameter to label your output ports. Use
the spacer character, |, as the delimiter. This parameter is visible if
you set the Image signal parameter to Separate color signals.
On the Data Types pane, use the Output data type parameter to
specify the data type of your output signal.
1-464
Image From Workspace
Dialog The Main pane of the Image From Workspace dialog box appears as
Box shown in the following figure.
Value
Specify the MATLAB workspace variable that you want to import
into Simulink environment.
Sample time
Enter the sample period of the output signal.
Image signal
Specify how the block outputs a color video signal. If you select One
multidimensional signal, the block outputs an M-by-N-by-P
color video signal, where P is the number of color planes, at one
port. If you select Separate color signals, additional ports
appear on the block. Each port outputs one M-by-N plane of an
RGB video stream.
1-465
Image From Workspace
The Data Types pane of the Image From Workspace dialog box appears
as shown in the following figure.
1-466
Image From Workspace
Word length
Specify the word length, in bits, of the fixed-point output data
type. This parameter is only visible if, from the Output data
type list, you select Fixed-point.
Set fraction length in output to
Specify the scaling of the fixed-point output by either of the
following two methods:
• Choose Best precision to have the output scaling
automatically set such that the output signal has the best
possible precision.
• Choose User-defined to specify the output scaling in the
Fraction length parameter.
This parameter is only visible if, from the Output data type list,
you select Fixed-point or when you select User-defined.
Fraction length
For fixed-point output data types, specify the number of fractional
bits, or bits to the right of the binary point. This parameter is
only visible when you select Fixed-point or User-defined for
the Output data type parameter and User-defined for the Set
fraction length in output to parameter.
User-defined data type
Specify any built-in or fixed-point data type. You can specify
fixed-point data types using the sfix, ufix, sint, uint, sfrac,
and ufrac functions from the Fixed-Point Designer library. This
parameter is only visible when you select User-defined for the
Output data type parameter.
1-467
Image From Workspace
1-468
Image Pad
Library Utilities
visionutilities
Description The Image Pad block expands the dimensions of a signal by padding its
rows, columns, or both. To crop an image, you can use the Simulink
Selector block, DSP System Toolbox Submatrix block, or the Image
Processing Toolbox imcrop function.
Complex Values
Port Input/Output Supported Data Types
Supported
Image / M-by-N matrix of • Double-precision floating Yes
I intensity values or an point.
M-by-N-by-P color video
• Single-precision floating
signal, where P is the
point.
number of color planes.
• Fixed point.
• Boolean.
• 8-, 16-, 32-bit signed integer.
• 8-, 16-, 32-bit unsigned
integer.
PVal Scalar value that Same as I port. Yes
represents the constant
pad value.
Output Padded scalar, vector, or Same as I port. Yes
matrix.
1-469
Image Pad
• Method = Constant
• Pad value source = Specify via dialog
• Pad value = 0
• Specify = Output size
• Add columns to = Left
• Output row mode = User-specified
• Number of output columns = 6
• Add rows to = No padding
1-470
Image Pad
• Method = Replicate
• Specify = Pad size
• Add columns to = Both left and right
• Number of added columns = 2
• Add rows to = Both top and bottom
• Number of added rows = [1 3]
1-471
Image Pad
The border values of the input signal are replicated on the top, bottom,
left, and right of the input signal so that the output is a 7-by-7 matrix.
The values in the corners of this output matrix are determined by
replicating the border values of the matrices on the top, bottom, left and
right side of the original input signal.
• Method = Symmetric
• Specify = Pad size
• Add columns to = Both left and right
1-472
Image Pad
The block flips the original input matrix and each matrix it creates
about their top, bottom, left, and right sides to populate the 7-by-13
output signal. For example, in the preceding figure, you can see how
the block flips the input matrix about its right side to create the matrix
directly to its right.
Pad Using a Circular Repetition of Elements
Suppose you want to pad your input signal using a circular repetition of
its values. Your input signal is defined as follows:
1-473
Image Pad
• Method = Circular
• Specify = Output size
• Add columns to = Both left and right
• Number of output columns = 9
• Add rows to = Both top and bottom
• Number of output rows = 9
The block repeats the values of the input signal in a circular pattern to
populate the 9-by-9 output matrix.
1-474
Image Pad
Dialog The Image Pad dialog box appears as shown in the following figure.
Box
1-475
Image Pad
Method
Specify how you want the block to pad your signal. The data type
of the input signal is the data type of the output signal.
Use the Method parameter to specify how you pad the input
signal.
• Constant — Pad with a constant value
• Replicate — Pad by repeating its border values
• Symmetric — Pad with its mirror image
• Circular — Pad using a circular repetition of its elements
1-476
Image Pad
If you select Output size, you can enter the total number of
output columns and rows. This setting enables you to pad the
input signal. See the previous section for descriptions of the Add
columns to and Add rows to parameters.
Add columns to
The Add columns to parameter controls the padding at the left,
right or both sides of the input signal.
• Left — The block adds additional columns on the left side.
• Right — The block adds additional columns on the right side.
• Both left and right — The block adds additional columns to
the left and right side.
• No padding — The block does not change the number of
columns.
1-477
Image Pad
1-478
Image Pad
1-479
Image Pad
1-480
Insert Text
Description The Insert Text block draws formatted text or numbers on an image or
video stream. The block uses the FreeType 2.3.5 library, an open-source
font engine, to produce stylized text bitmaps. To learn more about the
FreeType Project, visit http://www.freetype.org/. The Insert Text
block does not support character sets other than ASCII.
The Insert Text block lets you draw one or more instances of one or
more strings, including:
1-481
Insert Text
%c and %s:
%f:
1-482
Insert Text
1-483
Insert Text
1-484
Insert Text
When you use the row-major functionality, you must consider the
following issues:
• When you select this check box, the first two signal dimensions of the
Insert Text block’s input are swapped.
• All Computer Vision System Toolbox software blocks can be used to
process data that is in the row-major format, but you need to know
the image dimensions when you develop your algorithms.
For example, if you use the 2-D FIR Filter block, you need to verify
that your filter coefficients are transposed. If you are using the
Rotate block, you need to use negative rotation angles, etc.
• Only three blocks have the Input image is transposed (data
order is row major) check box. They are the Chroma Resampling,
Deinterlacing, and Insert Text blocks. You need to select this check
box to enable row-major functionality in these blocks. All other blocks
must be properly configured to process data in row-major format.
1-485
Insert Text
Step 1:
Create block diagram Algorithm
blocks
Step 2:
Replace source, transpose, and
Embedded sink blocks with target source Embedded
target source and sink blocks that produce target sink
block data in row-major format block
See the DM642 EVM Video ADC and DM642 EVM Video DAC reference
pages.
Dialog The Main pane of the Insert Text dialog box appears as shown in the
Box following figure.
1-486
Insert Text
1-487
Insert Text
Text
Specify the text string to be drawn on the image or video stream.
This parameter can be a single text string, such as 'Figure1', a
cell array of strings, such as {'Figure1','Figure2'}, or an ANSI
C printf-style format specifications, such as %s.. To create a
Select port enter a cell array of strings. To create a Variables
port, enter ANSI C printf-style format specifications, such as
%d, %f, or %s.
When you enter a cell array of strings, the Insert Text block does
not display all of the strings simultaneously. Instead, the Select
port appears on the block to let you indicate which text string
to display. The input to this port must be a scalar value, where
1 indicates the first string. If the input is less than 1 or greater
than one less than the number of strings in the cell array, no text
will be drawn on the image or video frame.
1-488
Insert Text
The following table describes how to format the color of the text
strings, which depend on the block input and the number of
strings you want to insert. Color values for a floating-point data
type input image must be between 0 and 1. Color values for an
8-bit unsigned integer data type input image must between 0 and
255.
1-489
Insert Text
Location source
Indicate where you want to specify the text location. Your choices
are:
• Specify via dialog — the Location [x y] parameter appears
on the dialog box.
• Input port — the Location port appears on the block.
Location [x y]
Specify the text location. This parameter is visible if, for the
Location source parameter, you select Specify via dialog.
Tunable.
1-490
Insert Text
insert. You can specify more than one location regardless of how
many text strings you specify, but the only way to get a different
text string at each location is to use the %s option for the Text
parameter to specify a set of text strings. You can enter negative
values or values that exceed the dimensions of the input image or
video frame, but the text might not be visible.
Opacity source
Indicate where you want to specify the text’s opaqueness. Your
choices are:
• Specify via dialog — the Opacity parameter appears on
the dialog box.
• Input port — the Opacity port appears on the block.
Opacity
Specify the opacity of the text. This parameter is visible if, for the
Opacity source parameter, you select Specify via dialog.
Tunable.
1-491
Insert Text
The following table describes how to format the opacity of the text
strings depending on the number of strings you want to insert.
1-492
Insert Text
The Font pane of the Insert Text dialog box appears as shown in the
following figure.
1-493
Insert Text
1-494
Insert Text
Font face
Specify the font of your text. The block populates this list with the
fonts installed on your system. On Windows, the block searches
the system registry for font files. On UNIX, the block searches the
X Server’s font path for font files.
Font size (points)
Specify the font size.
Anti-aliased
Select this check box if you want the block to smooth the edges of
the text. This can be computationally expensive. If you want your
model to run faster, clear this check box.
1-495
Insert Text (To Be Removed)
Description
Note This Insert Text block will be removed in a future release. It uses
the zero-based, [row column] coordinate system. It is recommended that
you replace this block with the updated Insert Text block that uses the
one-based, [x y] coordinate system.
1-496
Label
Description The Label block labels the objects in a binary image, BW, where the
background is represented by pixels equal to 0 (black) and objects are
represented by pixels equal to 1 (white). At the Label port, the block
outputs a label matrix that is the same size as the input matrix. In the
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. At the Count port, the block outputs a scalar value
that represents the number of labeled objects.
Complex
Port Input/Output Supported Data Types Values
Supported
BW Vector or matrix that Boolean No
represents a binary image
Label Label matrix • 8-, 16-, and 32-bit unsigned No
integer
Count Scalar that represents the Same as Label port No
number of labeled objects
1-497
Label
If, for the Connectivity parameter, you select 8, the block considers
the white pixels marked by black circles to be connected.
1-498
Label
Dialog The Label dialog box appears as shown in the following figure.
Box
Connectivity
Specify which pixels are connected to each other. If you want a
pixel to be connected to the pixels on the top, bottom, left, and
right, select 4. If you want a pixel to be connected to the pixels on
the top, bottom, left, right, and diagonally, select 8.
Output
Determine the block’s output. If you select Label matrix and
number of labels, the Label and Count ports appear on the
block. The block outputs the label matrix at the Label port and
the number of labeled objects at the Count port. If you select
1-499
Label
Label matrix, the Label port appears on the block. If you select
Number of labels, the Count port appears on the block.
Output data type
Set the data type of the outputs at the Label and Count ports.
If you select Automatic, the block determines the appropriate
data type for the output. If you select uint32, uint16, or uint8,
the data type of the output is 32-, 16-, or 8-bit unsigned integers,
respectively.
If label exceeds data type size, mark remaining regions using
Use this parameter to specify the block’s behavior if the number
of found objects exceeds the maximum number that can be
represented by the output data type. If you select Maximum
value of the output data type, the remaining regions are
labeled with the maximum value of the output data type. If you
select Zero, the remaining regions are labeled with zeroes. This
parameter is visible if, for the Output data type parameter, you
choose uint16 or uint8.
1-500
Median Filter
Description The Median Filter block replaces the central value of an M-by-N
neighborhood with its median value. If the neighborhood has a center
element, the block places the median value there, as illustrated in the
following figure.
The block has a bias toward the upper-left corner when the
neighborhood does not have an exact center. See the median value
placement in the following figure.
The block pads the edge of the input image, which sometimes causes the
pixels within [M/2 N/2] of the edges to appear distorted. The median
value is less sensitive than the mean to extreme values. As a result, the
Median Filter block can remove salt-and-pepper noise from an image
without significantly reducing the sharpness of the image.
1-501
Median Filter
Complex
Port Input/Output Supported Data Types Values
Supported
I Matrix of intensity values • Double-precision floating point No
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Val Scalar value that represents Same as I port No
the constant pad value
Output Matrix of intensity values Same as I port No
If the data type of the input signal is floating point, the output has
the same data type. The data types of the signals input to the I and
Val ports must be the same.
1-502
Median Filter
When M is even, fixed-point signals use the accumulator and output data
types. The accumulator data type store the result of the sum performed
while calculating the average of the two central rows of the input
matrix. The output data type stores the total result of the average.
Complex fixed-point inputs use the accumulator parameters. The
calculation for the sum of the squares of the real and imaginary parts of
the input occur, before sorting input elements. The accumulator data
type stores the result of the sum of the squares.
1-503
Median Filter
Dialog The Main pane of the Median Filter dialog box appears as shown in
Box the following figure.
Neighborhood size
Specify the size of the neighborhood over which the block
computes the median.
1-504
Median Filter
1-505
Median Filter
Pad value
Enter the constant value with which to pad your matrix. This
parameter appears if, for the Pad value source parameter, you
select Specify via dialog. Tunable.
The Data Types pane of the Median Filter dialog box appears as
follows. The parameters on this dialog box becomes visible only when
the dimensions of the neighborhood are even.
1-506
Median Filter
Rounding mode
Select the rounding mode for fixed-point operations.
1-507
Median Filter
Overflow mode
Select the overflow mode for fixed-point operations.
Note Only certain cases require the use of the accumulator and
output parameters. Refer to “Fixed-Point Data Types” on page
1-502 for more information.
Accumulator
Use this parameter to specify the accumulator word and fraction
lengths resulting from a complex-complex multiplication in the
block:
• When you select Same as input, these characteristics match
the related input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the accumulator, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the accumulator. This
block requires power-of-two slope and a bias of 0.
Output
Choose how to specify the output word length and fraction length:
• When you select Same as input, these characteristics match
the related input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. This block
requires power-of-two slope and a bias of 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
1-508
Median Filter
1-509
Opening
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating point No
values
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned
integer
Nhood Matrix or vector of ones and Boolean No
zeros that represents the
neighborhood values
Output Scalar, vector, or matrix Same as I port No
of intensity values that
represents the opened
image
The output signal has the same data type as the input to the I port.
1-510
Opening
Dialog The Opening dialog box appears as shown in the following figure.
Box
1-511
Opening
References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.
1-512
Optical Flow
Description
The Optical Flow block estimates the direction and speed of object
motion from one image to another or from one video frame to another
using either the Horn-Schunck or the Lucas-Kanade method.
Complex
Port Output Supported Data Types Values
Supported
I/I1 Scalar, vector, or matrix of • Double-precision floating point No
intensity values
• Single-precision floating point
• Fixed point (supported when
the Method parameter is set to
Lucas-Kanade)
I2 Scalar, vector, or matrix of Same as I port No
intensity values
|V|^2 Matrix of velocity Same as I port No
magnitudes
V Matrix of velocity Same as I port Yes
components in complex
form
1-513
Optical Flow
To compute the optical flow between two images, you must solve the
following optical flow constraint equation:
I x u + I y v + It = 0
• Horn-Schunck Method
• Lucas-Kanade Method
Horn-Schunck Method
By assuming that the optical flow is smooth over the entire image,
the Horn-Schunck method computes an estimate of the velocity field,
⎧⎪⎛ ∂u ⎞2 ⎛ ∂u ⎞2 ⎛ ∂v ⎞2 ⎛ ∂v ⎞2 ⎫⎪
∫∫ x y t ∫∫ ⎨⎪⎜⎝ ∂x ⎟⎠ + ⎜⎝ ∂y ⎟⎠ + ⎜⎝ ∂x ⎟⎠ + ⎜⎝ ∂y ⎟⎠ ⎬⎪dxdy
2
E= ( I u + I v + I ) dxdy + α
⎩ ⎭
∂u ∂u
In this equation, ∂x and ∂y are the spatial derivatives of the optical
velocity component u, and α scales the global smoothness term. The
Horn-Schunck method minimizes the previous equation to obtain the
velocity field, [u v], for each pixel in the image, which is given by the
following equations:
1-514
Optical Flow
k I x [ I x u xk, y + I y v xk, y + It ]
uxk,+y1 = u x, y −
α 2 + I x2 + I 2y
k I y[ I x u xk, y + I y v xk, y + It ]
vxk,+y1 = v x, y −
α 2 + I x2 + I 2y
In this equation, ⎡uxk, y vxk, y ⎤ is the velocity estimate for the pixel at
⎣ ⎦
⎡ k k ⎤
(x,y), and ⎢⎣u x, y v x, y ⎥⎦ is the neighborhood average of ⎡uxk, y vxk, y ⎤ .
⎣ ⎦
For k=0, the initial velocity is 0.
When you choose the Horn-Schunck method, u and v are solved as
follows:
Lucas-Kanade Method
To solve the optical flow constraint equation for u and v, the
Lucas-Kanade method divides the original image into smaller sections
and assumes a constant velocity in each section. Then, it performs a
weighted least-square fit of the optical flow constraint equation to
1-515
Optical Flow
∑ W 2[ I xu + I yv + It ]2
x∈Ω
⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥ ⎡u⎤ = − ⎡⎢∑ W 2 I x It ⎤⎥
⎢ ⎢ ⎥
⎢∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦ ⎣ v ⎦ ⎢⎣∑ W 2 I y It ⎥⎦
⎣
If you are working with fixed-point data types, the kernel values are
signed fixed-point values with word length equal to 16 and fraction
length equal to 15.
1-516
Optical Flow
4 Solve the 2-by-2 linear equations for each pixel using the following
method:
⎡ a b⎤ ⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥
• If A = ⎢ ⎥=⎢
⎣ b c ⎦ ⎢⎣ ∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦
a+c 4b2 + (a − c)2
Then the eigenvalues of A are λ i = ± ; i = 1, 2
2 2
Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, the system of equations are solved using
Cramer’s rule.
Derivative of Gaussian
If you set the temporal gradient filter to Derivative of Gaussian, u
and v are solved using the following steps. You can see the flow chart
for this process at the end of this section:
1-517
Optical Flow
4 Solve the 2-by-2 linear equations for each pixel using the following
method:
⎡ a b⎤ ⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥
• If A = ⎢ ⎥=⎢
⎣ b c ⎦ ⎢⎣ ∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦
a+c 4b2 + (a − c)2
Then the eigenvalues of A are λ i = ± ; i = 1, 2
2 2
• When the block finds the eigenvalues, it compares them to the
threshold, τ , that corresponds to the value you enter for the
1-518
Optical Flow
Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, so the block solves the system of equations using
Cramer’s rule.
1-519
Optical Flow
Threshold
Gradient Gradient Accumulator data type
Image data type data type data type Output
data type data type
SOLVE FIND
CONVOLUTION PRODUCT SMOOTHING LINEAR MOTION
EQUATIONS VECTORS
Output of Ix, Iy, It Ix^2, Motion
Iy^2, (W^2)Ix^2, vectors
each section (W^2)Iy^2, Eigenvalues
of the IxIy,
IxIt, (W^2)IxIy,
algorithm: (W^2)IxIt,
IyIt
(W^2)IyIt
1-520
Optical Flow
1-521
Optical Flow
You can set the product output, accumulator, gradients, threshold, and
output data types in the block mask.
1-523
Optical Flow
Dialog The Main pane of the Optical Flow dialog box appears as shown in
Box the following figure.
Method
Select the method the block uses to calculate the optical flow.
Your choices are Horn-Schunck or Lucas-Kanade.
Compute optical flow between
Select Two images to compute the optical flow between two
images. Select Current frame and N-th frame back to compute
the optical flow between two video frames that are N frames apart.
1-524
Optical Flow
1-525
Optical Flow
1-526
Optical Flow
The Data Types pane of the Optical Flow dialog box appears as shown
in the following figure. The parameters on this dialog box becomes
visible only when the Lucas-Kanade method is selected.
1-527
Optical Flow
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Product output
Use this parameter to specify how to designate the product output
word and fraction lengths.
Accumulator
data type Product
data type
MULTIPLIER
Accumulator
or kernel
data type
1-528
Optical Flow
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output in
bits.
• When you select Slope and bias scaling, you can enter the
word length in bits and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
Accumulator
Use this parameter to specify how to designate this accumulator
word and fraction lengths.
CAST ADDER
Input to adder - Accumulator
Image, gradient, Accumulator
data type data type
or product output
data type
1-529
Optical Flow
1-530
Optical Flow
References [1] Barron, J.L., D.J. Fleet, S.S. Beauchemin, and T.A. Burkitt.
Performance of optical flow techniques. CVPR, 1992.
1-531
Projective Transformation (To Be Removed)
Description
1-532
PSNR
Library Statistics
visionstatistics
Description The PSNR block computes the peak signal-to-noise ratio, in decibels,
between two images. This ratio is often used as a quality measurement
between the original and a compressed image. The higher the PSNR,
the better the quality of the compressed, or reconstructed image.
The Mean Square Error (MSE) and the Peak Signal to Noise Ratio
(PSNR) are the two error metrics used to compare image compression
quality. The MSE represents the cumulative squared error between
the compressed and the original image, whereas PSNR represents a
measure of the peak error. The lower the value of MSE, the lower the
error.
To compute the PSNR, the block first calculates the mean-squared error
using the following equation:
In the previous equation, M and N are the number of rows and columns
in the input images, respectively. Then the block computes the PSNR
using the following equation:
⎛ R2 ⎞
PSNR = 10 log10 ⎜ ⎟
⎜ MSE ⎟
⎝ ⎠
1-533
PSNR
Ports
Complex
Port Output Supported Data Types Values
Supported
I1 Scalar, vector, or matrix • Double-precision floating point No
of intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
I2 Scalar, vector, or matrix Same as I1 port No
of intensity values
Output Scalar value that • Double-precision floating point No
represents the PSNR
For fixed-point or integer input,
the block output is double-precision
floating point. Otherwise, the block
input and output are the same data
type.
1-534
PSNR
Dialog The PSNR dialog box appears as shown in the following figure.
Box
1-535
Read AVI File (To Be Removed)
Library vipobslib
Description
Note The Read AVI File block is obsolete. It may be removed in a
future version of the Computer Vision System Toolbox blocks. Use the
replacement block From Multimedia File.
1-536
Read Binary File
Library Sources
visionsources
Description The Read Binary File block reads video data from a binary file and
imports it into a Simulink model.
This block takes user specified parameters that describe the format of
the video data. These parameters together with the raw binary file,
which stores only raw pixel values, creates the video data signal for a
Simulink model. The video data read by this block must be stored in
row major format.
Note This block supports code generation only for platforms that have
file I/O available. You cannot use this block to do code generation with
Real-Time Windows Target (RTWin).
Complex
Port Output Supported Data Types Values
Supported
Output Scalar, vector, or matrix of • 8-, 16- 32-bit signed integer No
integer values
• 8-, 16- 32-bit unsigned integer
EOF Scalar value Boolean No
1-537
Read Binary File
• Use the Bit stream format parameter to specify whether your data
is planar or packed. If your data is packed, use the Rows and Cols
parameters to define the size of the output matrix.
• Use the Number of output components parameter to specify the
number of components in the binary file. This number corresponds to
the number of block output ports.
• Use the Component, Bits, Rows, and Cols parameters to specify
the component name, bit size, and size of the output matrices,
respectively. The block uses the Component parameter to label
the output ports.
• Use the Component order in binary file parameter to specify how
the components are arranged within the file.
• Select the Interlaced video check box if the binary file contains
interlaced video data.
• Select the Input file has signed data check box if the binary file
contains signed integers.
• Use the Byte order in binary file to indicate whether your binary
file has little endian or big endian byte ordering.
1-538
Read Binary File
Dialog The Read Binary File dialog box appears as shown in the following
Box figure.
File name
Specify the name of the binary file to read. If the location of this
file is on your MATLAB path, enter the filename. If the location of
this file is not on your MATLAB path, use the Browse button to
specify the full path to the file as well as the filename.
Video format
Specify the format of the binary video data. Your choices are
Four character codes or Custom. See “Four Character Code
Video Formats” on page 1-537 or “Custom Video Formats” on page
1-538 for more details.
Four character code
From the drop-down list, select the binary file format.
1-539
Read Binary File
1-540
Read Binary File
1-541
Read Binary File
1-542
Resize
Description The Resize block enlarges or shrinks an image by resizing the image
along one dimension (row or column). Then, it resizes the image along
the other dimension (column or row).
This block supports intensity and color images on its ports. When you
input a floating point data type signal, the block outputs the same data
type.
Shrinking an image can introduce high frequency components into the
image and aliasing might occur. If you select the Perform antialiasing
when resize factor is between 0 and 100 check box, the block
performs low pass filtering on the input image before shrinking it.
Port Description
Complex
Port Input/Output Supported Data Types Values
Supported
Image / M-by-N matrix of intensity • Double-precision floating point No
Input values or an M-by-N-by-P
• Single-precision floating point
color video signal where P is
the number of color planes • Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
ROI Four-element vector [x y • Double-precision floating point No
width height] that defines the (only supported if the input to
ROI the Input port is floating point)
• Single-precision floating point
(only supported if the input to
the Input port is floating point)
1-543
Resize
Complex
Port Input/Output Supported Data Types Values
Supported
ROI Processing
To resize a particular region of each image, select the Enable ROI
processing check box. To enable this option, select the following
parameter values.
If you select the Enable ROI processing check box, the ROI port
appears on the block. Use this port to define a region of interest (ROI)
in the input matrix, that you want to resize. The input to this port must
be a four-element vector, [x y width height]. The first two elements
define the upper-left corner of the ROI, and the second two elements
define the width and height of the ROI.
If you select the Enable ROI processing check box, the Output flag
indicating if any part of ROI is outside 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.
1-544
Resize
Dialog The Main pane of the Resize dialog box appears as shown in the
Box following figure:
1-545
Resize
1-546
Resize
Specify
Specify which aspects of the image to resize. Your choices are
Output size as a percentage of input size, Number of
output columns and preserve aspect ratio, Number of
output rows and preserve aspect ratio, or Number of
output rows and columns.
1-547
Resize
You must enter a scalar value that is greater than zero. The table
below describes the affect of the resize factor value:
number_output_rows =
round(number_input_rows*resize_factor/100);
number_output_cols =
round(number_input_cols*resize_factor/100);
Number of output columns
Enter a scalar value that represents the number of columns you
want the output image to have. This parameter is visible if, for
the Specify parameter, you select Number of output columns
and preserve aspect ratio.
Number of output rows
Enter a scalar value that represents the number of rows you
want the output image to have. This parameter is visible if, for
the Specify parameter, you select Number of output rows and
preserve aspect ratio.
1-548
Resize
When you select Nearest neighbor, the block uses one nearby
pixel to interpolate the pixel value. This option though the most
efficient, is the least accurate. When you select Bilinear, the
block uses four nearby pixels to interpolate the pixel value. When
you select Bicubic or Lanczos2, the block uses 16 nearby pixels to
interpolate the pixel value. When you select Lanczos3, the block
uses 36 surrounding pixels to interpolate the pixel value.
The Resize block performs optimally when you set this parameter
to Nearest neighbor with one of the following conditions:
• You set the Resize factor in % parameter to a multiple of 100.
• Dividing 100 by the Resize factor in % parameter value
results in an integer value.
Perform antialiasing when resize factor is between 0 and 100
If you select this check box, the block performs low-pass filtering
on the input image before shrinking it to prevent aliasing.
Enable ROI processing
Select this check box to resize a particular region of each image.
This parameter is available when the Specify parameter is set
to Number of output rows and columns, the Interpolation
method parameter is set to Nearest neighbor, Bilinear, or
Bicubic, and the Perform antialiasing when resize factor is
between 0 and 100 check box is not selected.
1-549
Resize
The Data Types pane of the Resize dialog box appears as shown in
the following figure.
1-550
Resize
1-551
Resize
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Interpolation weights table
Choose how to specify the word length of the values of
the interpolation weights table. The fraction length of the
interpolation weights table values is always equal to the word
length minus one:
• When you select Same as input, the word length of the
interpolation weights table values match that of the input to
the block.
• When you select Binary point scaling, you can enter the
word length of the interpolation weights table values, in bits.
• When you select Slope and bias scaling, you can enter the
word length of the interpolation weights table values, in bits.
Product output
1-552
Resize
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
Accumulator
1-553
Resize
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Same as input, these characteristics match
those of the input to the block.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. The bias of all
signals in the Computer Vision System Toolbox blocks is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
References [1] Ward, Joseph and David R. Cok. "Resampling Algorithms for
Image Resizing and Rotation", Proc. SPIE Digital Image Processing
Applications, vol. 1075, pp. 260-269, 1989.
1-554
Resize (To Be Removed)
Description
Note This Resize block will be removed in a future release. It uses
the zero-based, [row column] coordinate system. It is recommended
that you replace this block with the updated Resize block that uses the
one-based, [x y] coordinate system.
1-555
Rotate
Description Use the Rotate block to rotate an image by an angle specified in radians.
Note This block supports intensity and color images on its ports.
Port Description
Image M-by-N matrix of intensity values or an M-by-N-by-P color video
signal where P is the number of color planes
Angle Rotation angle
Output Rotated matrix
The Rotate block uses the 3-pass shear rotation algorithm to compute
its values, which is different than the algorithm used by the imrotate
function in the Image Processing Toolbox.
1-556
Rotate
You can set the angle values, product output, accumulator, and output
data types in the block mask.
The Rotate block requires additional data types. The Sine table value
has the same word length as the angle data type and a fraction length
that is equal to its word length minus one. The following diagram shows
how these data types are used inside the block.
1-557
Rotate
1-558
Rotate
Dialog The Main pane of the Rotate dialog box appears as shown in the
Box following figure.
Output size
Specify the size of the rotated matrix. If you select Expanded
to fit rotated input image, the block outputs a matrix that
contains all the rotated image values. If you select Same as input
image, the block outputs a matrix that contains the middle part
of the rotated image. As a result, the edges of the rotated image
might be cropped. Use the Background fill value parameter to
specify the pixel values outside the image.
1-559
Rotate
If you select Input port, the Angle port appears on the block.
The block uses the input to this port at each time step as your
rotation angle. The input to the Angle port must be the same data
type as the input to the I port.
Angle (radians)
Enter a real, scalar value for your rotation angle. This parameter
is visible if, for the Rotation angle source parameter, you select
Specify via dialog.
When the rotation angle is a multiple of pi/2, the block uses a more
efficient algorithm. If the angle value you enter for the Angle
(radians) parameter is within 0.00001 radians of a multiple of
pi/2, the block rounds the angle value to the multiple of pi/2 before
performing the rotation.
Maximum angle (enter pi radians to accommodate all positive
and negative angles)
Enter the maximum angle by which to rotate the input image.
Enter a scalar value, between 0 and radians. The block
determines which angle, 0 ≤ angle ≤ max angle , requires the
largest output matrix and sets the dimensions of the output port
accordingly.
1-560
Rotate
input image are always in contact with the top and left sides of
the output image.
This parameter is visible if, for the Output size parameter, you
select Expanded to fit rotated input image, and, for the
Rotation angle source parameter, you select Input port.
Sine value computation method
Specify the value computation method. If you select
Trigonometric function, the block computes sine and cosine
values it needs to calculate the rotation of your image during the
simulation. If you select Table lookup, the block computes and
stores the trigonometric values it needs to calculate the rotation
of your image before the simulation starts. In this case, the block
requires extra memory.
Background fill value
Specify a value for the pixels that are outside the image.
Interpolation method
Specify which interpolation method the block uses to rotate the
image. If you select Nearest neighbor, the block uses the value
of one nearby pixel for the new pixel value. If you select Bilinear,
the new pixel value is the weighted average of the four nearest
pixel values. If you select Bicubic, the new pixel value is the
weighted average of the sixteen nearest pixel values.
The Data Types pane of the Rotate dialog box appears as shown in
the following figure.
1-561
Rotate
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Angle values
Choose how to specify the word length and the fraction length of
the angle values.
• When you select Same word length as input, the word length
of the angle values match that of the input to the block. In this
1-562
Rotate
This parameter is only visible if, for the Rotation angle source
parameter, you select Specify via dialog.
Product output
1-563
Rotate
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
Accumulator
1-564
Rotate
Supported
Data
Types
If the data type of the input signal is floating point, the output signal is
the same data type as the input signal.
1-565
Rotate
1-566
SAD (To Be Removed)
Library vipobslib
Description
Note The SAD block is obsolete. It may be removed in a future version
of the Computer Vision System Toolboxsoftware. Use the replacement
block Template Matching.
1-567
Shear
Description The Shear block shifts the rows or columns of an image by a gradually
increasing distance left or right or up or down.
Note This block supports intensity and color images on its ports.
Complex
Port Input/Output Supported Data Types Values
Supported
Image M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P color
• Single-precision floating point
video signal where P is the
number of color planes • Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
S Two-element vector that Same as I port No
represents the number of
pixels by which you want to
shift your first and last rows or
columns
Output Shifted image Same as I port No
If the data type of the input to the I port is floating point, the input to
the S port of this block must be the same data type. Also, the block
output is the same data type.
Use the Shear direction parameter to specify whether you want to
shift the rows or columns. If you select Horizontal, the first row
1-568
Shear
1-569
Shear
the new pixel value is the weighted average of the four nearest pixel
values.
The number of pixels the block considers affects the complexity of the
computation. Therefore, the nearest-neighbor interpolation is the most
computationally efficient. However, because the accuracy of the method
is proportional to the number of pixels considered, the bicubic method is
the most accurate. For more information, see “Interpolation Methods”
in the Computer Vision System Toolbox User’s Guide.
If, for the Shear values source parameter, you select Input port, the
S port appears on the block. At each time step, the input to the S port
must be a two-element vector that represents the number of pixels by
which to shift your first and last rows or columns.
If, for the Output size after shear parameter, you select Full, and
for the Shear values source parameter, you select Input port, the
Maximum shear value parameter appears in the dialog box. Use this
parameter to enter a real, scalar value that represents the maximum
number of pixels by which to shear your image. The block uses this
parameter to determine the size of the output matrix. If any input to
the S port is greater than the absolute value of the Maximum shear
value parameter, the block saturates to the maximum value.
1-570
Shear
You can set the product output, accumulator, and output data types
in the block mask.
1-571
Shear
Dialog The Main pane of the Shear dialog box appears as shown in the
Box following figure.
Shear direction
Specify whether you want to shift the rows or columns of the
input image. Select Horizontal to linearly increase the offset of
the rows. Select Vertical to steadily increase the offset of the
columns.
1-572
Shear
The Data Types pane of the Shear dialog box appears as shown in
the following figure.
1-573
Shear
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Shear values
Choose how to specify the word length and the fraction length of
the shear values.
1-574
Shear
• When you select Same word length as input, the word length
of the shear values match that of the input to the block. In this
mode, the fraction length of the shear values is automatically
set to the binary-point only scaling that provides you with the
best precision possible given the value and word length of the
shear values.
• When you select Specify word length, you can enter the word
length of the shear values, in bits. The block automatically sets
the fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the shear values, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the shear values. The bias
of all signals in the Computer Vision System Toolbox blocks is 0.
1-575
Shear
• When you select Binary point scaling, you can enter the
word length and the fraction length of the product output, in
bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the product output. The
bias of all signals in the Computer Vision System Toolbox
blocks is 0.
Accumulator
1-576
Shear
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the accumulator. The bias
of all signals in the Computer Vision System Toolbox blocks is 0.
Output
Choose how to specify the word length and fraction length of the
output of the block:
• When you select Same as first input, these characteristics
match those of the first input to the block at the I port.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the output, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the output. The bias of all
signals in the Computer Vision System Toolbox blocks is 0.
Lock data type settings against change by the fixed-point tools
Select this parameter to prevent the fixed-point tools from
overriding the data types you specify on the block mask. For more
information, see fxptdlg, a reference page on the Fixed-Point
Tool in the Simulink documentation.
1-577
Template Matching
Description
The Template Matching block finds the best match of a template within
an input image. The block computes match metric values by shifting a
template over a region of interest or the entire image, and then finds
the best match location.
Port Description
1-578
Template Matching
1-579
Template Matching
1-580
Template Matching
sizevalid=sizeinput – sizetemplate+1
The output at the Metric port for the Match metric mode is of the
valid image size. The output at the Loc port for the Best match index
mode is a two-element vector of indices relative to the top-left corner
of the input image.
The neighborhood metric output at the NMetric port is of the size NxN,
where N must be an odd number specified in the block mask.
1-581
Template Matching
1-582
Template Matching
1-583
Template Matching
1 The block compares nine search points in each step. There is a central
point and eight search points located on the search area boundary.
2 The block decrements the step size by one, after each step, ending
the search with a step size of one pixel.
3 At each new step, the block moves the search center to the best
matching point resulting from the previous step. The number one
blue circles in the figure below represent a search with a starting
step size of three. The number two green circles represent the next
search, with step size of two, centered around the best match found
from the previous search. Finally, the number three orange circles
represent the final search, with step size of one, centered around
the previous best match.
1-584
Template Matching
Three-Step Search
1-585
Template Matching
• True, set to 1 indicating the ROI lies completely inside the valid part
of the input image.
• False, set to 0 indicating the ROI lies completely or partially outside
of the valid part of the input image.
Valid Neighborhood
The neighborhood matrix of metric values is valid inside of the Region
of Interest (ROI). You can use the Boolean flag at the NValid port to
track the valid neighborhood region. The block sets the neighborhood
NValid boolean flag output as follows:
Algorithm The match metrics use a difference equation with general form:
n 1
d p ( x, y) = (∑ xi − yi )
p p
i=1
n n
lnp denotes the metric space ( R , d p ) for R n > 1.
n
d1 ( I j , T ) = ∑ Ii, j − Ti
i=1
1-586
Template Matching
n
2
d2 ( I j , T ) = ∑ Ii, j − Ti
i=1
n
p
d∞ ( I j , T ) = lim
x →∞
∑ Ii, j − Ti
i=1
which simplifies to:
n p
d∞ ( I j , T ) = max Ii, j − Ti
i
Main The Main pane of the Template Matching block appears as shown in
Dialog the following figure.
Box
1-587
Template Matching
1-588
Template Matching
Match metric
Select one of three types of match metrics:
Output
Select one of two output types:
• Metric matrix
Select this option to output the match metric matrix. This option
adds the Metric output port to the block.
• Best match location
Select this option to output the [x y] coordinates for the location of the
best match. This option adds the Loc output port to the block. When
you select Best match location, the Search method, Output
NxN matrix of metric values around best match, and Enable
ROI processing parameter options appear.
Search method
This option appears when you select Best match location for the
Output parameter. Select one of two search methods.
• Exhaustive
• Three-step
1-589
Template Matching
N
This option appears when you select the Output NxN matrix of
metric values around best match check box. Enter an integer
number that determines the size of the N-by-N output matrix centered
around the best match location index. N must be an odd number.
Enable ROI processing
This option appears when you select Best match location for the
Output parameter. Select the check box for the Template Matching
block to perform region of interest processing. When you do so, the
block adds the ROI input port, and the Output flag indicating if ROI
is valid check box appears. The ROI input must have the format [x y
width height], where [x y] are the coordinates of the upper-left corner
of the ROI.
Output flag indicating if ROI is valid
This option appears when you select the Enable ROI processing
check box. Select the check box for the Template Matching block
to indicate whether the ROI is within the valid region of the image
boundary. When you do so, the block adds the ROIValid output port.
Data The Data Types pane of the Template Matching block dialog box
Types appears as shown in the following figure.
Dialog
Box
1-590
Template Matching
1-591
Template Matching
Rounding mode
Select the “Rounding Modes” for fixed-point operations.
Overflow mode
Select the Overflow mode for fixed-point operations.
• Wrap
• Saturate
Product output
Accumulator
Use this parameter to specify how you would like to designate the
accumulator word and fraction lengths.
1-592
Template Matching
When you select Slope and bias scaling, you can enter the Word
length, in bits, and the Slope of the Accumulator. All signals in
the Computer Vision System Toolbox software have a bias of 0.
The block casts inputs to the Accumulator to the accumulator data
type. It adds each element of the input to the output of the adder,
which remains in the accumulator data type. Use this parameter to
specify how to designate this accumulator word and fraction lengths.
Output
Choose how to specify the Word length, Fraction length and Slope
of the Template Matching output:
The Output parameter on the Data Types pane appears when you
select Metric matrix or if you select Best match location and the
Output NxN matrix of metric values around best match check
box is selected.
Reference [1] Koga T., et. Al. Motion-compensated interframe coding for video
conferencing. In National Telecommunications Conference. Nov. 1981,
G5.3.1–5, New Orleans, LA.
1-593
Template Matching
[3] Yu, J., J. Amores, N. Sebe, Q. Tian, "A New Study on Distance
Metrics as Similarity Measurement" IEEE International Conference
on Multimedia and Expo, 2006 .
1-594
Template Matching (To Be Removed)
Description
1-595
To Multimedia File
Library Sinks
visionsinks
Description
The To Multimedia File block writes video frames, audio samples, or
both to a multimedia (.avi, .wav, .wma, .mj2, .mp4, .m4v, or
.wmv) file.
Note This block supports code generation for platforms that have file
I/O available. You cannot use this block with Real-Time Windows
Target software, because that product does not support file I/O.
The generated code for this block relies on prebuilt library files. You
can run this code outside the MATLAB environment, or redeploy it,
but be sure to account for these extra library files when doing so. The
1-596
To Multimedia File
packNGo function creates a single zip file containing all of the pieces
required to run or rebuild this code. See packNGo for more information.
To run an executable file that was generated from a model containing
this block, you may need to add precompiled shared library files to
your system path. See “Simulink Coder”, “Simulink Shared Library
Dependencies”, and “Accelerating Simulink Models” for details.
This block allows you to write .wma/.mwv streams to disk or across a
network connection. Similarly, the From Multimedia File block allows
you to read .wma/.mwv streams to disk or across a network connection.
If you want to play an MP3/MP4 file in Simulink, but you do not
have the codecs, you can re-encode the file as .wma/.mwv, which are
supported by the Computer Vision System Toolbox.
Ports
Port Description
Image M-by-N-by-3 matrix RGB, Intensity, or YCbCr 4:2:2 signal.
R, G, B Matrix that represents one plane of the RGB video stream.
Inputs to the R, G, or B port must have the same dimensions
and data type.
Audio Vector of audio data
Y, Cb, Cr Matrix that represents one frame of the YCbCr video stream.
The Y, Cb, and Cr ports use the following dimensions:
Y: M x N
N
Cb: M x 2
N
Cr: M x 2
1-597
To Multimedia File
Dialog The Main pane of the To Multimedia File block dialog appears as
Box follows.
File name
Specify the name of the multimedia file. The block saves the file
in your current folder. To specify a different file or location, click
the Save As... button.
1-598
To Multimedia File
File type
Specify the file type of the multimedia file. You can select avi,
wav, wma, or wmv.
Write
Specify whether the block writes video frames, audio samples, or
both to the multimedia file. You can select Video and audio,
Video only, or Audio only.
Audio compressor
Select the type of compression algorithm to use to compress the
audio data. This compression reduces the size of the multimedia
file. Choose None (uncompressed) to save uncompressed audio
data to the multimedia file.
1-599
To Multimedia File
Supported For the block to display video data properly, double- and single-precision
Data floating-point pixel values must be between 0 and 1. Any other data
Types type requires the pixel values between the minimum and maximum
values supported by their data type.
Check the specific codecs you are using for supported audio rates.
Supports Complex
Port Supported Data Types Values?
Image • Double-precision floating point No
• Single-precision floating point
• Boolean
• 8-, 16- 32-bit signed integers
• 8-, 16- 32-bit unsigned integers
R, G, B Same as Image port No
1-600
To Multimedia File
Supports Complex
Port Supported Data Types Values?
Audio • Double-precision floating point No
• Single-precision floating point
• 16-bit signed integers
• 32-bit signed integers
• 8-bit unsigned integers
Y, Cb, Cr Same as Image port No
1-601
To Video Display
Library Sinks
visionsinks
Description
The To Video Display block sends video data to your computer screen.
It provides a Windows only, lightweight, high performance, simple
display, which accepts RGB and YCbCr formatted images. This block
also generates code.
The generated code for this block relies on prebuilt .dll files. You can
run this code outside the MATLAB environment, or redeploy it, but be
sure to account for these extra .dll files when doing so. The packNGo
function creates a single zip file containing all of the pieces required to
run or rebuild this code. See packNGo for more information.
To run an executable file that was generated from a model containing
this block, you may need to add precompiled shared library files to
your system path. See “Simulink Coder”, “Simulink Shared Library
Dependencies”, and “Accelerating Simulink Models” for details.
1-602
To Video Display
For the block to display video data properly, double- and single-precision
floating-point pixel values must be from 0 to 1. For any other data type,
the pixel values must be between the minimum and maximum values
supported by their data type.
You can set the display for full screen, normal or, to maintain one-to-one
size. When you save the model, the size and position of the display
window is saved. Any changes while working with the model should
be saved again in order that these preferences are maintained when
you run the model. The minimum display width of the window varies
depending on your system’s font size settings.
This block runs in real-time, and may limit the speed at which video
data displays. It operates and renders video data to the display
independent of the Simulink model. This design allows buffering to the
display, which increases performance. You may notice, the block lags
the model by one or more frames.
Rapid Accelerator
When you set your model to run in “Accelerator Mode”, and do not select
the Open at Start of Simulation option, the block will not be included
during the run, and therefore the video display will not be visible. For
Rapid Accelerator mode, menu preferences are saved only when the
model is compiled. To change any of the menu options, change the
model to run in “Normal Mode”, and re-save it. You can then run in
Rapid Accelerator mode with the new preferences.
Menu The To Video Display block provides menu options to modify viewing
Options preferences for the display. If however, your model is set to run in
“Accelerator Mode”, the menu options will not be available.
View menu
Window Size
1-603
To Video Display
M-by- N
2 matrix.
Image Signal
Specify how the block accepts a color video signal.
Select One multidimensional signal, for the block to accept
an M-by-N-by-3 color video signal at one port.
Select Separate color signals, for additional ports to appear
on the block. Each port accepts one M-by-N plane of an RGB
video stream.
Preferences
Set any preferences available for the Computer Vision System
Toolbox. You can set your model to use hardware acceleration,
by selecting the Use hardware acceleration checkbox in the
1-604
To Video Display
Help menu
Help
Supported
Data
Types
1-605
To Video Display
1-606
Top-hat
Complex
Port Input/Output Supported Data Types Values
Supported
I Vector or matrix of intensity • Double-precision floating No
values point
• Single-precision floating
point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
Nhood Matrix or vector of 1s and 0s that Boolean No
represents the neighborhood
values
Output Scalar, vector, or matrix that Same as I port No
represents the filtered image
1-607
Top-hat
If your input image is a binary image, for the Input image type
parameter, select Binary. If your input image is an intensity image,
select Intensity.
Use the Neighborhood or structuring element source parameter to
specify how to enter your neighborhood or structuring element values.
If you select Specify via dialog, the Neighborhood or structuring
element parameter appears in the dialog box. If you select Input
port, the Nhood port appears on the block. Use this port to enter your
neighborhood values as a matrix or vector of 1s and 0s. Choose your
structuring element so that it matches the shapes you want to remove
from your image. You can only specify a it using the dialog box.
Use the Neighborhood or structuring element parameter to
define the region the block moves throughout the image. Specify a
neighborhood by entering a matrix or vector of 1s and 0s. Specify a
structuring element with the strel function from the Image Processing
Toolbox. If the structuring element is decomposable into smaller
elements, the block executes at higher speeds due to the use of a more
efficient algorithm.
1-608
Top-hat
Dialog The Top-hat dialog box appears as shown in the following figure.
Box
1-609
Top-hat
1-610
Trace Boundaries (To Be Removed)
Description
Note This Trace Boundaries block will be removed in a future
release. It uses the zero-based, [row column] coordinate system. It
is recommended that you replace this block with the updated Trace
Boundary block that uses the one-based, [x y] coordinate system.
1-611
Trace Boundary
Description
1-612
Trace Boundary
of boundary pixels
parameter.
x1 y1
x y2
2
x3 y3
. .
. .
. .
x ym
m
1-613
Trace Boundary
Dialog The Trace Boundary dialog box appears as shown in the following figure.
Box
Connectivity
Specify which pixels are connected to each other. If you want a
pixel to be connected to the pixels on the top, bottom, left, and
right, select 4. If you want a pixel to be connected to the pixels
1-614
Trace Boundary
on the top, bottom, left, right, and diagonally, select 8. For more
information about this parameter, see the Label block reference
page.
Initial search direction
Specify the first direction in which to look to find the next
boundary pixel that is connected to the starting pixel.
North
West East
South
North
Northwest Northeast
West East
Trace direction
Specify the direction in which to trace the boundary. Your choices
are Clockwise or Counterclockwise.
1-615
Trace Boundary
1-616
Translate
Note This block supports intensity and color images on its ports.
Complex
Port Input/Output Supported Data Types Values
Supported
Image / M-by-N matrix of intensity • Double-precision floating No
Input values or an M-by-N-by-P color point
video signal where P is the
• Single-precision floating
number of color planes
point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned
integer
Offset Vector of values that represent Same as I port No
the number of pixels by which to
translate the image
Output Translated image Same as I port No
The input to the Offset port must be the same data type as the input
to the Image port. The output is the same data type as the input to
the Image port.
1-617
Translate
1-618
Translate
If, for the Output size after translation parameter, you select Full,
and for the Translation values source parameter, you select Input
port, the Maximum offset parameter appears in the dialog box. Use
the Maximum offset parameter to enter a two-element vector of real,
scalar values that represent the maximum number of pixels by which
you want to translate your image. The block uses this parameter to
determine the size of the output matrix. If the input to the Offset port
is greater than the Maximum offset parameter values, the block
saturates to the maximum values.
If, for the Translation values source parameter, you select Input
port, the Offset port appears on the block. At each time step, the input
to the Offset port must be a vector of real, scalar values that represent
the number of pixels by which to translate your image.
1-619
Translate
You can set the product output, accumulator, and output data types in
the block mask as discussed in the next section.
Dialog The Main pane of the Translate dialog box appears as shown in the
Box following figure.
1-620
Translate
1-621
Translate
The Data Types pane of the Translate dialog box appears as shown in
the following figure.
1-622
Translate
1-623
Translate
Rounding mode
Select the rounding mode for fixed-point operations.
Overflow mode
Select the overflow mode for fixed-point operations.
Offset values
Choose how to specify the word length and the fraction length of
the offset values.
• When you select Same word length as input, the word length
of the offset values match that of the input to the block. In this
mode, the fraction length of the offset values is automatically
set to the binary-point only scaling that provides you with the
best precision possible given the value and word length of the
offset values.
• When you select Specify word length, you can enter the word
length of the offset values, in bits. The block automatically sets
the fraction length to give you the best precision.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the offset values, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the offset values. The bias
of all signals in the Computer Vision System Toolbox blocks is 0.
1-624
Translate
1-625
Translate
1-626
Video From Workspace
Library Sources
visionsources
Description
The Video From Workspace block imports a video signal from the
MATLAB workspace. If the video signal is a M-by-N-by-T workspace
array, the block outputs an intensity video signal, where M and N
are the number of rows and columns in a single video frame, and T
is the number of frames in the video signal. If the video signal is a
M-by-N-by-C-by-T workspace array, the block outputs a color video
signal, where M and N are the number of rows and columns in a single
video frame, C is the number of color channels, and T is the number of
frames in the video stream. In addition to the video signals previously
described, this block supports fi objects.
Note If you generate code from a model that contains this block,
Simulink Coder takes a long time to compile the code because it puts all
of the video data into the .c file. Before you generate code, you should
convert your video data to a format supported by the From Multimedia
File block or the Read Binary File block.
1-627
Video From Workspace
Complex
Port Output Supported Data Types Values
Supported
Image M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P color
• Single-precision floating point
video signal where P is the
number of color planes • Fixed point
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
For the Computer Vision System Toolbox blocks to display video data
properly, double- and single-precision floating-point pixel values must
be from 0 to 1. This block does not scale pixel values.
Use the Signal parameter to specify the MATLAB workspace variable
from which to read. For example, to read an AVI file, use the following
syntax:
mov = VideoReader('filename.avi')
If filename.avi has a colormap associated with it, the AVI file must
satisfy the following conditions or the block produces an error:
1-628
Video From Workspace
Use the Sample time parameter to set the sample period of the output
signal.
When the block has output all of the available signal samples, it can
start again at the beginning of the signal, repeat the final value, or
generate 0s until the end of the simulation. The Form output after
final value by parameter controls this behavior:
Use the Image signal parameter to specify how the block outputs a
color video signal. If you select One multidimensional signal, the
block outputs an M-by-N-by-P color video signal, where P is the number
of color planes, at one port. If you select Separate color signals,
additional ports appear on the block. Each port outputs one M-by-N
plane of an RGB video stream.
Use the Output port labels parameter to label your output ports. Use
the spacer character, |, as the delimiter. This parameter is available
when the Image signal parameter is set to Separate color signals.
1-629
Video From Workspace
Dialog The Video From Workspace dialog box appears as shown in the
Box following figure.
1-630
Video From Workspace
Signal
Specify the MATLAB workspace variable that contains the
video signal, or use the VideoReader function to specify an AVI
filename.
Sample time
Enter the sample period of the output.
Form output after final value by
Specify the output of the block after all of the specified signal
samples have been generated. The block can output zeros for the
duration of the simulation (Setting to zero), repeat the final
value (Holding Final Value) or repeat the entire signal from the
beginning (Cyclic Repetition).
Image signal
Specify how the block outputs a color video signal. If you select One
multidimensional signal, the block outputs an M-by-N-by-P
color video signal, where P is the number of color planes, at one
port. If you select Separate color signals, additional ports
appear on the block. Each port outputs one M-by-N plane of an
RGB video stream.
Output port labels
Enter the labels for your output ports using the spacer character,
|, as the delimiter. This parameter is available when the Image
signal parameter is set to Separate color signals.
1-631
Video To Workspace
Library Sinks
visionsinks
Description The Video To Workspace block exports a video signal to the MATLAB
workspace. If the video signal is represented by intensity values, it
appears in the workspace as a three-dimensional M-by-N-by-T array,
where M and N are the number of rows and columns in a single video
frame, and T is the number of frames in the video signal. If it is a
color video signal, it appears in the workspace as a four-dimensional
M-by-N-by-C-by-T array, where M and N are the number of rows and
columns in a single video frame, C is the number of inputs to the
block, and T is the number of frames in the video stream. During code
generation, Simulink Coder does not generate code for this block.
Note This block supports intensity and color images on its ports.
Complex
Port Input Supported Data Types Values
Supported
Image M-by-N matrix of intensity • Double-precision floating point No
values or an M-by-N-by-P color
• Single-precision floating point
video signal where P is the
number of color planes • Fixed point
• Boolean
• 8-, 16-, 32-bit signed integer
1-632
Video To Workspace
Complex
Port Input Supported Data Types Values
Supported
1-633
Video To Workspace
Dialog The Video To Workspace dialog box appears as shown in the following
Box figure.
Variable name
Specify the MATLAB workspace variable to which to write the
video signal.
Number of inputs
Enter the number of inputs to the block. If the video signal is black
and white, enter 1. If it is a color (R, G, B) video signal, enter 3.
Limit data points to last
Enter the number of video frames to export to the MATLAB
workspace.
Decimation
Enter your decimation factor.
1-634
Video To Workspace
1-635
Video Viewer
Library Sinks
visionsinks
Description The Video Viewer block enables you to view a binary, intensity, or RGB
image or a video stream. The block provides simulation controls for
play, pause, and step while running the model. The block also provides
pixel region analysis tools. During code generation, Simulink Coder
software does not generate code for this block.
Input Description
Image M-by-N matrix of intensity values or an
M-by-N-by-P color video signal where P is the
number of color planes.
R/G/B Scalar, vector, or matrix that represents one plane
of the RGB video stream. Inputs to the R, G, or
B ports must have the same dimensions and data
type.
Select File > Image Signal to set the input to either Image or RGB.
1-636
Video Viewer
Dialogs
1-637
Video Viewer
Toolbar
Toolbar
Note The Image Tool can only know that the frame is an intensity
image if the colormap of the frame is grayscale (gray(256)).
Otherwise, the Image Tool assumes the frame is an indexed image
and disables the Adjust Contrast button.
1-638
Video Viewer
Toolbar (Continued)
1-639
Video Viewer
Playback Toolbar
Playback Toolbar
1-640
Video Viewer
Core Pane
The Core pane in the Viewer Configuration dialog box controls the
GUI’s general settings.
1-641
Video Viewer
General UI
Click General UI, and click the Options button to open the General
UI Options dialog box.
If you select the Display the full source path in the title bar check
box, the GUI displays the model name and full Simulink path to the
video data source in the title bar. Otherwise, it displays a shortened
name.
Use the Open message log: parameter to control when the Message
log window opens. You can use this window to debug issues with video
playback. Your choices are for any new messages, for warn/fail
messages, only for fail messages, or manually.
Tools Pane
The Tools pane in the Viewer Configuration dialog box contains the
tools that appear on the Video Viewer GUI. Select the Enabled check
box next to the tool name to specify which tools to include on the GUI.
1-642
Video Viewer
Image Tool
Click Image Tool, and then click the Options button to open the
Image Tool Options dialog box.
Select the Open new Image Tool window for export check box if
you want to open a new Image Tool for each exported frame.
1-643
Video Viewer
Pixel Region
Select the Pixel Region check box to display and enable the pixel
region GUI button. For more information on working with pixel regions
see Getting Information about the Pixels in an Image.
Instrumentation Set
Select the Instrumentation Set check box to enable the option to load
and save viewer settings. The option appears in the File menu.
Video Information
The Video Information dialog box lets you view basic information
about the video. To open this dialog box, you can select Tools > Video
Information , click the information button , or press the V key.
1-644
Video Viewer
Status Bar
A status bar appear along the bottom of the Video Viewer. It displays
information pertaining to the video status (running, paused or ready),
type of video (Intensity or RGB) and video time.
Message Log
The Message Log dialog provides a system level record of configurations
and extensions used. You can filter what messages to display by Type
and Category, view the records, and display record details.
The Type parameter allows you to select either All, Info, Warn, or
Fail message logs. The Category parameter allows you to select either
1-645
Video Viewer
Supported
Data
Types
1-646
Video Viewer
1-647
Write AVI File (To Be Removed)
Library Sinks
Description
Note The Write AVI File block is obsolete. It may be removed in a
future version of the Computer Vision System Toolbox blocks. Use the
replacement block To Multimedia File.
1-648
Write Binary File
Library Sinks
visionsinks
Description The Write Binary File block takes video data from a Simulink model
and exports it to a binary file.
This block produces a raw binary file with no header information. It
has no encoded information providing the data type, frame rate or
dimensionality. The video data for this block appears in row major
format.
Note This block supports code generation only for platforms that have
file I/O available. You cannot use this block to do code generation with
Real-Time Windows Target (RTWin).
Complex
Port Input Supported Data Types Values
Supported
Input Matrix that represents the • 8-, 16- 32-bit signed integer No
luma (Y') and chroma (Cb
• 8-, 16- 32-bit unsigned integer
and Cr) components of a video
stream
1-649
Write Binary File
• Use the Bit stream format parameter to specify whether you want
your data in planar or packed format.
• Use the Number of input components parameter to specify the
number of components in the video stream. This number corresponds
to the number of block input ports.
• Select the Inherit size of components from input data type
check box if you want each component to have the same number of
bits as the input data type. If you clear this check box, you must
specify the number of bits for each component.
• Use the Component parameters to specify the component names.
• Use the Component order in binary file parameter to specify how
to arrange the components in the binary file.
• Select the Interlaced video check box if the video stream represents
interlaced video data.
• Select the Write signed data to output file check box if your input
data is signed.
• Use the Byte order in binary file parameter to specify whether the
byte ordering in the output binary file is little endian or big endian.
1-650
Write Binary File
Dialog The Write Binary File dialog box appears as shown in the following
Box figure.
File name
Specify the name of the binary file. To specify a different file or
location, click the Save As... button.
Video format
Specify the format of the binary video data as eitherFour
character codes or Custom. See “Four Character Code Video
Formats” on page 1-649 or “Custom Video Formats” on page 1-649
for more details.
Four character code
From the list, select the binary file format.
1-651
Write Binary File
Line ordering
Specify how the block fills the binary file. If you select Top line
first, the block first fills the binary file with the first row of the
video frame. It then fills the file with the other rows in increasing
order. If you select Bottom line first, the block first fills the
binary file with the last row of the video frame. It then fills the
file with the other rows in decreasing order.
Bit stream format
Specify whether you want your data in planar or packed format.
Number of input components
Specify the number of components in the video stream. This
number corresponds to the number of block input ports.
Inherit size of components from input data type
Select this check box if you want each component to have the
same number of bits as the input data type. If you clear this check
box, you must specify the number of bits for each component.
Component
Specify the component names.
Component order in binary file
Specify how to arrange the components in the binary file.
Interlaced video
Select this check box if the video stream represents interlaced
video data.
Write signed data to output file
Select this check box if your input data is signed.
Byte order in binary file
Use this parameter to specify whether the byte ordering in the
output binary file is little endian or big endian.
1-652
2
Alphabetical List
binaryFeatures
Description This object provides the ability to pass data between the
extractFeatures and matchFeatures functions. It can also be used to
manipulate and plot the data returned by extractFeatures.
Input Arguments
featureVectors
Input feature vectors, specified as an M-by-N input matrix. This
matrix contains M binary feature vectors stored in N uint8
containers.
Properties Features
Feature vectors, stated as an M-by-N input matrix. This matrix
consists of M feature vectors stored in N uint8 containers.
NumBits
Number of bits per feature, which is the number of uint8 feature
vector containers times 8.
NumFeatures
Number of feature vectors contained in the binaryFeatures
object.
2-2
binaryFeatures
2-3
vision.CameraParameters
Description
Note vision.CameraParameters will be removed in a future version.
Use cameraParameters instead.
2-4
cameraParameters
Description This object contains the intrinsic, extrinsic, and lens distortion
parameters of a camera.
Input The object contains intrinsic, extrinsic, lens distortion, and estimation
Arguments properties.
2-5
cameraParameters
f 0 0
x
s fy 0
cx cy 1
The coordinates [cx cy] represent the optical center (the principal
point), in pixels. When the x and y axis are exactly perpendicular,
the skew parameter, s, equals 0.
fx = F*sx
fy = F*sy
2-6
cameraParameters
2-7
cameraParameters
2-8
cameraParameters
2-9
cameraParameters
R
s x y 1 X Y Z 1 K
t
R is the 3-D rotation matrix.
t is the translation vector.
K is the IntrinsicMatrix.
s is a scalar.
This equation does not take distortion into consideration.
Distortion is removed by the undistortImage function.
You must set the RotationVectors and TranslationVectors
properties together in the constructor to ensure that the number
of rotation vectors equals the number of translation vectors.
Setting only one property results in an error.
’WorldPoints’ - World coordinates
M-by-2 array | []
World coordinates of key points on calibration pattern, specified
as the comma-separated pair consisting of ’WorldPoints’ and
an M-by-2 array. M represents the number of key points in the
pattern.
’WorldUnits’ - World points units
'mm' (default) | string
World points units, specified as the comma-separated pair
consisting of ’WorldUnits’ and a string. The string describes the
units of measure.
’EstimateSkew’ - Estimate skew flag
false (default) | logical scalar
Estimate skew flag, specified as the comma-separated pair
consisting of ’EstimateSkew’ and a logical scalar. When you set
the logical to true, the object estimates the image axes skew.
When you set the logical to false, the image axes are exactly
perpendicular.
2-10
cameraParameters
2-11
cameraParameters
f 0 0
x
s fy 0
cx cy 1
The coordinates [cx cy] represent the optical center (the principal
point), in pixels. When the x and y axis are exactly perpendicular,
the skew parameter, s, equals 0.
fx = F*sx
fy = F*sy
F, is the focal length in world units, typically expressed in
millimeters.
[sx, sy] are the number of pixels per world unit in the x and y
direction respectively.
fx and fy are expressed in pixels.
2-12
cameraParameters
r2 = x 2 + y 2
Typically, two coefficients are sufficient. For severe distortion,
you can include k3. The undistorted pixel locations appear in
normalized image coordinates, with the origin at the optical
center. The coordinates are expressed in world units.
TangentialDistortion - Tangential distortion coefficients
2-element vector | [0 0]' (default)
Tangential distortion coefficients, specified as a 2-element vector.
Tangential distortion occurs when the lens and the image plane
are not parallel. The camera parameters object calculates the
tangential distorted location of a point. You can denote the
distorted points as (xdistorted, ydistorted), as follows:
2-13
cameraParameters
R
s x y 1 X Y Z 1 K
t
R is the 3-D rotation matrix.
t is the translation vector.
K is the IntrinsicMatrix.
s is a scalar.
This equation does not take distortion into consideration.
Distortion is removed by the undistortImage function.
TranslationVectors - Camera translations
M-by-3 matrix | []
Camera translations, specified as an M-by-3 matrix. This matrix
contains translation vectors for M images. The vectors contain
the calibration pattern that estimates the calibration parameters.
Each row of the matrix contains a vector that describes the
translation of the camera relative to the corresponding pattern,
expressed in world units.
The following equation provides the transformation that relates a
world coordinate [X Y Z] and the corresponding image point [x y]:
R
s x y 1 X Y Z 1 K
t
R is the 3-D rotation matrix.
t is the translation vector.
K is the IntrinsicMatrix.
s is a scalar.
This equation does not take distortion into consideration.
Distortion is removed by the undistortImage function.
You must set the RotationVectors and TranslationVectors
properties in the constructor to ensure that the number of rotation
vectors equals the number of translation vectors. Setting only one
property but not the other results in an error.
2-14
cameraParameters
2-15
cameraParameters
2-16
cameraParameters
IntrinsicMatrix = [715.2699 0 0;
0 711.5281 0;
565.6995 355.3466 1];
radialDistortion = [-0.3361 0.0921];
cameraParams = cameraParameters('IntrinsicMatrix', IntrinsicMatrix
2-17
cameraParameters
References
[1] Zhang, Z. “A flexible new technique for camera calibration”. IEEE
Transactions on Pattern Analysis and Machine Intelligence, Vol. 22, No.
11, pp. 1330–1334, 2000.
2-18
cameraParameters
2-19
BRISKPoints
Description This object provides the ability to pass data between the
detectBRISKFeatures and extractFeatures functions. You can also
use it to manipulate and plot the data returned by these functions. You
can use the object to fill the points interactively in situations where you
might want to mix a non-BRISK interest point detector with a BRISK
descriptor.
2-20
BRISKPoints
Input Arguments
Location
Point locations, specified as an M-by-2 array of [x y] point
coordinates.
Properties Scale
Scale at which the feature is detected, specified as a value greater
than or equal to 1.6.
Default: 12.0
Metric
Strength of detected feature, specified as a numeric value. The
BRISK algorithm uses a determinant of an approximated Hessian.
Default: 0.0
Orientation
Orientation of the detected feature, specified as an angle, in
radians. The angle is measured counterclockwise from the X-axis
with the origin specified by the Location property. Do not set
this property manually. Use the call to extractFeatures to
fill in this value. The extractFeatures function modifies the
default value of 0.0. Using BRISK interest points to extract a
non-BRISK descriptor, (e.g. SURF, FREAK, MSER, etc.), can
alter Orientation values. The Orientation is mainly useful for
visualization purposes.
Default: 0.0
Count
Number of points held by the BRISK object, specified as a numeric
value.
2-21
BRISKPoints
Default: 0
I = imread('cameraman.tif');
points = detectBRISKFeatures(I);
strongest = points.selectStrongest(10);
imshow(I); hold on;
plot(strongest);
2-22
BRISKPoints
strongest.Location
ans =
136.4033 55.5000
155.6964 83.7577
197.0000 233.0000
117.3680 92.3680
147.0000 162.0000
104.0000 229.0000
129.7972 68.2028
2-23
BRISKPoints
154.8790 77.0000
118.0269 174.0269
131.0000 91.1675
References [1] Leutenegger, S., M. Chli, and R. Siegwart. BRISK: Binary Robust
Invariant Scalable Keypoints, Proceedings of the IEEE International
Conference on Computer Vision (ICCV) 2011.
2-24
BRISKPoints.isempty
Syntax isempty(BRISKPointsObj)
2-25
BRISKPoints.length
Syntax length(BRISKPointsObj)
2-26
BRISKPoints.plot
Syntax briskPoints.plot
briskPoints.plot(AXES_HANDLE,...)
briskPoints.plot(AXES_HANDLE,Name,Value)
Input AXES_HANDLE
Arguments Handle for plot method to use for display. You can set the handle
using gca.
showScale
Display proportional circle around feature. Set this value to true
or false. When you set this value to true, the object draws a
circle proportional to the scale of the detected feature, with the
feature point located at its center. When you set this value to
false, the object turns the display of the circle off.
The algorithm represents the scale of the feature with a circle of
6*Scale radius. The BRISK algorithm uses this equivalent size of
circular area to compute the orientation of the feature.
2-27
BRISKPoints.plot
Default: true
showOrientation
Display a line corresponding to feature point orientation. Set this
value to true or false. When you set this value to true, the
object draws a line corresponding to the point’s orientation. The
object draws the line from the feature point location to the edge of
the circle, indicating the scale.
Default: false
% Display
imshow(I); hold on;
plot(points);
2-28
BRISKPoints.selectStrongest
2-29
BRISKPoints.size
Syntax size(BRISKPointsObj)
2-30
MSERRegions
Description This object describes MSER regions and corresponding ellipses that
have the same second moments as the regions. It passes data between
the detectMSERFeatures and extractFeatures functions. The object
can also be used to manipulate and plot the data returned by these
functions.
Input Arguments
pixellist
M-by-2 cell array of [x y] coordinates of the detected MSER
regions.
2-31
MSERRegions
Properties The following properties are read-only and are calculated once the input
pixel list is specified.
Count
Number of stored regions
Default: 0
Location
An M-by-2 array of [x y] centroid coordinates of ellipses that have
the same second moments as the MSER regions.
Axes
A two-element vector, [majorAxis minorAxis]. This vector
specifies the major and minor axis of the ellipse that have the
same second moments as the MSER regions.
Orientation
A value in the range from -pi/2 to +pi/2 radians. This value
represents the orientation of the ellipse as measured from the
X-axis to the major axis of the ellipse. You can use this property
for visualization purposes.
Load an image.
I = imread('cameraman.tif');
2-32
MSERRegions
regions = detectMSERFeatures(I);
2-33
MSERRegions
I = imread('cameraman.tif');
regions = detectMSERFeatures(I);
Read image.
2-34
MSERRegions
I = imread('cameraman.tif');
regionsObj = detectMSERFeatures(I);
References [1] Nister, D., and H. Stewenius, "Linear Time Maximally Stable
Extremal Regions", Lecture Notes in Computer Science. 10th European
Conference on Computer Vision, Marseille, France: 2008, no. 5303,
pp. 183–196.
[2] Matas, J., O. Chum, M. Urba, and T. Pajdla. "Robust wide baseline
stereo from maximally stable extremal regions. "Proceedings of British
Machine Vision Conference, pages 384-396, 2002.
2-35
MSERRegions
2-36
MSERRegions.isempty
Syntax isempty(MSERRegionsObj)
2-37
MSERRegions.length
Syntax length(MSERRegionsObj)
2-38
MSERRegions.plot
Syntax MSERRegions.plot
MSERRegions.plot(AXES_HANDLE,...)
MSERRegions.plot(AXES_HANDLE,Name,Value)
Input AXES_HANDLE
Arguments Handle for plot method to use for display. You can set the handle
using gca.
showEllipses
Display ellipses around feature. Set this value to true or false.
When you set this value to true, the object draws an ellipse with
the same 2nd order moments as the region.
When you set this value to false, only the ellipses centers are
plotted.
Default: true
showOrientation
Display a line corresponding to the region’s orientation. Set this
value to true or false. When you set this value to true, the
object draws a line corresponding to the region’s orientation. The
2-39
MSERRegions.plot
object draws the line from the ellipse’s centroid to the edge of the
ellipse, which indicates the region’s major axis.
Default: false
showPixelList
Display the MSER regions. Set this value to true or false. When
you set this value to true, the object plots the MSER regions
using the JET colormap.
I = imread('cameraman.tif');
regions = detectMSERFeatures(I);
imshow(I);hold on;
plot(regions);
2-40
MSERRegions.size
Syntax size(MSERRegionsObj)
2-41
cornerPoints
Description This object stores information about feature points detected from a
2-D grayscale image.
Input Arguments
Location
M-by-2 array of [x y] point coordinates.
2-42
cornerPoints
’Count’
Number of points held by the object.
Default: 0
’Metric’
Value describing strength of detected feature.
Default: 0.0
I = imread('cameraman.tif');
points = detectHarrisFeatures(I);
2-43
cornerPoints
strongest = points.selectStrongest(10);
imshow(I); hold on;
plot(strongest);
strongest.Location
I = checkerboard(50,2,2);
Load locations.
Save points.
points = cornerPoints(location);
2-44
cornerPoints
2-45
cornerPoints.isempty
Syntax isempty(cornerPointsObj)
2-46
cornerPoints.length
Syntax length(cornerPointsObj)
2-47
cornerPoints.plot
Syntax cornerPoints.plot
cornerPoints.plot(axesHandle, ___ )
Input axesHandle
Arguments Handle for plot method to use for display. You can set the handle
using gca.
Read an image.
I = imread('cameraman.tif');
featurePoints = detectHarrisFeatures(I);
2-48
cornerPoints.selectStrongest
points = points.selectStrongest(2)
2-49
cornerPoints.size
Syntax size(cornerPointsObj)
2-50
SURFPoints
Description This object provides the ability to pass data between the
detectSURFFeatures and extractFeatures functions. It can also be
used to manipulate and plot the data returned by these functions.
You can use the object to fill the points interactively. You can use
this approach in situations where you might want to mix a non-SURF
interest point detector with a SURF descriptor.
2-51
SURFPoints
Input Arguments
Location
M-by-2 array of [x y] point coordinates.
Properties Count
Number of points held by the object.
Default: 0
Scale
Specifies scale at which the interest points were detected. This
value must be greater than or equal to 1.6.
Default: 1.6
Metric
Value describing strength of detected feature. The SURF
algorithm uses a determinant of an approximated Hessian.
Default: 0.0
SignOfLaplacian
Sign of the Laplacian determined during the detection process.
This value must be an integer, -1, 0, or 1. You can use this
parameter to accelerate the feature matching process.
Blobs with identical metric values but different signs of Laplacian
can differ by their intensity values. For example, a white blob on a
blackground versus a black blob on a white background. You can
use this parameter to quickly eliminate blobs that do not match.
For non-SURF detectors, this property is not relevant. For
example, for corner features, you can simply use the default value
of 0.
2-52
SURFPoints
Default: 0
Orientation
Orientation of the detected feature, specified as an angle, in
radians. The angle is measured counter-clockwise from the
X-axis with the origin specified by the Location property. Do
not set this property manually. Rely instead, on the call to
extractFeatures to fill in this value. The extractFeatures
function modifies the default value of 0.0.The Orientation is
mainly useful for visualization purposes.
Default: 0.0
Read in image.
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
strongest = points.selectStrongest(10);
2-53
SURFPoints
strongest.Location
ans =
139.7482 95.9542
107.4502 232.0347
116.6112 138.2446
105.5152 172.1816
2-54
SURFPoints
113.6975 48.7220
104.4210 75.7348
111.3914 154.4597
106.2879 175.2709
131.1298 98.3900
124.2933 64.4942
Read in image.
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
2-55
SURFPoints
[2] Matas, J., O. Chum, M. Urba, and T. Pajdla. "Robust wide baseline
stereo from maximally stable extremal regions." Proc. of British
Machine Vision Conference, pages 384-396, 2002.
2-56
SURFPoints
2-57
SURFPoints.isempty
Syntax isempty(SURFPointsObj)
2-58
SURFPoints.length
Syntax length(SURFPointsObj)
2-59
SURFPoints.plot
Syntax surfPoints.plot
surfPoints.plot(AXES_HANDLE,...)
surfPoints.plot(AXES_HANDLE,Name,Value)
Input AXES_HANDLE
Arguments Handle for plot method to use for display. You can set the handle
using gca.
showScale
Display proportional circle around feature. Set this value to true
or false. When you set this value to true, the object draws a
circle proportional to the scale of the detected feature, with the
feature point located at its center. When you set this value to
false, the object turns the display of the circle off.
The algorithm represents the scale of the feature with a circle of
6*Scale radius. The SURF algorithm uses this equivalent size of
circular area to compute the orientation of the feature.
2-60
SURFPoints.plot
Default: true
showOrientation
Display a line corresponding to feature point orientation. Set this
value to true or false. When you set this value to true, the
object draws a line corresponding to the point’s orientation. The
object draws the line from the feature point location to the edge of
the circle, indicating the scale.
Default: false
2-61
SURFPoints.selectStrongest
2-62
SURFPoints.size
Syntax size(SURFPointsObj)
2-63
vision.AlphaBlender
Description The AlphaBlender object combines two images, overlays one image over
another, or highlights selected pixels.
Use the step syntax below with input images, I1 and I2, the alpha
blender object, H, and any optional properties.
Y = step(H,I1,I2) performs the alpha blending operation on images
I1 and I2.
Y = step(H,I1,I2,OPACITY) uses OPACITY input to combine pixel
values of I1 and I2 when you set the Operation property to Blend and
the OpacitySource property to Input port.
Y = step(H,I1,I2,MASK) uses MASK input to overlay I2 over I1 when
you set the Operation property to Binary mask and the MaskSource
property to Input port’.
Y = step(H,I1,MASK) uses MASK input to determine which pixels in I1
are set to the maximum value supported by their data type when you
set the Operation property to Highlight selected pixels and the
MaskSource property to Input port.
Y = step(H,I1,I2,...,LOCATION) uses LOCATION input to specify
the upper-left corner position of I2 when you set the LocationSource
property to Input port.
2-64
vision.AlphaBlender
Properties Operation
Operation to perform
Specify the operation that the object performs as Blend, Binary
mask, or Highlight selected pixels. If you set this property to
Blend, the object linearly combines the pixels of one image with
another image. If you set this property to Binary mask, the object
overwrites the pixel values of one image with the pixel values of
another image. If you set this property to Highlight selected
pixel, the object uses the binary image input, MASK, to determine
which pixels are set to the maximum value supported by their
data type.
OpacitySource
Source of opacity factor
Specify how to determine any opacity factor as Property or Input
port. This property applies when you set the Operation property
to Blend. The default is Property.
Opacity
Amount by which the object scales each pixel value before
combining them
Specify the amount by which the object scales each pixel value
before combining them. Determine this value before combining
pixels as a scalar value used for all pixels, or a matrix of values
that defines the factor for each pixel. This property applies when
you set the OpacitySource property to Property. This property
is tunable. The default is 0.75.
2-65
vision.AlphaBlender
MaskSource
Source of binary mask
Specify how to determine any masking factors as Property or
Input port. This property applies when you set the Operation
property to Binary mask. The default is Property.
Mask
Which pixels are overwritten
Specify which pixels are overwritten as a binary scalar 0 or 1 used
for all pixels, or a matrix of 0s and 1s that defines the factor for
each pixel. This property applies when you set the MaskSource
property to Property. This property is tunable. The default is 1.
LocationSource
Source of location of the upper-left corner of second input image
Specify how to enter location of the upper-left corner of second
input image as Property or Input port. The default is Property.
Location
Location [x y] of upper-left corner of second input image relative
to first input image
Specify the row and column position of upper-left corner of the
second input image relative to upper-left corner of first input
image as a two-element vector. This property applies when you
set the LocationSource property to Property. The default is [1
1]. This property is tunable.
See “Coordinate Systems” for a discussion on pixel coordinates
and spatial coordinates, which are the two main coordinate
systems used in the Computer Vision System Toolbox.
Fixed-Point Properties
RoundingMethod
2-66
vision.AlphaBlender
2-67
vision.AlphaBlender
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as Same as
product, Same as first input, or Custom. The default is Same
as product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the AccumulatorDataType property to Custom. The default is
numerictype([],32,10).
OutputDataType
Output word and fraction lengths
Specify the output fixed-point data type as Same as first input
or Custom. The default is Same as first input.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the OutputDataType property to Custom. The default is
numerictype([],32,10).
2-68
vision.AlphaBlender
I1 = im2single(imread('blobs.png'));
I2 = im2single(imread('circles.png'));
subplot(1,2,1);
imshow(I1);
subplot(1,2,2);
imshow(I2);
2-69
vision.AlphaBlender
halphablend = vision.AlphaBlender;
J = step(halphablend,I1,I2);
figure;
imshow(J);
2-70
vision.AlphaBlender
Algorithms This object implements the algorithm, inputs, and outputs described on
the Compositing block reference page. The object properties correspond
to the block parameters.
2-71
vision.AlphaBlender.clone
Syntax C = clone(H)
2-72
vision.AlphaBlender.getNumInputs
Syntax N = getNumInputs(H)
2-73
vision.AlphaBlender.getNumOutputs
Syntax N = getNumOutputs(H)
2-74
vision.AlphaBlender.isLocked
Syntax TF = isLocked(H)
2-75
vision.AlphaBlender.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-76
vision.AlphaBlender.step
Syntax Y = step(H,I1,I2)
Y = step(H,I1,I2,OPACITY)
Y = step(H,I1,I2,MASK)
Y = step(H,I1,MASK)
Y = step(H,I1,I2,...,LOCATION)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-77
vision.Autocorrelator
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as Same as
product, Same as input, or Custom. The default is Same as
product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the AccumulatorDataType property to Custom. The default is
numerictype([],32,30).
CustomOutputDataType
2-78
vision.Autocorrelator
2-79
vision.Autocorrelator
hac2d = vision.Autocorrelator;
x = [1 2;2 1];
Y = step(hac2d, x)
Y =
1 4 4
4 10 4
4 4 1
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2-D Autocorrelation block reference page. The object properties
correspond to the block parameters.
2-80
vision.Autocorrelator.clone
Syntax C = clone(H)
2-81
vision.Autocorrelator.getNumInputs
Syntax N = getNumInputs(H)
2-82
vision.Autocorrelator.getNumOutputs
Syntax N = getNumOutputs(H)
2-83
vision.Autocorrelator.isLocked
Syntax TF = isLocked(H)
2-84
vision.Autocorrelator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-85
vision.Autocorrelator.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-86
vision.Autothresholder
Properties Operator
Threshold operator on input matrix values
Specify the condition the object places on the input matrix values
as one of > | <= . The default is >.
If you set this property to >, and the step method inputs a value
greater than the threshold value, the object outputs 1. If the step
method inputs a value less than the threshold value, the object
outputs 0.
If you set this property to <=, and the step method inputs a value
less than or equal to the threshold value, the object outputs 1. If
the step method inputs a value greater than the threshold value,
the object outputs 0.
ThresholdOutputPort
2-87
vision.Autothresholder
2-88
vision.Autothresholder
Specify the object’s behavior when the input values are outside
the expected data range as one of Ignore | Saturate. The
default is Saturate. This property applies when you set the
InputRangeSource property to Property.
ThresholdScaleFactor
Threshold scale factor
Specify the threshold scale factor as a numeric scalar greater than
0. The default is 1. The object multiplies this scalar value with the
threshold value computed by Otsu’s method. The result becomes
the new threshold value. The object does not do threshold scaling.
This property is tunable.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent |
Floor | Nearest | Round | Simplest | Zero. The default isFloor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. The default
isWrap.
Product1DataType
Product-1 word and fraction lengths
This is a constant property with value Custom.
CustomProduct1DataType
Product-1 word and fraction lengths
Specify the product-1 fixed-point type as a signed
numerictype object with a Signedness of Auto. The default
isnumerictype([],32).
2-89
vision.Autothresholder
Accumulator1DataType
Accumulator-1 word and fraction lengths
Specify the accumulator-1 fixed-point data type as Same as
product 1, Custom. The default isSame as product 1.
CustomAccumulator1DataType
Accumulator-1 word and fraction lengths
Specify the accumulator-1 fixed-point type as a signed
numerictype object with a Signedness of Auto. This property
applies when you set the Accumulator1DataType property to
Custom. The default isnumerictype([],32).
Product2DataType
Product-2 word and fraction lengths
This is a constant property with value Custom.
CustomProduct2DataType
Product-2 word and fraction lengths
Specify the product-2 fixed-point type as a signed
numerictype object with a Signedness of Auto. The default
isnumerictype([],32).
Accumulator2DataType
Accumulator-2 word and fraction lengths
Specify the accumulator-2 fixed-point data type as Same as
product 2, Custom. The default is Same as product 2.
CustomAccumulator2DataType
Accumulator-2 word and fraction lengths
Specify the accumulator-2 fixed-point type as a signed
numerictype object with a Signedness of Auto. This property
applies when you set the Accumulator2DataType property to
Custom. The default isnumerictype([],32).
2-90
vision.Autothresholder
Product3DataType
Product-3 word and fraction lengths
This is a constant property with value Custom.
CustomProduct3DataType
Product-3 word and fraction lengths
Specify the product-3 fixed-point type as a signed
numerictype object with a Signedness of Auto. The default
isnumerictype([],32).
Accumulator3DataType
Accumulator-3 word and fraction lengths
Specify the accumulator-3 fixed-point data type as Same as
product 3, Custom. This property applies when you set the
EffectivenessOutputPort property to true. The default isSame
as product 3.
CustomAccumulator3DataType
Accumulator-3 word and fraction lengths
Specify the accumulator-3 fixed-point type as a signed
numerictype object with a Signedness of Auto. This property
applies when you set the EffectivenessOutputPort property to
true, and when you set the Accumulator3DataType property to
Custom. The default isnumerictype([],32).
Product4DataType
Product-4 word and fraction lengths
Specify the product-4 fixed-point data type as Same as input , or
Custom. The default isCustom.
CustomProduct4DataType
Product-4 word and fraction lengths
2-91
vision.Autothresholder
2-92
vision.Autothresholder
img = im2single(rgb2gray(imread('peppers.png')));
imshow(img);
hautoth = vision.Autothresholder;
bin = step(hautoth,img);
pause(2);
figure;imshow(bin);
2-93
vision.Autothresholder
2-94
vision.Autothresholder
Algorithms This object implements the algorithm, inputs, and outputs described
on the Autothreshold block reference page. The object properties
correspond to the block parameters, except:
2-95
vision.Autothresholder.clone
Syntax C = clone(H)
2-96
vision.Autothresholder.getNumInputs
Syntax N = getNumInputs(H)
2-97
vision.Autothresholder.getNumOutputs
Syntax N = getNumOutputs(H)
2-98
vision.Autothresholder.isLocked
Syntax TF = isLocked(H)
2-99
vision.Autothresholder.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-100
vision.Autothresholder.step
Syntax BW = step(H,I)
[BW,TH] = step(H,I)
[...,EMETRIC] = step(H,I)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-101
vision.BinaryFileReader
Description The BinaryFileReader object reads video data from binary files.
Properties Filename
Name of binary file to read from
Specify the name of the binary file as a string. The full path for
the file needs to be specified only if the file is not on the MATLAB
path. The default is vipmen.bin.
VideoFormat
Format of binary video data
Specify the format of the binary video data as Four character
codes, or Custom. The default is Four character codes.
FourCharacterCode
Four Character Code video format
Specify the binary file format from the available list of Four
Character Code video formats. For more information on Four
Character Codes, see http://www.fourcc.org. This property applies
when you set the VideoFormat property to Four character
codes.
2-102
vision.BinaryFileReader
BitstreamFormat
Format of data as planar or packed
Specify the data format as Planar or Packed. This property
applies when you set the VideoFormat property to Custom. The
default is Planar.
OutputSize
Size of output matrix
Specify the size of the output matrix. This property applies when
you set the BitstreamFormat property to Packed.
VideoComponentCount
Number of video components in video stream
Specify the number of video components in the video stream as
1, 2, 3 or 4. This number corresponds to the number of video
component outputs. This property applies when you set the
VideoFormat property to Custom. The default is 3.
VideoComponentBits
Bit size of video components
Specify the bit sizes of video components as an integer
valued vector of length N, where N is the value of the
VideoComponentCount property. This property applies when you
set the VideoFormat property to Custom. The default is [8 8 8].
VideoComponentSizes
Size of output matrix
Specify the size of the output matrix. This property must
be set to an N-by-2 array, where N is the value of the
VideoComponentCount property. Each row of the matrix
corresponds to the size of that video component, with the first
element denoting the number of rows and the second element
denoting the number of columns. This property applies when you
2-103
vision.BinaryFileReader
2-104
vision.BinaryFileReader
ByteOrder
Byte ordering as little endian or big endian
Specify the byte ordering in the output binary file as Little
endian, Big endian. This property applies when you set the
VideoFormat property to Custom. The default is Little endian.
PlayCount
Number of times to play the file
Specify the number of times to play the file as a positive integer
or inf. The default is 1.
Examples Read in a binary video file and play it back on the screen
hbfr = vision.BinaryFileReader('ecolicells.bin');
hbfr.VideoFormat = 'Custom';
hbfr.VideoComponentCount = 1;
2-105
vision.BinaryFileReader
hbfr.VideoComponentBits = 16;
hbfr.VideoComponentSizes = [442 538];
hbfr.VideoComponentOrder = 1;
hvp = vision.VideoPlayer;
while ~isDone(hbfr)
y = step(hbfr);
step(hvp,y);
end
Algorithms This object implements the algorithm, inputs, and outputs described
on the Read Binary File block reference page. The object properties
correspond to the block parameters.
2-106
vision.BinaryFileReader.clone
Purpose Create binary file reader object with same property values
Syntax C = clone(H)
2-107
vision.BinaryFileReader.getNumInputs
Syntax N = getNumInputs(H)
2-108
vision.BinaryFileReader.getNumOutputs
Syntax N = getNumOutputs(H)
2-109
vision.BinaryFileReader.isDone
Syntax TF = isDone(H)
2-110
vision.BinaryFileReader.isLocked
Syntax TF = isLocked(H)
2-111
vision.BinaryFileReader.reset
Syntax reset(H)
2-112
vision.BinaryFileReader.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-113
vision.BinaryFileReader.step
2-114
vision.BinaryFileReader.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-115
vision.BinaryFileWriter
Properties Filename
Name of binary file to write to
Specify the name of the binary file as a string. The default is the
file output.bin.
VideoFormat
Format of binary video data
Specify the format of the binary video data as Four character
codes, or Custom. The default is Four character codes.
FourCharacterCode
Four Character Code video format
Specify the binary file format from the available list of Four
Character Code video formats. For more information on Four
Character Codes, see http://www.fourcc.org. This property applies
when you set the VideoFormat property to Four character
codes.
BitstreamFormat
2-116
vision.BinaryFileWriter
2-117
vision.BinaryFileWriter
2-118
vision.BinaryFileWriter
filename = fullfile(tempdir,'output.bin');
hbfr = vision.BinaryFileReader;
hbfw = vision.BinaryFileWriter(filename);
while ~isDone(hbfr)
[y,cb,cr] = step(hbfr);
step(hbfw,y,cb,cr);
end
Algorithms This object implements the algorithm, inputs, and outputs described
on the Write Binary File block reference page. The object properties
correspond to the block parameters.
2-119
vision.BinaryFileWriter.clone
Purpose Create binary file writer object with same property values
Syntax C = clone(H)
2-120
vision.BinaryFileWriter.getNumInputs
Syntax N = getNumInputs(H)
2-121
vision.BinaryFileWriter.getNumOutputs
Syntax N = getNumOutputs(H)
2-122
vision.BinaryFileWriter.isLocked
Syntax TF = isLocked(H)
2-123
vision.BinaryFileWriter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-124
vision.BinaryFileWriter.step
Syntax step(H,Y,Cb,Cr)
step(H,Y)
step(H,Y,Cb)
step(H,Y,Cb,Cr)
step(H,Y,Cb,Cr,Alpha)
Description step(H,Y,Cb,Cr) writes one frame of video to the specified output file.
Y , Cb, Cr represent the luma (Y) and chroma (Cb and Cr) components
of a video stream. This option applies when you set the VideoFormat
property to Four character codes.
step(H,Y) writes video component Y to the output file when the
VideoFormat property is set to Custom and the VideoComponentCount
property is set to 1.
step(H,Y,Cb) writes video components Y and Cb to the output file when
the VideoFormat property is Custom and the VideoComponentCount
property is set to 2.
step(H,Y,Cb,Cr) writes video components Y , Cb and Cr to the
output file when the VideoFormat property is set to Custom and the
VideoComponentCount property is set to3.
step(H,Y,Cb,Cr,Alpha) writes video components Y , Cb, Cr and Alpha
to the output file when the VideoFormat property is set to Custom, and
the VideoComponentCount property is set to 4.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-125
vision.BlobAnalysis
2-126
vision.BlobAnalysis
2-127
vision.BlobAnalysis
2-128
vision.BlobAnalysis
Properties AreaOutputPort
Return blob area
Setting this property to true outputs the area of the blobs. The
default is true.
CentroidOutputPort
Return coordinates of blob centroids
Set this property to true to output the coordinates of the centroid
of the blobs. The default is true.
BoundingBoxOutputPort
Return coordinates of bounding boxes
2-129
vision.BlobAnalysis
2-130
vision.BlobAnalysis
2-131
vision.BlobAnalysis
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
2-132
vision.BlobAnalysis
2-133
vision.BlobAnalysis
2-134
vision.BlobAnalysis
2-135
vision.BlobAnalysis
hblob = vision.BlobAnalysis;
hblob.AreaOutputPort = false;
hblob.BoundingBoxOutputPort = false;
img = logical([0 0 0 0 0 0; ...
0 1 1 1 1 0; ...
0 1 1 1 1 0; ...
0 1 1 1 1 0; ...
0 0 0 0 0 0]);
centroid = step(hblob, img); % [x y] coordinates of the centroid
Algorithms This object implements the algorithm, inputs, and outputs described
on the Blob Analysis block reference page. The object properties
correspond to the block parameters, except:
2-136
vision.BlobAnalysis
2-137
vision.BlobAnalysis.clone
Syntax C = clone(H)
2-138
vision.BlobAnalysis.getNumInputs
Syntax N = getNumInputs(H)
2-139
vision.BlobAnalysis.getNumOutputs
Syntax N = getNumOutputs(H)
2-140
vision.BlobAnalysis.isLocked
Syntax TF = isLocked(H)
2-141
vision.BlobAnalysis.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-142
vision.BlobAnalysis.step
Description AREA = step(H,BW) computes the AREA of the blobs found in input
binary image BW when the AreaOutputPort property is set to true.
[...,CENTROID] = step(H,BW) computes the CENTROID of the blobs
found in input binary image BW when the CentroidOutputPort property
is set to true.
[...,BBOX] = step(H,BW) computes the bounding box BBOX of the
blobs found in input binary image BW when the BoundingBoxOutputPort
property is set to true.
[...,MAJORAXIS] = step(H,BW) computes the major axis length
MAJORAXIS of the blobs found in input binary image BW when the
MajorAxisLengthOutputPort property is set to true.
[...,MINORAXIS] = step(H,BW) computes the minor axis length
MINORAXIS of the blobs found in input binary image BW when the
MinorAxisLengthOutputPort property is set to true.
[...,ORIENTATION] = step(H,BW) computes the ORIENTATION of the
blobs found in input binary image BW when the OrientationOutputPort
property is set to true.
2-143
vision.BlobAnalysis.step
2-144
vision.BlobAnalysis.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-145
vision.BlockMatcher
Properties ReferenceFrameSource
Reference frame source
Specify the source of the reference frame as one of Input port |
Property. When you set the ReferenceFrameSource property to
Input port a reference frame input must be specified to the step
method of the block matcher object. The default is Property.
ReferenceFrameDelay
Number of frames between reference and current frames
Specify the number of frames between the reference frame
and the current frame as a scalar integer value greater than
or equal to zero. This property applies when you set the
ReferenceFrameSource property to Property.
The default is 1.
SearchMethod
Best match search method
Specify how to locate the block of pixels in frame k+1 that best
matches the block of pixels in frame k. You can specify the search
2-146
vision.BlockMatcher
2-147
vision.BlockMatcher
Fixed-Point Properties
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as input
| Custom. The default is Custom. This property applies when you
set the MatchCriteria property to Mean square error (MSE).
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the MatchCriteria property to Mean square error (MSE)
and the ProductDataType property to Custom.
The default is numerictype([],32,0).
AccumulatorDataType
2-148
vision.BlockMatcher
2-149
vision.BlockMatcher
img1 = im2double(rgb2gray(imread('onion.png')));
Create objects
2-150
vision.BlockMatcher
Algorithms This object implements the algorithm, inputs, and outputs described
on the Block Matching block reference page. The object properties
correspond to the block parameters.
2-151
vision.BlockMatcher.clone
Syntax C = clone(H)
2-152
vision.BlockMatcher.getNumInputs
Syntax N = getNumInputs(H)
2-153
vision.BlockMatcher.getNumOutputs
Syntax N = getNumOutputs(H)
2-154
vision.BlockMatcher.isLocked
Syntax TF = isLocked(H)
2-155
vision.BlockMatcher.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-156
vision.BlockMatcher.step
Syntax V = step(H,I)
C = step(H,I)
Y = step(H,I,IREF)
Description V = step(H,I) computes the motion of input image I from one video
frame to another, and returns V as a matrix of velocity magnitudes.
C = step(H,I) computes the motion of input image I from one video
frame to another, and returns C as a complex matrix of horizontal
and vertical components, when you set the OutputValue property to
Horizontal and vertical components in complex form.
Y = step(H,I,IREF) computes the motion between input image I
and reference image IREF when you set the ReferenceFrameSource
property to Input port.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-157
vision.BoundaryTracer
Description The boundary tracer object traces object boundaries in binary images.
Use the step syntax below with input image BW, starting point STARTPT,
boundary tracer object, H, and any optional properties.
PTS = step(H,BW,STARTPT) traces the boundary of an object in a
binary image, BW. The input matrix, STARTPT, specifies the starting
point for tracing the boundary. STARTPT is a two-element vector of [x y]
coordinates of the initial point on the object boundary. The step method
outputs PTS, an M-by-2 matrix of [x y] coordinates of the boundary
points. In this matrix, M is the number of traced boundary pixels. M
is less than or equal to the value specified by the MaximumPixelCount
property.
Properties Connectivity
How to connect pixels to each other
Specify which pixels are connected to each other as one of 4 | 8.
The default is 8. Set this property to 4 to connect a pixel to the
pixels on the top, bottom, left, and right. Set this property to 8 to
2-158
vision.BoundaryTracer
connect a pixel to the pixels on the top, bottom, left, right, and
diagonally.
InitialSearchDirection
First search direction to find next boundary pixel
Specify the first direction in which to look to find the next
boundary pixel that is connected to the starting pixel.
When you set the Connectivity property to 8, this property
accepts a value of North, Northeast, East, Southeast, South,
Southwest, West, or Northwest.
When you set the Connectivity property to 4, this property
accepts a value of North, East, South, or West
TraceDirection
Direction in which to trace the boundary
Specify the direction in which to trace the boundary as one of
Clockwise | Counterclockwise. The default is Clockwise.
MaximumPixelCount
Maximum number of boundary pixels
Specify the maximum number of boundary pixels as a scalar
integer greater than 1. The object uses this value to preallocate
the number of rows of the output matrix, Y. This preallocation
enables the matrix to hold all the boundary pixel location values.
The default is 500.
NoBoundaryAction
How to fill empty spaces in output matrix
Specify how to fill the empty spaces in the output matrix, Y
as one of None | Fill with last point found | Fill with
user-defined values. The default is None. If you set this
property to None, the object takes no action. Thus, any element
that does not contain a boundary pixel location has no meaningful
2-159
vision.BoundaryTracer
value. If you set this property to Fill with last point found,
the object fills the remaining elements with the position of
the last boundary pixel. If you set this property to Fill with
user-defined values, you must specify the values in the
FillValues property.
FillValues
Value to fill in remaining empty elements in output matrix
Set this property to a scalar value or two-element vector to fill
in the remaining empty elements in the output matrix Y. This
property applies when you set the NoBoundaryAction property to
Fill with user-defined values.
The default is [0 0].
2-160
vision.BoundaryTracer
Algorithms This object implements the algorithm, inputs, and outputs described
on the Trace Boundary block reference page. The object properties
correspond to the block parameters.
2-161
vision.BoundaryTracer.clone
Syntax C = clone(H)
2-162
vision.BoundaryTracer.getNumInputs
Syntax N = getNumInputs(H)
2-163
vision.BoundaryTracer.getNumOutputs
Syntax N = getNumOutputs(H)
2-164
vision.BoundaryTracer.isLocked
Syntax TF = isLocked(H)
2-165
vision.BoundaryTracer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-166
vision.BoundaryTracer.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-167
vision.CascadeObjectDetector
Description The cascade object detector uses the Viola-Jones algorithm to detect
people’s faces, noses, eyes, mouth, or upper body. You can also use the
trainCascadeObjectDetector function to train a custom classifier to
use with this System object. For details on how the function works, see
“Train a Cascade Object Detector”.
2-168
vision.CascadeObjectDetector
To detect a feature:
1 Define and set up your cascade object detector using the constructor.
2 Call the step method with the input image, I, the cascade object
detector object, detector, points PTS, and any optional properties.
See the syntax below for using the step method.
Use the step syntax with input image, I, the selected Cascade object
detector object, and any optional properties to perform detection.
BBOX = step(detector,I) returns BBOX, an M-by-4 matrix defining M
bounding boxes containing the detected objects. This method performs
multiscale object detection on the input image, I. Each row of the output
matrix, BBOX, contains a four-element vector, [x y width height], that
specifies in pixels, the upper-left corner and size of a bounding box. The
input image I, must be a grayscale or truecolor (RGB) image.
Properties ClassificationModel
Trained cascade classification model
Specify the name of the model as a string. This value sets the
classification model for the detector. You may set this string to
an XML file containing a custom classification model, or to one
of the valid model strings listed below. You can train a custom
classification model using the trainCascadeObjectDetector
function. The function can train the model using Haar-like
features, histograms of oriented gradients (HOG), or local binary
patterns (LBP). For details on how to use the function, see “Train
a Cascade Object Detector”.
2-169
vision.CascadeObjectDetector
Image
ClassificationModel Model Description
String Size
Used
to Train
FrontalFaceCART Model
[20 20] Detects faces that are upright
(Default) and forward facing. This model
is composed of weak classifiers,
based on the classification
and regression tree analysis
(CART). These classifiers use
Haar features to encode facial
features. CART-based classifiers
provide the ability to model
higher-order dependencies
between facial features. [1]
Image
ClassificationModel Model Description
String Size
Used
to Train
FrontalFaceLBP Model
[24 24] Detects faces that are upright
and forward facing. This model
is composed of weak classifiers,
based on a decision stump.
These classifiers use local binary
patterns (LBP) to encode facial
features. LBP features can
provide robustness against
variation in illumination.[2]
2-170
vision.CascadeObjectDetector
Upper Body
Image
ClassificationModel Model Description
String Size
Used
to Train
UpperBody Model
[18 22] Detects the upper-body region,
which is defined as the head
and shoulders area. This model
uses Haar features to encode
the details of the head and
shoulder region. Because it
uses more features around the
head, this model is more robust
against pose changes, e.g. head
rotations/tilts. [3]
Eye Pair
Image
ClassificationModel Model Description
String Size
Used
to Train
EyePairBig Model
[11 45] Detects a pair of eyes. The
EyePairSmall [5 22] EyePairSmall model is
trained using a smaller image.
This enables the model to
detect smaller eyes than the
EyePairBig model can detect.[4]
2-171
vision.CascadeObjectDetector
Single Eye
Image
ClassificationModel Model Description
String Size
Used
to Train
LeftEye Model
[12 18] Detects the left and right eye
RightEye separately. These models are
composed of weak classifiers,
based on a decision stump These
classifiers use Haar features to
encode details.[4]
Image
ClassificationModel Model Description
String Size
Used
to Train
LeftEyeCART Model
[20 20] Detects the left and right
RightEyeCART eye separately. The weak
classifiers that make up
these models are CART-trees.
Compared to decision stumps,
CART-tree-based classifiers are
better able to model higher-order
dependencies. [5]
2-172
vision.CascadeObjectDetector
Profile Face
Image
ClassificationModel Model Description
String Size
Used
to Train
ProfileFace Model
[20 20] Detects upright face profiles.
This model is composed of weak
classifiers, based on a decision
stump. These classifiers use
Haar features to encode face
Mouth details.
Image
ClassificationModel Model Description
String Size
Used
to Train
Mouth Model
[15 25] Detects the mouth. This model
is composed of weak classifiers,
based on a decision stump, which
use Haar features to encode
mouth details.[4]
Nose
Image
ClassificationModel Model Description
String Size
Used
to Train
Nose Model
[15 18] This model is composed of weak
classifiers, based on a decision
stump, which use Haar features
to encode nose details.[4]
Default: FrontalFaceCART
MinSize
2-173
vision.CascadeObjectDetector
size(I)/(size(I)-0.5)
2-174
vision.CascadeObjectDetector
2-175
vision.CascadeObjectDetector
faceDetector = vision.CascadeObjectDetector;
I = imread('visionteam.jpg');
Detect faces.
2-176
vision.CascadeObjectDetector
bodyDetector = vision.CascadeObjectDetector('UpperBody');
bodyDetector.MinSize = [60 60];
bodyDetector.MergeThreshold = 10;
I2 = imread('visionteam.jpg');
bboxBody = step(bodyDetector, I2);
2-177
vision.CascadeObjectDetector
2-178
vision.CascadeObjectDetector
Cascade of Classifiers
This object uses a cascade of classifiers to efficiently process image
regions for the presence of a target object. Each stage in the cascade
applies increasingly more complex binary classifiers, which allows
the algorithm to rapidly reject regions that do not contain the target.
If the desired object is not found at any stage in the cascade, the
detector immediately rejects the region and processing is terminated.
By terminating, the object avoids invoking computation-intensive
classifiers further down the cascade.
2-179
vision.CascadeObjectDetector
The search window traverses the image for each scaled increment.
The actual range of returned object sizes may not be exactly what
you select for the MinSize and MaxSize properties. For example, a
ScaleFactor value of 1.1 with a 24x24 training size, and an N value
from 1 to 5, the search region calculation would be:
2-180
vision.CascadeObjectDetector
>> 26 29 32 35 39
If you were to set MaxSize to 34, due to the search region quantization,
the actual maximum object size used by the algorithm would be 32.
2-181
vision.CascadeObjectDetector
2-182
vision.CascadeObjectDetector
References [1] Lienhart R., Kuranov A., and V. Pisarevsky “Empirical Analysis of
Detection Cascades of Boosted Classifiers for Rapid Object Detection.”,
Proceedings of the 25th DAGM Symposium on Pattern Recognition.
Magdeburg, Germany, 2003.
[6] Viola, Paul and Michael J. Jones, “Rapid Object Detection using
a Boosted Cascade of Simple Features”, Proceedings of the 2001
IEEE Computer Society Conference on Computer Vision and Pattern
Recognition, 2001. Volume: 1, pp.511–518.
2-183
vision.CascadeObjectDetector
2-184
vision.CascadeObjectDetector.clone
Purpose Create cascade object detector object with same property values
Syntax C = clone(H)
2-185
vision.CascadeObjectDetector.getNumInputs
Syntax N = getNumInputs(H)
2-186
vision.CascadeObjectDetector.getNumOutputs
Syntax N = getNumOutputs(H)
2-187
vision.CascadeObjectDetector.isLocked
Syntax TF = isLocked(H)
2-188
vision.CascadeObjectDetector.release
Syntax release(H)
2-189
vision.CascadeObjectDetector.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-190
vision.ChromaResampler
Properties Resampling
Resampling format
To downsample the chrominance components of images, set this
property to one of the following:
[4:4:4 to 4:2:2]
[4:4:4 to 4:2:0 (MPEG1)]
[4:4:4 to 4:2:0 (MPEG2)]
[4:4:4 to 4:1:1]
[4:2:2 to 4:2:0 (MPEG1)]
[4:2:2 to 4:2:0 (MPEG2)]
2-191
vision.ChromaResampler
[4:2:2 to 4:4:4]
[4:2:0 (MPEG1) to 4:4:4]
[4:2:0 (MPEG2) to 4:4:4]
[4:1:1 to 4:4:4]
[4:2:0 (MPEG1) to 4:2:2]
[4:2:0 (MPEG2) to 4:2:2]
2-192
vision.ChromaResampler
2-193
vision.ChromaResampler
H = vision.ChromaResampler;
hcsc = vision.ColorSpaceConverter;
x = imread('peppers.png');
x1 = step(hcsc, x);
[Cb, Cr] = step(H, x1(:,:,2), x1(:,:,3));
Algorithms This object implements the algorithm, inputs, and outputs described
on the Chroma Resampling block reference page. The object properties
correspond to the block parameters.
2-194
vision.ChromaResampler.clone
Syntax C = clone(H)
2-195
vision.ChromaResampler.getNumInputs
Syntax N = getNumInputs(H)
2-196
vision.ChromaResampler.getNumOutputs
Syntax N = getNumOutputs(H)
2-197
vision.ChromaResampler.isLocked
Syntax TF = isLocked(H)
2-198
vision.ChromaResampler.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-199
vision.ChromaResampler.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-200
vision.ColorSpaceConverter
Properties Conversion
Color space input and output conversion
Specify the conversion color spaces as one of the following:
[RGB to YCbCr]
[YCbCr to RGB]
[RGB to intensity]
[RGB to HSV]
[HSV to RGB]
[sRGB to XYZ]
[XYZ to sRGB]
[sRGB to L*a*b*]
[L*a*b* to sRGB]
2-201
vision.ColorSpaceConverter
2-202
vision.ColorSpaceConverter
i1 = imread('pears.png');
imshow(i1);
hcsc = vision.ColorSpaceConverter;
hcsc.Conversion = 'RGB to intensity';
i2 = step(hcsc, i1);
pause(2);
imshow(i2);
Algorithms This object implements the algorithm, inputs, and outputs described on
the Color Space Conversion block reference page. The object properties
correspond to the block parameters, except:
2-203
vision.ColorSpaceConverter.clone
Purpose Create color space converter object with same property values
Syntax C = clone(H)
2-204
vision.ColorSpaceConverter.getNumInputs
Syntax N = getNumInputs(H)
2-205
vision.ColorSpaceConverter.getNumOutputs
Syntax N = getNumOutputs(H)
2-206
vision.ColorSpaceConverter.isLocked
Syntax TF = isLocked(H)
2-207
vision.ColorSpaceConverter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-208
vision.ColorSpaceConverter.step
Syntax C2 = step(H,C1)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-209
vision.ConnectedComponentLabeler
Properties Connectivity
Which pixels are connected to each other
Specify which pixels are connected to each other as either 4 or 8.
If a pixel should be connected to the pixels on the top, bottom, left,
and right, set this property to 4. If a pixel should be connected to
the pixels on the top, bottom, left, right, and diagonally, set this
property to 8. The default is 8.
LabelMatrixOutputPort
Enable output of label matrix
2-210
vision.ConnectedComponentLabeler
2-211
vision.ConnectedComponentLabeler
img =
0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 0 0 0 0 1
2-212
vision.ConnectedComponentLabeler
0 1 1 1 1 1 0 0 0 0 1
0 1 1 1 1 1 0 0 0 1 1
0 1 1 1 1 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0
labeled =
0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 0 0 0 0 2 0
0 1 1 1 1 1 0 0 0 0 2 2 0
0 1 1 1 1 1 0 0 0 2 2 2 0
0 1 1 1 1 0 0 0 2 2 2 2 0
0 0 0 0 0 0 0 2 2 2 2 2 0
0 0 0 0 0 0 0 0 0 0 0 0 0
Algorithms This object implements the algorithm, inputs, and outputs described
on the Label block reference page. The object properties correspond
to the block parameters, except:
2-213
vision.ConnectedComponentLabeler.clone
Purpose Create connected component labeler object with same property values
Syntax C = clone(H)
2-214
vision.ConnectedComponentLabeler.getNumInputs
Syntax N = getNumInputs(H)
2-215
vision.ConnectedComponentLabeler.getNumOutputs
Syntax N = getNumOutputs(H)
2-216
vision.ConnectedComponentLabeler.isLocked
Syntax TF = isLocked(H)
2-217
vision.ConnectedComponentLabeler.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-218
vision.ConnectedComponentLabeler.step
Syntax L = step(H,BW)
COUNT = step(H,BW)
[L,COUNT] = step(H,BW)
Description L = step(H,BW) outputs the matrix, L for input binary image BW when
the LabelMatrixOutputPort property is true.
COUNT = step(H,BW) outputs the number of distinct,
connected regions found in input binary image BW when you set the
LabelMatrixOutputPort property to false and LabelCountOutputPort
property to true.
[L,COUNT] = step(H,BW) outputs both the L matrix and number
of distinct, connected regions, COUNT when you set both the
LabelMatrixOutputPort property and LabelCountOutputPort to true.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-219
vision.ContrastAdjuster
Properties InputRange
How to specify lower and upper input limits
Specify how to determine the lower and upper input limits as
one of Full input data range [min max] | Custom | Range
determined by saturating outlier pixels. The default is
Full input data range [min max].
CustomInputRange
Lower and upper input limits
Specify the lower and upper input limits as a two-element vector
of real numbers. The first element corresponds to the lower input
limit, and the second element corresponds to the upper input
2-220
vision.ContrastAdjuster
limit. This property applies only when you set the InputRange
property to Custom. This property is tunable.
PixelSaturationPercentage
Percentage of pixels to consider outliers
Specify the percentage of pixels to consider outliers, as a
two-element vector. This property only applies when you set
the InputRange property to Range determined by saturating
outlier pixels.
The contrast adjustment object calculates the lower input limit.
This calculation ensures that the maximum percentage of pixels
with values smaller than the lower limit can only equal the value
of the first element.
Similarly, the object calculates the upper input limit. This
calculation ensures that the maximum percentage of pixels with
values greater than the upper limit is can only equal the value of
the second element.
The default is [1 1].
HistogramNumBins
Number of histogram bins
Specify the number of histogram bins used to calculate the scaled
input values.
The default is 256.
OutputRangeSource
How to specify lower and upper output limits
Specify how to determine the lower and upper output limits as
one of Auto | Property. The default is Auto. If you set the value
of this property to Auto, the object uses the minimum value of the
input data type as the lower output limit. The maximum value of
the input data type indicates the upper output limit.
OutputRange
2-221
vision.ContrastAdjuster
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Wrap
ProductInputDataType
Product input word and fraction lengths
Specify the product input fixed-point data type as Custom.
CustomProductInputDataType
Product input word and fraction lengths
Specify the product input fixed-point type as a scaled numerictype
object with a Signedness of Auto.
The default is numerictype([],32,16).
ProductHistogramDataType
Product histogram word and fraction lengths
2-222
vision.ContrastAdjuster
hcontadj = vision.ContrastAdjuster;
x = imread('pout.tif');
y = step(hcontadj, x);
2-223
vision.ContrastAdjuster
Algorithms This object implements the algorithm, inputs, and outputs described on
the Contrast Adjustment block reference page. The object properties
correspond to the block parameters.
2-224
vision.ContrastAdjuster.clone
Syntax C = clone(H)
2-225
vision.ContrastAdjuster.getNumInputs
Syntax N = getNumInputs(H)
2-226
vision.ContrastAdjuster.getNumOutputs
Syntax N = getNumOutputs(H)
2-227
vision.ContrastAdjuster.isLocked
Syntax TF = isLocked(H)
2-228
vision.ContrastAdjuster.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-229
vision.ContrastAdjuster.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-230
vision.Convolver
Description The Convolver object computes 2-D discrete convolution of two input
matrices.
Properties OutputSize
Specify dimensions of output
This property controls the size of the output scalar, vector, or
matrix produced as a result of the convolution between the two
inputs. You can set this property to one of Full | Same as first
input | Valid. The default is Full. When you set this property to
Full, the object outputs the full two-dimensional convolution with
dimension, (Ma+Mb-1, Na+Nb-1). When you set this property to
Same as first input, the object outputs the central part of the
convolution with the same dimensions as the first input. When
you set this property to Valid, the object outputs only those parts
of the convolution that are computed without the zero-padded
edges of any input. For this case, the object outputs dimension,
(Ma-Mb+1, Na-Nb+1). (Ma, Na) is the size of the first input
matrix and (Mb, Na) is the size of the second input matrix.
Normalize
2-231
vision.Convolver
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Wrap.
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as first
input | Custom. The default is Custom.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ProductDataType property to Custom. The default is
numerictype([],32,10).
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as one of Same as
product | Same as first input | Custom. The default is Same
as product.
2-232
vision.Convolver
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the AccumulatorDataType property to Custom. The default is
numerictype([],32,10).
OutputDataType
Output word and fraction lengths
Specify the output fixed-point data type as one of Same as first
input | Custom. The default is Custom.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the OutputDataType property to Custom. The default is
numerictype([],32,12).
2-233
vision.Convolver
hconv2d = vision.Convolver;
x1 = [1 2;2 1];
x2 = [1 -1;-1 1];
y = step(hconv2d, x1, x2)
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2-D Convolution block reference page. The object properties
correspond to the block parameters.
2-234
vision.Convolver.clone
Syntax C = clone(H)
2-235
vision.Convolver.getNumInputs
Syntax N = getNumInputs(H)
2-236
vision.Convolver.getNumOutputs
Syntax N = getNumOutputs(H)
2-237
vision.Convolver.isLocked
Syntax TF = isLocked(H)
2-238
vision.Convolver.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-239
vision.Convolver.step
Syntax Y = step(HCONV2D,X1,X2)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-240
vision.CornerDetector
Description
Note Use this object for fixed-point support. Otherwise, it is
recommended to use one of the new detectHarrisFeatures,
detectMinEigenFeatures, or detectFASTFeatures functions in place
of vision.CornerDetector.
To detect corners:
2 Call the step method with the input image, I, the corner detector
object, cornerDetector, and any optional properties. See the syntax
below for using the step method.
2-241
vision.CornerDetector
Properties Method
Method to find corner values
Specify the method to find the corner values. Specify as one of
Harris corner detection (Harris & Stephens) | Minimum
eigenvalue (Shi & Tomasi) | Local intensity comparison
(Rosten & Drummond).
Default: Harris corner detection (Harris & Stephens)
Sensitivity
Harris corner sensitivity factor
Specify the sensitivity factor, k, used in the Harris corner
detection algorithm as a scalar numeric value such that 0 < k <
0.25. The smaller the value of k, the more likely the algorithm
will detect sharp corners. This property only applies when you set
the Method property to Harris corner detection (Harris &
Stephens). This property is tunable.
Default: 0.04
SmoothingFilterCoefficients
Smoothing filter coefficients
Specify the filter coefficients for the separable smoothing filter
as a real-valued numeric vector. The vector must have an
odd number of elements and a length of at least 3. For more
2-242
vision.CornerDetector
2-243
vision.CornerDetector
Set this property to true to output the metric matrix after corner
detection. This property and the CornerLocationOutputPort
property cannot both be set to false.
Default: false
MaximumCornerCount
Maximum number of corners to detect
Specify the maximum number of corners to detect as a positive
scalar integer value. This property only applies when you set the
CornerLocationOutputPort property to true.
Default: 200
CornerThreshold
Minimum metric value to indicate a corner
Specify a positive scalar number for the minimum metric value
that indicates a corner. This property applies only when you set
the CornerLocationOutputPort property to true. This property
is tunable.
Default: 0.0005
NeighborhoodSize
Size of suppressed region around detected corner
Specify the size of the neighborhood around the corner metric
value over which the object zeros out the values. The neighborhood
size is a two element vector of positive odd integers, [r c]. Here, r
indicates the number of rows in the neighborhood, and c indicates
the number of columns. This property only applies when you set
the CornerLocationOutputPort property to true.
Default: [11 11]
Fixed-Point Properties
RoundingMethod
2-244
vision.CornerDetector
2-245
vision.CornerDetector
2-246
vision.CornerDetector
Default: Custom
CustomMemoryDataType
Memory word and fraction lengths
Specify the memory fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies only you
do not set the Method property to Local intensity comparison
(Rosten & Drummond) and you set the MemoryDataType property
to Custom.
Default: numerictype([],32,0)
MetricOutputDataType
Metric output word and fraction lengths
Specify the metric output fixed-point data type as one of Same as
accumulator | Same as input | Custom.
Default: Same as accumulator
CustomMetricOutputDataType
Metric output word and fraction lengths
Specify the metric output fixed-point type as a signed, scaled
numerictype object with a Signedness of Auto. This property
applies when you set the MetricOutputDataType property to
Custom.
Default: numerictype([],32,0)
2-247
vision.CornerDetector
I = im2single(imread('circuit.tif'));
Find corners
Create the markers. The color data range must match the data range of
the input image. The color format for the marker is [red, green, blue].
color = [1 0 0];
drawMarkers = vision.MarkerInserter('Shape', 'Circle', 'BorderColor', 'Cu
J = repmat(I,[1 1 3]);
J = step(drawMarkers, J, pts);
imshow(J); title ('Corners detected in a grayscale image');
2-248
vision.CornerDetector
2-249
vision.CornerDetector.clone
Syntax C = clone(H)
2-250
vision.CornerDetector.getNumInputs
Syntax getNumInputs(H)
2-251
vision.CornerDetector.getNumOutputs
Syntax getNumOutputs(H)
2-252
vision.CornerDetector.isLocked
Syntax isLocked(H)
2-253
vision.CornerDetector.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-254
vision.CornerDetector.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-255
vision.Crosscorrelator
Properties OutputSize
Specify dimensions of output
This property controls the size of the output scalar, vector, or
matrix produced as a result of the cross-correlation between the
two inputs. This property can be set to one of Full, Same as
first input, Valid. If this property is set to Full, the output
is the full two-dimensional cross-correlation with dimensions
(Ma+Mb-1, Na+Nb-1). if this property is set to same as first
input, the output is the central part of the cross-correlation with
the same dimensions as the first input. if this property is set to
valid, the output is only those parts of the cross-correlation that
are computed without the zero-padded edges of any input. this
output has dimensions (Ma-Mb+1, Na-Nb+1). (Ma, Na) is the size
of the first input matrix and (Mb, Nb) is the size of the second
input matrix. The default is Full.
Normalize
2-256
vision.Crosscorrelator
Normalize output
Set this property to true to normalize the output. If you
set this property to true, the object divides the output by
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. The default is
Wrap.
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as Same as first
input, Custom. The default is Same as first input.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ProductDataType property to Custom. The default is
numerictype([],32,30).
AccumulatorDataType
2-257
vision.Crosscorrelator
2-258
vision.Crosscorrelator
hcorr2d = vision.Crosscorrelator;
x1 = [1 2;2 1];
x2 = [1 -1;-1 1];
y = step(hcorr2d,x1,x2);
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2-D Correlation block reference page. The object properties
correspond to the block parameters.
2-259
vision.Crosscorrelator.clone
Purpose Create 2-D cross correlator object with same property values
Syntax C = clone(H)
2-260
vision.Crosscorrelator.getNumInputs
Syntax N = getNumInputs(H)
2-261
vision.Crosscorrelator.getNumOutputs
Syntax N = getNumOutputs(H)
2-262
vision.Crosscorrelator.isLocked
Syntax TF = isLocked(H)
2-263
vision.Crosscorrelator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-264
vision.Crosscorrelator.step
Syntax Y = step(H,X1,X2)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-265
vision.DCT
Description The DCT object computes a 2-D discrete cosine transform. The number
of rows and columns of the input matrix must be a power of 2.
Properties SineComputation
Specify how the System object computes sines and cosines as
Trigonometric function, or Table lookup. This property must
be set to Table lookup for fixed-point inputs.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor. This property applies when you set the SineComputation
to Table lookup.
OverflowAction
2-266
vision.DCT
2-267
vision.DCT
2-268
vision.DCT
Examples Use 2-D discrete cosine transform to analyze the energy content in an
image. Set the DCT coefficients lower than a threshold of 0, and then
reconstruct the image using the 2-D inverse discrete cosine transform
object.
hdct2d = vision.DCT;
I = double(imread('cameraman.tif'));
J = step(hdct2d, I);
imshow(log(abs(J)),[]), colormap(jet(64)), colorbar
hidct2d = vision.IDCT;
J(abs(J) < 10) = 0;
It = step(hidct2d, J);
figure, imshow(I, [0 255]), title('Original image')
figure, imshow(It,[0 255]), title('Reconstructed image')
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2-D DCT block reference page. The object properties correspond
to the block parameters.
2-269
vision.DCT.clone
Purpose Create 2-D discrete cosine transform object with same property values
Syntax C = clone(H)
Description C = clone(H) creates a DCT System object C, with the same property
values as H. The clone method creates a new unlocked object.
2-270
vision.DCT.getNumInputs
Syntax N = getNumInputs(H)
2-271
vision.DCT.getNumOutputs
Syntax N = getNumOutputs(H)
2-272
vision.DCT.isLocked
Syntax TF = isLocked(H)
2-273
vision.DCT.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-274
vision.DCT.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-275
vision.Deinterlacer
Properties Method
Method used to deinterlace input video
Specify how the object deinterlaces the input video as one of Line
repetition | Linear interpolation | Vertical temporal
median filtering. The default is Line repetition.
TransposedInput
Indicate if input data is in row-major order
Set this property to true if the input buffer contains data elements
from the first row first, then the second row second, and so on.
The default is false.
2-276
vision.Deinterlacer
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor. This property applies when you set the Method property to
Linear Interpolation.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The default
is Wrap. This property applies when you set the Method property
to Linear Interpolation.
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as one of Same as
input | Custom. The default is Custom. This property applies
when you set the Method property to Linear Interpolation.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property is applicable
when the AccumulatorDataType property is Custom. This
property applies when you set the Method property to Linear
Interpolation.
The default is numerictype([],12,3).
OutputDataType
Output word and fraction lengths
2-277
vision.Deinterlacer
hdint = vision.Deinterlacer;
x = imread('vipinterlace.png');
y = step(hdint, x);
imshow(x); title('Original Image');
figure, imshow(y); title('Image after deinterlacing');
2-278
vision.Deinterlacer
Algorithms This object implements the algorithm, inputs, and outputs described
on the Deinterlacing block reference page. The object properties
correspond to the block parameters.
2-279
vision.Deinterlacer.clone
Syntax C = clone(H)
2-280
vision.Deinterlacer.getNumInputs
Syntax N = getNumInputs(H)
2-281
vision.Deinterlacer.getNumOutputs
Syntax N = getNumOutputs(H)
2-282
vision.Deinterlacer.isLocked
Syntax TF = isLocked(H)
2-283
vision.Deinterlacer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-284
vision.Deinterlacer.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-285
vision.DemosaicInterpolator
Properties Method
Interpolation algorithm
Specify the algorithm the object uses to calculate the missing color
information as one of Bilinear | Gradient-corrected linear.
The default is Gradient-corrected linear.
SensorAlignment
Alignment of the input image
Specify the sequence of R, G and B pixels that correspond to the
2-by-2 block of pixels in the top-left corner, of the image. It can
be set to one of RGGB |GRBG | GBRG | BGGR. The default is RGGB.
Specify the sequence in left-to-right, top-to-bottom order.
2-286
vision.DemosaicInterpolator
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Saturate.
ProductDataType
Product output word and fraction lengths
Specify the product output fixed-point data type as one of Same
as input | Custom. The default is Custom.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ProductDataType property to Custom. The default is
numerictype([],32,10).
AccumulatorDataType
Data type of the accumulator
Specify the accumulator fixed-point data type as one of Same as
product | Same as input | Custom. The default is Same as
product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
2-287
vision.DemosaicInterpolator
x = imread('mandi.tif');
hdemosaic = ...
vision.DemosaicInterpolator('SensorAlignment', 'BGGR');
y = step(hdemosaic, x);
imshow(x,'InitialMagnification',20);
title('Original Image');
figure, imshow(y,'InitialMagnification',20);
title('RGB image after demosaic');
2-288
vision.DemosaicInterpolator
Algorithms This object implements the algorithm, inputs, and outputs described on
the Demosaic block reference page. The object properties correspond
to the block parameters, except:
2-289
vision.DemosaicInterpolator.clone
Syntax C = clone(H)
2-290
vision.DemosaicInterpolator.getNumInputs
Syntax N = getNumInputs(H)
2-291
vision.DemosaicInterpolator.getNumOutputs
Syntax N = getNumOutputs(H)
2-292
vision.DemosaicInterpolator.isLocked
Syntax TF = isLocked(H)
2-293
vision.DemosaicInterpolator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-294
vision.DemosaicInterpolator.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-295
vision.DeployableVideoPlayer
To display video:
1 Define and set up your deployable video player object using the
constructor.
2-296
vision.DeployableVideoPlayer
2 Call the step method with the deployable video player object,
depVideoPlayer, and any optional properties. See the syntax below
for using the step method.
Properties Location
Location of bottom left corner of video window
Specify the location for the bottom left corner of the video player
window as a two-element vector. The first and second elements
are specified in pixels and represent the horizontal and vertical
coordinates respectively. The coordinates [0 0] represent the
bottom left corner of the screen.
Default: Dependent on the screen resolution, and will result in a
window positioned in the center of the screen.
Name
Video window title bar caption
Specify the caption to display on the video player window title
bar as any string.
Default: ‘Deployable Video Player’
Size
Size of video display window
Specify the video player window size as Full-screen, True size
(1:1) or Custom. When this property is set to Full-screen, use
the Esc key to exit out of full-screen mode.
2-297
vision.DeployableVideoPlayer
2-298
vision.DeployableVideoPlayer
videoFReader = vision.VideoFileReader;
depVideoPlayer = vision.DeployableVideoPlayer;
while ~isDone(videoFReader)
frame = step(videoFReader);
step(depVideoPlayer, frame);
end
release(videoFReader);
release(depVideoPlayer);
2-299
vision.DeployableVideoPlayer.clone
Purpose Create deployable video player object with same property values
Syntax C = clone(H)
2-300
vision.DeployableVideoPlayer.getNumInputs
Syntax N = getNumInputs(H)
2-301
vision.DeployableVideoPlayer.getNumOutputs
Syntax N = getNumOutputs(H)
2-302
vision.DeployableVideoPlayer.isLocked
Syntax TF = isLocked(H)
2-303
vision.DeployableVideoPlayer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-304
vision.DeployableVideoPlayer.step
Syntax step(depVideoPlayer,I)
step(depVideoPlayer,Y,Cb,Cr)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-305
vision.EdgeDetector
Description The EdgeDetector object finds edges of objects in images. For Sobel,
Prewitt and Roberts algorithms, the object finds edges in an input image
by approximating the gradient magnitude of the image. The object
obtains the gradient as a result of convolving the image with the Sobel,
Prewitt or Roberts kernel. For Canny algorithm, the object finds edges
by looking for the local maxima of the gradient of the input image. The
calculation derives the gradient using a Gaussian filter. This algorithm
is more robust to noise and more likely to detect true weak edges.
Properties Method
Edge detection algorithm
Specify the edge detection algorithm as one of Sobel | Prewitt
| Roberts | Canny. The default is Sobel.
BinaryImageOutputPort
Output the binary image
2-306
vision.EdgeDetector
Set this property to true to output the binary image after edge
detection. When you set this property to true, the object will
output a logical matrix. The nonzero elements of this matrix
correspond to the edge pixels and the zero elements correspond
to the background pixels. This property applies when you set the
Method property to Sobel, Prewitt or Roberts.
The default is true.
GradientComponentOutputPorts
Output the gradient components
Set this property to true to output the gradient components after
edge detection. When you set this property to true, and the
Method property to Sobel or Prewitt, this System object outputs
the gradient components that correspond to the horizontal and
vertical edge responses. When you set the Method property to
Roberts, the System object outputs the gradient components
that correspond to the 45 and 135 degree edge responses. Both
BinaryImageOutputPort and GradientComponentOutputPorts
properties cannot be false at the same time.
The default is false.
ThresholdSource
Source of threshold value
Specify how to determine threshold as one of Auto | Property |
Input port. The default is Auto. This property applies when you
set the Method property to Canny. This property also applies when
you set the Method property to Sobel, Prewitt or Roberts and the
BinaryImageOutputPort property to true.
Threshold
Threshold value
Specify the threshold value as a scalar of a MATLAB built-in
numeric data type. When you set the you set the Method property
to Sobel, Prewitt or Roberts, you must a value within the range
2-307
vision.EdgeDetector
of the input data. When you set the Method property to Canny,
specify the threshold as a two-element vector of low and high
values that define the weak and strong edges. This property
is accessible when the ThresholdSource property is Property.
This property is tunable.
The default is[0.25 0.6] when you set the Method property to
Canny. Otherwise, The default is20.
ThresholdScaleFactor
Multiplier to adjust value of automatic threshold
Specify multiplier that is used to adjust calculation of automatic
threshold as a scalar MATLAB built-in numeric data type. This
property applies when you set the Method property to Sobel,
Prewitt or Roberts and the ThresholdSource property to Auto.
This property is tunable.
The default is 4.
EdgeThinning
Enable performing edge thinning
Indicate whether to perform edge thinning. Choosing to perform
edge thinning requires additional processing time and resources.
This property applies when you set the Method property to Sobel,
Prewitt or Roberts and the BinaryImageOutputPort property
to true.
The default is false.
NonEdgePixelsPercentage
Approximate percentage of weak and nonedge pixels
Specify the approximate percentage of weak edge and nonedge
image pixels as a scalar between 0 and 100. This property
applies when you set the Method property to Canny and the
ThresholdSource to Auto. This property is tunable.
The default is 70.
2-308
vision.EdgeDetector
GaussianFilterStandardDeviation
Standard deviation of Gaussian
filter Specify the standard deviation of the Gaussian filter whose
derivative is convolved with the input image. You can set this
property to any positive scalar. This property applies when you
set the Method property to Canny.
The default is 1.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Custom. This property applies when you do not set the Method
property to Canny.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. This property
applies when you do not set the Method property to Canny.
The default is Wrap.
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as first
input | Custom. The default is Custom. This property applies
when you do not set the Method property to Canny.
CustomProductDataType
Product word and fraction lengths
2-309
vision.EdgeDetector
2-310
vision.EdgeDetector
Create edge detector, color space converter, and image type converter
objects.
hedge = vision.EdgeDetector;
hcsc = vision.ColorSpaceConverter('Conversion', 'RGB to intensity
hidtypeconv = vision.ImageDataTypeConverter('OutputDataType','sin
Read in the original image and convert color and data type.
Find edges.
2-311
vision.EdgeDetector
subplot(1,2,1);
imshow(imread('peppers.png'));
subplot(1,2,2);
imshow(edges);
2-312
vision.EdgeDetector
Algorithms This object implements the algorithm, inputs, and outputs described
on the Edge Detection block reference page. The object properties
correspond to the block parameters.
2-313
vision.EdgeDetector.clone
Syntax C = clone(H)
2-314
vision.EdgeDetector.getNumInputs
Syntax N = getNumInputs(H)
2-315
vision.EdgeDetector.getNumOutputs
Syntax N = getNumOutputs(H)
2-316
vision.EdgeDetector.isLocked
Syntax TF = isLocked(H)
2-317
vision.EdgeDetector.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-318
vision.EdgeDetector.step
Description EDGES = step(H,IMG) finds the edges, EDGES , in input IMG using the
specified algorithm when the BinaryImageOutputPort property is
true. EDGES is a boolean matrix with non-zero elements representing
edge pixels and zero elements representing background pixels.
[GV,GH] = step(H,IMG) finds the two gradient components, GV and GH
, of the input IMG, when you set the Method property to Sobel, Prewitt
or Roberts, and you set the GradientComponentOutputPorts property
to true and the BinaryImageOutputPort property to false. If you set
the Method property to Sobel or Prewitt, then GV is a matrix of gradient
values in the vertical direction and GH is a matrix of gradient values in
the horizontal direction. If you set the Method property to Roberts, then
GV represents the gradient component at 45 degree edge response, and
GH represents the gradient component at 135 degree edge response.
[EDGES,GV,GH] = step(H,IMG) finds the edges, EDGES , and the
two gradient components, GV and GH , of the input IMG when you
set the Method property to Sobel, Prewitt or Roberts and both
the BinaryImageOutputPort and GradientComponentOutputPorts
properties are true.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-319
vision.FFT
To compute FFT:
2 Call the step method with the input image, I and the FFT object,
fftObj. See the syntax below for using the step method.
Properties FFTImplementation
FFT implementation
2-320
vision.FFT
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent |
Floor | Nearest | Round | Simplest | Zero.
Default: Floor
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate.
Default: Wrap
2-321
vision.FFT
SineTableDataType
Sine table word and fraction lengths
Specify the sine table data type as Same word length as input,
or Custom.
Default: Same word length as input
CustomSineTableDataType
Sine table word and fraction lengths
Specify the sine table fixed-point type as an unscaled numerictype
object with a Signedness of Auto. This property applies only
when you set the SineTableDataType property to Custom.
Default: numerictype([],16)
ProductDataType
Product word and fraction lengths
Specify the product data type as Full precision, Same as
input, or Custom.
Default: Full precision
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies only
when you set the ProductDataType property to Custom.
Default: numerictype([],32,30)
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator data type as Full precision, Same as
input, Same as product, or Custom.
Default: Full precision
2-322
vision.FFT
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies only
when you set the AccumulatorDataType property to Custom.
Default: numerictype([],32,30)
OutputDataType
Output word and fraction lengths
Specify the output data type as Full precision, Same as input,
or Custom.
Default: Full precision
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype object
with a Signedness of Auto. This property applies when you set
the OutputDataType property to Custom.
Default: numerictype([],16,15)
2-323
vision.FFT
fftObj = vision.FFT;
I = im2single(imread('pout.tif'));
J = step(fftObj, I);
J_shifted = fftshift(J);
2-324
vision.FFT.clone
Syntax C = clone(H)
Description C = clone(H) creates an FFT System object C, with the same property
values as H. The clone method creates a new unlocked object.
2-325
vision.FFT.getNumInputs
Syntax N = getNumInputs(H)
2-326
vision.FFT.getNumOutputs
Syntax N = getNumOutputs(H)
2-327
vision.FFT.isLocked
Syntax TF = isLocked(H)
2-328
vision.FFT.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-329
vision.FFT.step
Syntax Y = step(H,X)
2-330
vision.ForegroundDetector
Properties AdaptLearningRate
Adapt learning rate
Enables the object to adapt the learning rate during the period
specified by the NumTrainingFrames property. When you set this
property to true, the object sets the LearningRate property to
1/(current frame number). When you set this property to false,
the LearningRate property must be set at each time step.
2-331
vision.ForegroundDetector
Default: true
NumTrainingFrames
Number of initial video frames for training background model
Set this property to the number of training frames at the start of
the video sequence.
When you set the AdaptLearningRate to false, this property
will not be available.
Default: 150
LearningRate
Learning rate for parameter updates
Specify the learning rate to adapt model parameters. This
property controls how quickly the model adapts to changing
conditions. Set this property appropriately to ensure algorithm
stability.
When you set AdaptLearningRate to true, the LearningRate
property takes effect only after the training period specified by
NumTrainingFrames is over.
When you set the AdaptLearningRate to false, this property will
not be available. This property is tunable.
Default: 0.005
MinimumBackgroundRatio
Threshold to determine background model
Set this property to represent the minimum of the apriori
probabilities for pixels to be considered background values.
Multimodal backgrounds can not be handled, if this value is too
small.
Default: 0.7
NumGaussians
2-332
vision.ForegroundDetector
30 255
2
2-333
vision.ForegroundDetector
videoSource = vision.VideoFileReader('viptraffic.avi','ImageColorSpace','
detector = vision.ForegroundDetector(...
'NumTrainingFrames', 5, ... % 5 because of short video
'InitialVariance', 30*30); % initial standard deviation of 30
blob = vision.BlobAnalysis(...
'CentroidOutputPort', false, 'AreaOutputPort', false, ...
'BoundingBoxOutputPort', true, ...
'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 250);
shapeInserter = vision.ShapeInserter('BorderColor','White');
videoPlayer = vision.VideoPlayer();
while ~isDone(videoSource)
frame = step(videoSource);
fgMask = step(detector, frame);
bbox = step(blob, fgMask);
out = step(shapeInserter, frame, bbox); % draw bounding boxes aro
step(videoPlayer, out); % view results in the video player
end
release(videoPlayer);
release(videoSource);
2-334
vision.ForegroundDetector
2-335
vision.ForegroundDetector.clone
Syntax C = clone(H)
2-336
vision.ForegroundDetector.getNumInputs
Syntax N = getNumInputs(H)
2-337
vision.ForegroundDetector.getNumOutputs
Syntax N = getNumOutputs(H)
2-338
vision.ForegroundDetector.isLocked
Syntax TF = isLocked(H)
2-339
vision.ForegroundDetector.release
Syntax release(H)
Note You cannot use the release method on System objects in code
generated from MATLAB.
2-340
vision.ForegroundDetector.reset
Syntax reset(H)
Description reset(H) resets the GMM model to its initial state for the
ForegroundDetector object H.
2-341
vision.ForegroundDetector.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-342
vision.GammaCorrector
Properties Correction
Specify gamma correction or linearization
Specify the object’s operation as one of Gamma | De-gamma. The
default is Gamma.
Gamma
Gamma value of output or input
When you set the Correction property to Gamma, this property
gives the desired gamma value of the output video stream. When
you set the Correction property to De-gamma, this property
indicates the gamma value of the input video stream. You must
2-343
vision.GammaCorrector
2-344
vision.GammaCorrector
hgamma = ...
vision.GammaCorrector(2.0,'Correction','De-gamma');
x = imread('pears.png');
y = step(hgamma, x);
Algorithms This object implements the algorithm, inputs, and outputs described
on the Gamma Correction block reference page. The object properties
correspond to the block parameters.
2-345
vision.GammaCorrector.clone
Syntax C = clone(H)
2-346
vision.GammaCorrector.getNumInputs
Syntax N = getNumInputs(H)
2-347
vision.GammaCorrector.getNumOutputs
Syntax N = getNumOutputs(H)
2-348
vision.GammaCorrector.isLocked
Syntax TF = isLocked(H)
2-349
vision.GammaCorrector.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-350
vision.GammaCorrector.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-351
vision.GeometricRotator
Properties OutputSize
Output size as full or same as input image size
Specify the size of output image as one of Expanded to fit
rotated input image | Same as input image. The default is
Expanded to fit rotated input image. When you set this
property to Expanded to fit rotated input image, the object
outputs a matrix that contains all the rotated image values. When
you set this property to Same as input image, the object outputs
a matrix that contains the middle part of the rotated image.
AngleSource
Source of angle
Specify how to specify the rotation angle as one of Property |
Input port. The default is Property.
Angle
Rotation angle value (radians)
2-352
vision.GeometricRotator
Set this property to a real, scalar value for the rotation angle
(radians). The default is pi/6. This property applies when you
set the AngleSource property to Property.
MaximumAngle
Maximum angle by which to rotate image
Specify the maximum angle by which to rotate the input image
as a numeric scalar value greater than 0. The default is pi. This
property applies when you set the AngleSource property to Input
port.
RotatedImageLocation
How the image is rotated
Specify how the image is rotated as one of Top-left corner |
Center. The default is Center. When you set this property to
Center, the object rotates the image about its center point. When
you set this property to Top-left corner, the object rotates the
image so that two corners of the input image are always in contact
with the top and left side of the output image. This property
applies when you set the OutputSize property to Expanded to
fit rotated input image, and, the AngleSource property to
Input port.
SineComputation
How to calculate the rotation
Specify how to calculate the rotation as one of Trigonometric
function | Table lookup. The default is Table lookup. When
you set this property to Trigonometric function, the object
computes the sine and cosine values it needs to calculate the
rotation of the input image. When you set this property to Table
lookup, the object computes the trigonometric values it needs
to calculate the rotation of the input image, and stores them in
a table. The object uses the table, each time it calls the step
method. In this case, the object requires extra memory.
BackgroundFillValue
2-353
vision.GeometricRotator
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. he
default is Nearest. This property applies when you set the
SineComputation property to Table lookup. T
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Saturate. This property applies when you set the
SineComputation property to Table lookup.
AngleDataType
2-354
vision.GeometricRotator
2-355
vision.GeometricRotator
2-356
vision.GeometricRotator
Examples Rotate an image 30 degrees ( 6 radians)
img = im2double(imread('peppers.png'));
hrotate = vision.GeometricRotator;
hrotate.Angle = pi / 6;
hrotate = vision.GeometricRotator;
hrotate.AngleSource = 'Input port';
img = im2double(imread('onion.png'));
figure;
% Rotate img by multiple angles
for i = 1: 4
rotimg = step(hrotate,img,i*pi/16);
subplot(1,4,i);
imshow(rotimg);
end
Algorithms This object implements the algorithm, inputs, and outputs described
on the Rotate block reference page. The object properties correspond
to the block parameters.
2-357
vision.GeometricRotator.clone
Syntax C = clone(H)
2-358
vision.GeometricRotator.getNumInputs
Syntax N = getNumInputs(H)
2-359
vision.GeometricRotator.getNumOutputs
Syntax N = getNumOutputs(H)
2-360
vision.GeometricRotator.isLocked
Syntax TF = isLocked(H)
2-361
vision.GeometricRotator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-362
vision.GeometricRotator.step
Syntax Y = step(H,IMG)
Y = step(H,IMG,ANGLE)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-363
vision.GeometricScaler
Properties SizeMethod
Aspects of image to resize
2-364
vision.GeometricScaler
2-365
vision.GeometricScaler
2-366
vision.GeometricScaler
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Nearest.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Saturate.
InterpolationWeightsDataType
Interpolation weights word and fraction lengths
Specify the interpolation weights fixed-point data type as one
of Same word length as input | Custom. The default is Same
word length as input. This property applies when you set:
2-367
vision.GeometricScaler
CustomInterpolationWeightsDataType
Interpolation weights word and
fraction lengths Specify the interpolation weights
fixed-point type as an unscaled numerictype object with a
Signedness of Auto. This property applies when you set the
InterpolationWeightsDataType property to Custom. The default
is numerictype([],32).
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as input
| Custom. The default is Custom.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ProductDataType property to Custom. The default is
numerictype([],32,10).
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as one of Same as
product | Same as input | Custom. The default is Same as
product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
2-368
vision.GeometricScaler
Examples Enlarge an image. Display the original and the enlarged images.
I=imread('cameraman.tif');
hgs=vision.GeometricScaler;
hgs.SizeMethod = ...
2-369
vision.GeometricScaler
J = step(hgs,I);
imshow(I); title('Original Image');
figure,imshow(J);title('Resized Image');
Algorithms This object implements the algorithm, inputs, and outputs described
on the Resize block reference page. The object properties correspond
to the block parameters.
2-370
vision.GeometricScaler.clone
Syntax C = clone(H)
2-371
vision.GeometricScaler.getNumInputs
Syntax N = getNumInputs(H)
2-372
vision.GeometricScaler.getNumOutputs
Syntax N = getNumOutputs(H)
2-373
vision.GeometricScaler.isLocked
Syntax TF = isLocked(H)
2-374
vision.GeometricScaler.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-375
vision.GeometricScaler.step
Syntax J = step(H,I)
J = step(H,X,ROI)
[J,FLAG] = step(H,I,ROI)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-376
vision.GeometricShearer
Properties Direction
Direction to apply offset
Specify the direction of linearly increasing the offset as one of
Horizontal | Vertical. The default is Horizontal. Set this
property to Horizontal to linearly increase the offset of the rows,
or Vertical to linearly increase the offset of the columns.
OutputSize
Output size
Specify the size of the output image as one of Full | Same as
input image. The default is Full. If you set this property to
Full, the object outputs a matrix that contains the sheared image
values. If you set this property to Same as input image, the
object outputs a matrix that is the same size as the input image
and contains a portion of the sheared image.
ValuesSource
2-377
vision.GeometricShearer
2-378
vision.GeometricShearer
the new pixel value as the weighted average of the four nearest
pixel values.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Nearest.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The
default is Saturate.
ValuesDataType
Shear values word and fraction lengths
Specify the shear values fixed-point data type as one of Same word
length as input | Custom. The default is Same word length
as input. This property applies when you set the ValuesSource
property to Property.
CustomValuesDataType
Shear values word and fraction lengths
Specify the shear values fixed-point type as an auto-signed
numerictype object. This property applies when you set the
ValuesSource property to Property and the ValuesDataType
property to Custom. The default is numerictype([],32,10).
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as first
input | Custom. The default is Custom. This property applies
2-379
vision.GeometricShearer
2-380
vision.GeometricShearer
Algorithms This object implements the algorithm, inputs, and outputs described
on the Shear block reference page. The object properties correspond
to the block parameters.
2-381
vision.GeometricShearer.clone
Syntax C = clone(H)
2-382
vision.GeometricShearer.getNumInputs
Syntax N = getNumInputs(H)
2-383
vision.GeometricShearer.getNumOutputs
Syntax N = getNumOutputs(H)
2-384
vision.GeometricShearer.isLocked
Syntax TF = isLocked(H)
2-385
vision.GeometricShearer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-386
vision.GeometricShearer.step
Syntax Y = step(H,IMG)
Y = step(H,IMG,S)
Description Y = step(H,IMG) shifts the input, IMG, and returns the shifted image,
Y, with the shear values specified by the Values property.
Y = step(H,IMG,S) uses the two-element vector, S, as the number of
pixels by which to shift the first and last rows or columns of IMG. This
applies when you set the ValuesSource property to Input port.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-387
vision.GeometricTransformer
Properties TransformMatrixSource
Method to specify transformation matrix
Specify as one of Property | Input port.
Default: Input port.
TransformMatrix
Transformation matrix
Specify the applied transformation matrix as a 3-by-2 or Q-by-6
affine transformation matrix, or a 3-by-3 or a Q-by-9 projective
transformation matrix. Q is the number of transformations.
2-388
vision.GeometricTransformer
2-389
vision.GeometricTransformer
2-390
vision.GeometricTransformer
ClippingStatusOutputPort
Enable clipping status flag output
Set this property to true to enable the output of a flag indicating
if any part of the output image is outside the input image.
Default: false
htrans1 = vision.GeometricTransformer(...
'TransformMatrixSource', 'Property', ...
'TransformMatrix',[1 0 0; .5 1 0; 0 0 1],...
'OutputImagePositionSource', 'Property',...
'OutputImagePosition', [0 0 400 750]);
img1 = im2single(rgb2gray(imread('peppers.png')));
transimg1 = step(htrans1,img1);
imshow(transimg1);
2-391
vision.GeometricTransformer
htrans2 = vision.GeometricTransformer;
img2 = checker_board(20,10);
Algorithms This object implements the algorithm, inputs, and outputs described on
the Apply Geometric Transformation block reference page. The object
properties correspond to the block parameters.
2-392
vision.GeometricTransformer.clone
Syntax C = clone(H)
2-393
vision.GeometricTransformer.getNumInputs
Syntax N = getNumInputs(H)
2-394
vision.GeometricTransformer.getNumOutputs
Syntax N = getNumOutputs(H)
2-395
vision.GeometricTransformer.isLocked
Syntax TF = isLocked(H)
2-396
vision.GeometricTransformer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-397
vision.GeometricTransformer.step
Syntax Y = step(H,X,TFORM)
Y = step(H,X)
Y = step(H,X,ROI)
[Y, ROIFLAG]=(H,X,...)
[Y,CLIPFLAG]=(H,X,...)
[Y,ROIFLAG,CLIPFLAG] = step(H,X,TFORM,ROI)
2-398
vision.GeometricTransformer.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-399
vision.GeometricTransformEstimator
Description
Note It is recommended that you use the new
estimateGeometricTransform function in place of the
vision.GeometricTransformEstimator object.
2-400
vision.GeometricTransformEstimator
Properties Transform
Transformation type
Specify transformation type as one of Nonreflective similarity
| Affine | Projective.
Default: Affine
ExcludeOutliers
Whether to exclude outliers from input points
Set this property to true to find and exclude outliers from the
input points and use only the inlier points to calculate the
transformation matrix. When you set this property to false, all
input points are used to calculate the transformation matrix.
Default: true
Method
Method to find outliers
Specify the method to find outliers as one of Random Sample
Consensus (RANSAC) | Least Median of Squares.
Default: Random Sample Consensus (RANSAC).
AlgebraicDistanceThreshold
Algebraic distance threshold for determining inliers
Specify a scalar threshold value for determining inliers as a
positive, scalar value. The threshold controls the upper limit
used to find the algebraic distance for the RANSAC method.
This property applies when you set the Transform property
to Projective and the Method property to Random Sample
Consensus (RANSAC). This property is tunable.
Default: 2.5.
PixelDistanceThreshold
Distance threshold for determining inliers in pixels
2-401
vision.GeometricTransformEstimator
Specify the upper limit of the algebraic distance that a point can
differ from the projection location of its associating point. Set this
property as a positive, scalar value. This property applies when
you set the Transform property to Nonreflective similarity or
to Affine, and the Method property to Random Sample Consensus
(RANSAC). This property is tunable.
Default: 2.5.
NumRandomSamplingsMethod
How to specify number of random samplings
Indicate how to specify number of random samplings as one of
Specified value | Desired confidence. Set this property to
Desired confidence to specify the number of random samplings
as a percentage and a maximum number. This property applies
when you set the ExcludeOutliers property to true and the
Method property to Random Sample Consensus (RANSAC).
Default: Specified value.
NumRandomSamplings
Number of random samplings
Specify the number of random samplings as a positive,
integer value. This property applies when you set the
NumRandomSamplingsMethod property to Specified value. This
property is tunable.
Default: 500.
DesiredConfidence
Probability to find largest group of points
Specify as a percentage, the probability to find the largest group
of points that can be mapped by a transformation matrix. This
property applies when you set the NumRandomSamplingsMethod
property to Desired confidence. This property is tunable.
Default: 99.
2-402
vision.GeometricTransformEstimator
MaximumRandomSamples
Maximum number of random samplings
Specify the maximum number of random samplings as a
positive, integer value. This property applies when you set the
NumRandomSamplingsMethod property to Desired confidence.
This property is tunable.
Default: 1000.
InlierPercentageSource
Source of inlier percentage
Indicate how to specify the threshold to stop random sampling
when a percentage of input point pairs have been found as inliers.
You can set this property to one of Auto | Property. If set to Auto
then inlier threshold is disabled. This property applies when you
set the Method property to Random Sample Consensus (RANSAC).
Default: Auto.
InlierPercentage
Percentage of point pairs to be found to stop random sampling
Specify the percentage of point pairs that needs to be determined
as inliers, to stop random sampling. This property applies when
you set the InlierPercentageSource property to Property. This
property is tunable.
Default: 75.
RefineTransformMatrix
Whether to refine transformation matrix
Set this property to true to perform additional iterative
refinement on the transformation matrix. This property applies
when you set the ExcludeOutliers property to true.
Default: false.
TransformMatrixDataType
2-403
vision.GeometricTransformEstimator
2-404
vision.GeometricTransformEstimator
ptsIn = detectSURFFeatures(Iin);
ptsOut = detectSURFFeatures(Iout);
[featuresIn validPtsIn] = extractFeatures(Iin, ptsIn);
[featuresOut validPtsOut] = extractFeatures(Iout, ptsOut);
matchedPtsIn = validPtsIn(index_pairs(:,1));
matchedPtsOut = validPtsOut(index_pairs(:,2));
figure; showMatchedFeatures(Iin,Iout,matchedPtsIn,matchedPtsOut);
title('Matched SURF points, including outliers');
gte = vision.GeometricTransformEstimator;
gte.Transform = 'Nonreflective similarity';
[tform inlierIdx] = step(gte, matchedPtsOut.Location, matchedPtsIn.Loc
figure; showMatchedFeatures(Iin,Iout,matchedPtsIn(inlierIdx),matchedPt
title('Matching inliers'); legend('inliersIn', 'inliersOut');
agt = vision.GeometricTransformer;
Ir = step(agt, im2single(Iout), tform);
figure; imshow(Ir); title('Recovered image');
input = checkerboard;
2-405
vision.GeometricTransformEstimator
[h, w] = size(input);
inImageCorners = [1 1; w 1; w h; 1 h];
outImageCorners = [4 21; 21 121; 79 51; 26 6];
hgte1 = vision.GeometricTransformEstimator('ExcludeOutliers', false);
tform = step(hgte1, inImageCorners, outImageCorners);
hgt = vision.GeometricTransformer;
output = step(hgt, input, tform);
figure; imshow(input); title('Original image');
figure; imshow(output); title('Transformed image');
2-406
vision.GeometricTransformEstimator
Algorithms This object implements the algorithm, inputs, and outputs described
on the Estimate Geometric Transformation block reference page. The
object properties correspond to the block parameters.
2-407
vision.GeometricTransformEstimator.clone
Purpose Create geometric transform estimator object with same property values
Syntax C = clone(H)
2-408
vision.GeometricTransformEstimator.getNumInputs
Syntax N = getNumInputs(H)
2-409
vision.GeometricTransformEstimator.getNumOutputs
Syntax N = getNumOutputs(H)
2-410
vision.GeometricTransformEstimator.isLocked
Syntax TF = isLocked(H)
2-411
vision.GeometricTransformEstimator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-412
vision.GeometricTransformEstimator.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-413
vision.GeometricTranslator
Properties OutputSize
Output size as full or same as input image size
Specify the size of output image after translation as one of Full |
Same as input image. The default is Full. When you set this
property to Full, the object outputs a matrix that contains the
translated image values. When you set this property to Same as
input image, the object outputs a matrix that is the same size as
the input image and contains a portion of the translated image.
OffsetSource
Source of specifying offset values
Specify how the translation parameters are provided as one of
Input port | Property. The default is Property. When you set
the OffsetSource property to Input port, a two-element offset
vector must be provided to the object’s step method.
Offset
2-414
vision.GeometricTranslator
Translation values
Specify the number of pixels to translate the image as a
two-element offset vector. The default is [1.5 2.3]. The first
element of the vector represents a shift in the vertical direction
and a positive value moves the image downward. The second
element of the vector represents a shift in the horizontal direction
and a positive value moves the image to the right. This property
applies when you set the OffsetSource property to Property.
MaximumOffset
Maximum number of pixels by which to translate image
Specify the maximum number of pixels by which to translate the
input image as a two-element real vector with elements greater
than 0. The default is [8 10]. This property must have the same
data type as the Offset input. This property applies when you set
the OutputSize property to Full and OffsetSource property to
Input port. The system object uses this property to determine
the size of the output matrix. If the Offset input is greater than
this property value, the object saturates to the maximum value.
BackgroundFillValue
Value of pixels outside image
Specify the value of pixels that are outside the image as a numeric
scalar value or a numeric vector of same length as the third
dimension of input image. The default is 0.
InterpolationMethod
Interpolation method used to translate image
Specify the interpolation method used to translate the image as
one of Nearest neighbor | Bilinear | Bicubic. The default
is Bilinear. When you set this property to Nearest neighbor,
the object uses the value of the nearest pixel for the new pixel
value. When you set this property to Bilinear, the object sets
the new pixel value as the weighted average of the four nearest
pixel values. When you set this property to Bicubic, the object
2-415
vision.GeometricTranslator
sets the new pixel value as the weighted average of the sixteen
nearest pixel values.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Nearest.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap |Saturate. The default
is Saturate.
OffsetValuesDataType
Offset word and fraction lengths
Specify the offset fixed-point data type as one of Same word
length as input | Custom. The default is Same word length
as input.
CustomOffsetValuesDataType
Offset word and fraction lengths
Specify the offset fixed-point type as a signed numerictype object
with a Signedness of Auto. This property applies when you set
the OffsetValuesDataType property to Custom. The default is
numerictype([],16,6).
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as first
input | Custom. The default is Custom. This property is applies
2-416
vision.GeometricTranslator
2-417
vision.GeometricTranslator
htranslate=vision.GeometricTranslator;
htranslate.OutputSize='Same as input image';
htranslate.Offset=[30 30];
I=im2single(imread('cameraman.tif'));
Y = step(htranslate,I);
imshow(Y);
Algorithms This object implements the algorithm, inputs, and outputs described on
the Translate block reference page. The object properties correspond
to the block parameters.
2-418
vision.GeometricTranslator.clone
Syntax C = clone(H)
2-419
vision.GeometricTranslator.getNumInputs
Syntax N = getNumInputs(H)
2-420
vision.GeometricTranslator.getNumOutputs
Syntax N = getNumOutputs(H)
2-421
vision.GeometricTranslator.isLocked
Syntax TF = isLocked(H)
2-422
vision.GeometricTranslator.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-423
vision.GeometricTranslator.step
Syntax Y = step(H,I)
Y = step(H,I,OFFSET)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-424
vision.Histogram
Properties LowerLimit
Lower boundary
Specify the lower boundary of the lowest-valued bin as a
real-valued scalar value. NaN and Inf are not valid values for this
property. The default is 0. This property is tunable.
UpperLimit
Upper boundary
Specify the upper boundary of the highest-valued bin as a
real-valued scalar value. NaN and Inf are not valid values for this
property. The default is 1. This property is tunable.
2-425
vision.Histogram
NumBins
Number of bins in the histogram
Specify the number of bins in the histogram. The default is 256.
Normalize
Enable output vector normalization
Specify whether the output vector, v, is normalized such that
sum(v) = 1. Use of this property is not supported for fixed-point
signals. The default is false.
RunningHistogram
Enable calculation over successive calls to step method
Set this property to true to enable computing the histogram of
the input elements over successive calls to the step method. Set
this property to false to enable basic histogram operation. The
default is false.
ResetInputPort
Enable resetting in running histogram mode
Set this property to true to enable resetting the running
histogram. When the property is set to true, a reset input must be
specified to the step method to reset the running histogram. This
property applies when you set the RunningHistogram property
to true. When you set this property to false, the object does not
reset. The default is false.
ResetCondition
Condition for running histogram mode
Specify event to reset the running histogram as Rising edge,
Falling edge, Either edge, or Non-zero. This property applies
when you set the ResetInputPort property to true. The default
is Non-zero.
2-426
vision.Histogram
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. The default is
Wrap.
ProductDataType
Data type of product
Specify the product data type as Full precision, Same as
input, or Custom. The default is Full precision.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a signed, scaled
numerictype object. This property applies only when you
set the ProductDataType property to Custom. The default is
numerictype(true,32,30).
AccumulatorDataType
Data type of the accumulator
Specify the accumulator data type as, Same as input, Same as
product, or Custom. The default is Same as input.
CustomAccumulatorDataType
Accumulator word and fraction lengths
2-427
vision.Histogram
img = im2single(rgb2gray(imread('peppers.png')));
hhist2d = vision.Histogram;
y = step(hhist2d,img);
bar((0:255)/256, y);
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2D-Histogram block reference page. The object properties
correspond to the block parameters, except:
2-428
vision.Histogram
2-429
vision.Histogram.clone
Syntax C = clone(H)
2-430
vision.Histogram.getNumInputs
Syntax N = getNumInputs(H)
2-431
vision.Histogram.getNumOutputs
Syntax N = getNumOutputs(H)
2-432
vision.Histogram.isLocked
Syntax TF = isLocked(H)
2-433
vision.Histogram.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-434
vision.Histogram.reset
Syntax reset(H)
Description reset(H) sets the Histogram object bin values to zero when the
RunningHistogram property is true.
2-435
vision.Histogram.step
Syntax Y = step(H,X)
Y = step(H,X,R)
Description Y = step(H,X) returns a histogram y for the input data X. When you set
the RunningHistogram property to true, Y corresponds to the histogram
of the input elements over successive calls to the step method.
Y = step(H,X,R) computes the histogram of the input X elements over
successive calls to the step method, and optionally resets the object’s
state based on the value of R and the object’s ResetCondition property.
This applies when you set the RunningHistogram and ResetInputPort
properties to true.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-436
vision.HistogramBasedTracker
2-437
vision.HistogramBasedTracker
Properties ObjectHistogram
Normalized pixel value histogram
An N-element vector. This vector specifies the normalized
histogram of the object’s pixel values. Histogram values must
be normalized to a value between 0 and 1. You can use the
initializeObject method to set the property. This property
is tunable.
2-438
vision.HistogramBasedTracker
Default: []
Create System objects for reading and displaying video and for drawing
a bounding box of the object.
videoFileReader = vision.VideoFileReader('vipcolorsegmentation.avi');
videoPlayer = vision.VideoPlayer();
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBor
Read the first video frame, which contains the object. Convert the
image to HSV color space. Then define and display the object region.
objectFrame = step(videoFileReader);
objectHSV = rgb2hsv(objectFrame);
objectRegion = [40, 45, 25, 25];
objectImage = step(shapeInserter, objectFrame, objectRegion);
figure; imshow(objectImage); title('Red box shows object region');
Optionally, you can select the object region using your mouse. The object
must occupy the majority of the region. Use the following command.
2-439
vision.HistogramBasedTracker
figure; imshow(objectFrame);
objectRegion=round(getPosition(imrect))
Set the object, based on the hue channel of the first video frame.
tracker = vision.HistogramBasedTracker;
initializeObject(tracker, objectHSV(:,:,1) , objectRegion);
Track and display the object in each video frame. The while loop reads
each image frame, converts the image to HSV color space, then tracks
the object in the hue channel where it is distinct from the background.
Finally, the example draws a box around the object and displays the
results.
while ~isDone(videoFileReader)
frame = step(videoFileReader);
hsv = rgb2hsv(frame);
bbox = step(tracker, hsv(:,:,1));
release(videoPlayer);
release(videoFileReader);
2-440
vision.HistogramBasedTracker.clone
Syntax C = clone(H)
2-441
vision.HistogramBasedTracker.initializeObject
Syntax initializeObject(H,I,R)
Description Use the initializeObject method to set the object to track, and to
set the initial search window. Use this method before calling the step
method.
initializeObject(H,I,R) sets the object to track by extracting it from
the [x y width height] region R located in the 2-D input image, I. The
input image, I, can be any 2-D feature map that distinguishes the object
from the background. For example, the image can be a hue channel of
the HSV color space. Typically, I will be the first frame in which the
object appears. The region, R, is also used for the initial search window,
in the next call to the step method. For best results, the object must
occupy the majority of the region, R.
initializeObject(H,I,R,N) additionally, lets you specify N, the
number of histogram bins. By default, N is set to 16. Increasing N
enhances the ability of the tracker to discriminate the object. However,
this approach also narrows the range of changes to the object’s visual
characteristics that the tracker can accommodate. Consequently, this
narrow range increases the likelihood of losing track.
2-442
vision.HistogramBasedTracker.initializeSearchWindow
Syntax initializeSearchWindow(H,R)
2-443
vision.HistogramBasedTracker.isLocked
Syntax isLocked(H)
2-444
vision.HistogramBasedTracker.release
Syntax release(H)
2-445
vision.HistogramBasedTracker.step
Description BBOX = step(H,I) returns the bounding box, BBOX, of the tracked
object. The bounding box output is in the format [x y width height].
Before calling the step method, you must identify the object to track,
and set the initial search window. Use the initializeObject method
to do this.
[BBOX,ORIENTATION] = step(H,I) additionally returns the angle
between the x-axis and the major axis of the ellipse that has the same
second-order moments as the object. The returned angle is between
–pi/2 and pi/2.
[BBOX,ORIENTATION, SCORE] = step(H,I) additionally returns the
confidence score for the returned bounding box, BBOX, that contains the
tracked object. SCORE is between 0 and 1, with the greatest confidence
equal to 1.
Before calling the step method, you must identify the object to track,
and set the initial search window. Use the initializeObject method
to do this.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-446
vision.HistogramEqualizer
Properties Histogram
How to specify histogram
Specify the desired histogram of the output image as one of
Uniform | Input port | Custom. The default is Uniform.
CustomHistogram
Desired histogram of output image
Specify the desired histogram of output image as a numeric vector.
This property applies when you set the Histogram property to
Custom.
The default is ones(1,64).
BinCount
Number of bins for uniform histogram
2-447
vision.HistogramEqualizer
hhisteq = vision.HistogramEqualizer;
x = imread('tire.tif');
y = step(hhisteq, x);
imshow(x); title('Original Image');
figure, imshow(y);
title('Enhanced Image after histogram equalization');
Algorithms This object implements the algorithm, inputs, and outputs described on
the Histogram Equalization block reference page. The object properties
correspond to the block parameters, except:
The Histogram property for the object, corresponds to both the
Target Histogram and the Histogram Source parameters for
the block.
2-448
vision.HistogramEqualizer
2-449
vision.HistogramEqualizer.clone
Syntax C = clone(H)
2-450
vision.HistogramEqualizer.getNumInputs
Syntax N = getNumInputs(H)
2-451
vision.HistogramEqualizer.getNumOutputs
Syntax N = getNumOutputs(H)
2-452
vision.HistogramEqualizer.isLocked
Syntax TF = isLocked(H)
2-453
vision.HistogramEqualizer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-454
vision.HistogramEqualizer.step
Syntax Y = step(H,X)
Y = step(H,X,HIST)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-455
vision.HoughLines
Purpose Find Cartesian coordinates of lines that are described by rho and theta
pairs
Description The HoughLines object finds Cartesian coordinates of lines that are
described by rho and theta pairs. The object inputs are the theta and
rho values of lines and a reference image. The object outputs the
one-based row and column positions of the intersections between the
lines and two of the reference image boundary lines. The boundary
lines are the left and right vertical boundaries and the top and bottom
horizontal boundaries of the reference image.
Properties SineComputation
Method to calculate sine values used to find intersections of lines
Specify how to calculate sine values which are used to find
intersection of lines as Trigonometric function, or Table
lookup. If this property is set to Trigonometric function, the
object computes sine and cosine values it needs to calculate the
intersections of the lines. If it is set to Table lookup, the object
computes and stores the trigonometric values it needs to calculate
the intersections of the lines in a table and uses the table for each
2-456
vision.HoughLines
step call. In this case, the object requires extra memory. For
floating-point inputs, this property must be set to Trigonometric
function. For fixed-point inputs, the property must be set to
Table lookup. The default is Table lookup.
ThetaResolution
Spacing of the theta-axis
Specify the spacing of the theta-axis. This property applies when
you set the SineComputation property to Table lookup.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor. This property applies when you set the SineComputation
property to Table lookup.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. This property
applies when you set the SineComputation property to Table
lookup. The default is Wrap.
SineTableDataType
Sine table word and fraction lengths
Specify the sine table fixed-point data type as a constant property
always set to Custom. This property applies when you set the
SineComputation property to Table lookup.
CustomSineTableDataType
Sine table word and fraction lengths
2-457
vision.HoughLines
2-458
vision.HoughLines
I = imread('circuit.tif');
hedge = vision.EdgeDetector;
hhoughtrans = vision.HoughTransform(pi/360,'ThetaRhoOutputPort', t
hfindmax = vision.LocalMaximaFinder(1, 'HoughMatrixInput', true);
hhoughlines = vision.HoughLines('SineComputation','Trigonometric f
BW = step(hedge, I);
2-459
vision.HoughLines
2-460
vision.HoughLines
Algorithms This object implements the algorithm, inputs, and outputs described on
the Hough Lines block reference page. The object properties correspond
to the block parameters.
2-461
vision.HoughLines.clone
Syntax C = clone(H)
2-462
vision.HoughLines.getNumInputs
Syntax N = getNumInputs(H)
2-463
vision.HoughLines.getNumOutputs
Syntax N = getNumOutputs(H)
2-464
vision.HoughLines.isLocked
Syntax TF = isLocked(H)
2-465
vision.HoughLines.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-466
vision.HoughLines.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-467
vision.HoughTransform
Description The HoughTransform object finds lines in images via Hough transform.
The Hough transform maps points in the Cartesian image space to
curves in the Hough parameter space using the following equation:
2-468
vision.HoughTransform
Properties ThetaResolution
Theta resolution in radians
Specify the spacing of the Hough transform bins along the
theta-axis in radians, as a scalar numeric value between 0 and
pi/2. The default is pi/180.
RhoResolution
Rho resolution
Specify the spacing of the Hough transform bins along the rho-axis
as a scalar numeric value greater than 0. The default is 1.
ThetaRhoOutputPort
Enable theta and rho outputs
Set this property to true for the object to output theta and rho
values. The default is false.
OutputDataType
Data type of output
Specify the data type of the output signal as double, single, or
Fixed point. The default is double.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.This property applies when you set the OutputDataType
property to Fixed point.
OverflowAction
Overflow action for fixed-point operations
2-469
vision.HoughTransform
2-470
vision.HoughTransform
2-471
vision.HoughTransform
2-472
vision.HoughTransform
I = imread('circuit.tif');
hedge = vision.EdgeDetector;
hhoughtrans = vision.HoughTransform(pi/360,'ThetaRhoOutputPort', t
hfindmax = vision.LocalMaximaFinder(1, 'HoughMatrixInput', true);
hhoughlines = vision.HoughLines('SineComputation','Trigonometric f
BW = step(hedge, I);
2-473
vision.HoughTransform
Algorithms This object implements the algorithm, inputs, and outputs described
on the Hough Transform block reference page. The object properties
correspond to the block parameters.
2-474
vision.HoughTransform.clone
Syntax C = clone(H)
2-475
vision.HoughTransform.getNumInputs
Syntax N = getNumInputs(H)
2-476
vision.HoughTransform.getNumOutputs
Syntax N = getNumOutputs(H)
2-477
vision.HoughTransform.isLocked
Syntax TF = isLocked(H)
2-478
vision.HoughTransform.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-479
vision.HoughTransform.step
Purpose Output parameter space matrix for binary input image matrix
Syntax HT = step(H,BW)
[HT,THETA,RHO] = step(H,BW)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-480
vision.IDCT
Description The IDCT object computes 2-D inverse discrete cosine transform of the
input signal. The number of rows and columns of the input matrix must
be a power of 2.
Properties SineComputation
Specify how the System object computes sines and cosines as
Trigonometric function, or Table lookup. This property must
be set to Table lookup for fixed-point inputs.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.This property applies when you set the SineComputation
to Table lookup.
2-481
vision.IDCT
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap or Saturate. This property
applies when you set the SineComputation to Table lookup.
The default is Wrap.
SineTableDataType
Sine table word-length designation
Specify the sine table fixed-point data type as Same word length
as input, or Custom. This property applies when you set the
SineComputation to Table lookup. The default is Same word
length as input.
CustomSineTableDataType
Sine table word length
Specify the sine table fixed-point type as a signed, unscaled
numerictype object. This property applies when you set
the SineComputation to Table lookup and you set the
SineTableDataType property to Custom. The default is
numerictype(true,16).
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as Full precision,
Same as first input, or Custom. This property applies when
you set the SineComputation to Table lookup. The default is
Custom.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a signed, scaled
numerictype object. This property applies when you set the
SineComputation to Table lookup, and the ProductDataType
property to Custom. The default is numerictype(true,32,30).
2-482
vision.IDCT
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as Full precision,
Same as input,Same as product, Same as first input,
Custom. This property applies when you set the SineComputation
property to Table lookup. The default is Full precision.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a signed, scaled
numerictype object. This property applies when you set the
SineComputation to Table lookup, and AccumulatorDataType
property to Custom. The default is numerictype(true,32,30).
OutputDataType
Output word and fraction lengths
Specify the output fixed-point data type as Full precision, Same
as first input, or Custom. This property applies when you set
the SineComputation to Table lookup. The default is Custom.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a signed, scaled
numerictype object. This property applies when you set the
SineComputation to Table lookup, and the OutputDataType
property to Custom. The default is numerictype(true,16,15).
2-483
vision.IDCT
Examples Use 2-D discrete cosine transform (DCT) to analyze the energy content
in an image. Set the DCT coefficients lower than a threshold of 0.
Reconstruct the image using 2-D inverse discrete cosine transform
(IDCT).
hdct2d = vision.DCT;
I = double(imread('cameraman.tif'));
J = step(hdct2d, I);
imshow(log(abs(J)),[]), colormap(jet(64)), colorbar
hidct2d = vision.IDCT;
J(abs(J) < 10) = 0;
It = step(hidct2d, J);
figure, imshow(I, [0 255]), title('Original image')
figure, imshow(It,[0 255]), title('Reconstructed image')
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D IDCT block reference page. The object properties correspond
to the block parameters.
2-484
vision.IDCT.clone
Purpose Create 2-D inverse discrete cosine transform object with same property
values
Syntax C = clone(H)
Description C = clone(H) creates a IDCT System object C, with the same property
values as H. The clone method creates a new unlocked object.
2-485
vision.IDCT.getNumInputs
Syntax N = getNumInputs(H)
2-486
vision.IDCT.getNumOutputs
Syntax N = getNumOutputs(H)
2-487
vision.IDCT.isLocked
Syntax TF = isLocked(H)
2-488
vision.IDCT.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-489
vision.IDCT.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-490
vision.IFFT
• Double-signal algorithm
• Half-length algorithm
• Radix-2 decimation-in-time (DIT) algorithm
• Radix-2 decimation-in-frequency (DIF) algorithm
• An algorithm chosen by FFTW [1], [2]
Properties FFTImplemenation
FFT implementation
Specify the implementation used for the FFT as one of Auto |
Radix-2 | FFTW. When you set this property to Radix-2, the FFT
length must be a power of two.
2-491
vision.IFFT
BitReversedInput
Indicates whether input is in bit-reversed order
Set this property to true if the order of 2D FFT transformed input
elements are in bit-reversed order. The default is false, which
denotes linear ordering.
ConjugateSymmetricInput
Indicates whether input is conjugate symmetric
Set this property to true if the input is conjugate symmetric.
The 2D DFT of a real valued signal is conjugate symmetric and
setting this property to true optimizes the 2D IFFT computation
method. Setting this property to false for conjugate symmetric
inputs results in complex output values with nonzero imaginary
parts. Setting this property to true for non conjugate symmetric
inputs results in invalid outputs. This property must be false for
fixed-point inputs. The default is true.
Normalize
Divide output by FFT length
Specify if the 2D IFFT output should be divided by the FFT
length. The value of this property defaults to true and divides
each element of the output by the product of the row and column
dimensions of the input matrix.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as Ceiling, Convergent, Floor,
Nearest, Round, Simplest, or Zero. This property applies when
you set the ConjugateSymmetricInput property to false. The
default is Floor.
OverflowAction
2-492
vision.IFFT
2-493
vision.IFFT
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator data type as Full precision, Same as
input, Same as product, or Custom. This property applies when
you set the ConjugateSymmetricInput property to false. The
default is Full precision.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ConjugateSymmetricInput property to false and
the AccumulatorDataType property to Custom. The default is
numerictype([],32,30).
OutputDataType
Output word and fraction lengths
Specify the output data type as Full precision, Same as
input, or Custom. This property applies when you set the
ConjugateSymmetricInput property to false. The default is
Full precision.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when
you set the ConjugateSymmetricInput property to false
and the OutputDataType property is Custom. The default is
numerictype([],16,15).
2-494
vision.IFFT
hfft2d = vision.FFT;
hifft2d = vision.IFFT;
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D IFFT block reference page. The object properties correspond to
the Simulink block parameters.
2-495
vision.IFFT
2-496
vision.IFFT.clone
Syntax C = clone(H)
Description C = clone(H) creates an IFFT System object C, with the same property
values as H. The clone method creates a new unlocked object.
2-497
vision.IFFT.getNumInputs
Syntax getNumInputs(H)
2-498
vision.IFFT.getNumOutputs
Syntax getNumOutputs(H)
2-499
vision.IFFT.isLocked
Syntax isLocked(H)
2-500
vision.IFFT.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-501
vision.IFFT.step
Syntax Y = step(H,X)
2-502
vision.ImageComplementer
2-503
vision.ImageComplementer
himgcomp = vision.ImageComplementer;
hautoth = vision.Autothresholder;
% Read in image
I = imread('coins.png');
Algorithms This object implements the algorithm, inputs, and outputs described
on the Image Complement block reference page. The object properties
correspond to the block parameters.
2-504
vision.ImageComplementer.clone
Syntax C = clone(H)
2-505
vision.ImageComplementer.getNumInputs
Syntax N = getNumInputs(H)
2-506
vision.ImageComplementer.getNumOutputs
Syntax N = getNumOutputs(H)
2-507
vision.ImageComplementer.isLocked
Syntax TF = isLocked(H)
2-508
vision.ImageComplementer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-509
vision.ImageComplementer.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-510
vision.ImageDataTypeConverter
Purpose Convert and scale input image to specified output data type
Properties OutputDataType
Data type of output
Specify the data type of the output signal as one of double |
single | int8 | uint8 | int16 | uint16 | boolean | Custom.
The default is single.
2-511
vision.ImageDataTypeConverter
Fixed-Point Properties
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a signed or unsigned,
scaled numerictype object. This property applies when you
set the OutputDataType property to Custom. The default is
numerictype([],16,0).
x = imread('pout.tif');
hidtypeconv = vision.ImageDataTypeConverter;
y = step(hidtypeconv, x);
imshow(y);
whos y % Image has been converted from uint8 to single.
Algorithms This object implements the algorithm, inputs, and outputs described
on the Image Data Type Conversion block reference page. The object
properties correspond to the block parameters.
2-512
vision.ImageDataTypeConverter
2-513
vision.ImageDataTypeConverter.clone
Purpose Create image data type converter object with same property values
Syntax C = clone(H)
2-514
vision.ImageDataTypeConverter.getNumInputs
Syntax N = getNumInputs(H)
2-515
vision.ImageDataTypeConverter.getNumOutputs
Syntax N = getNumOutputs(H)
2-516
vision.ImageDataTypeConverter.isLocked
Syntax TF = isLocked(H)
2-517
vision.ImageDataTypeConverter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-518
vision.ImageDataTypeConverter.step
Syntax Y = step(H,X)
Description Y = step(H,X) converts the data type of the input image X. You can set
the data type of the converted output image Y with the OutputDataType
property.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-519
vision.ImageFilter
Description The ImageFilter object performs 2-D FIR filtering of input matrix.
Properties SeparableCoefficients
Set to true if filter coefficients are separable
Using separable filter coefficients reduces the amount of
calculations the object must perform to compute the output.
The function isfilterseparable can be used to check filter
separability. The default is false.
CoefficientsSource
Source of filter coefficients
Indicate how to specify the filter coefficients as one of Property |
Input port. The default is Property.
Coefficients
Filter coefficients
2-520
vision.ImageFilter
2-521
vision.ImageFilter
2-522
vision.ImageFilter
Specify the method by which the object filters the input matrix as
one of Convolution | Correlation. The default is Convolution.
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling| Convergent|
Floor| Nearest| Round| Simplest| Zero. The default is Floor.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap| Saturate. The default
is Wrap.
CoefficientsDataType
Coefficients word and fraction lengths
Specify the coefficients fixed-point data type as one of Same word
length as input| Custom. This property applies when you set
the CoefficientsSource property to Property. The default is
Custom.
CustomCoefficientsDataType
Coefficients word and fraction lengths
Specify the coefficients fixed-point type as a signed or unsigned
numerictype object. This property applies when you set
the CoefficientsSource property to Property and the
CoefficientsDataType property to Custom. The default is
numerictype([],16).
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as one of Same as
input| Custom. The default is Custom
2-523
vision.ImageFilter
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as an auto-signed, scaled
numerictype object. This property applies when you set
the ProductDataType property to Custom. The default is
numerictype([],32,10).
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as one of Same
as product| Same as input| Custom. The default is Same as
product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as an auto-signed,
scaled numerictype object. This property applies when you set
the AccumulatorDataType property to Custom. The default is
numerictype([],32,10).
OutputDataType
Output word and fraction lengths
Specify the output fixed-point data type as one of Same as input|
Custom. The default is Same as input.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype. This
property applies when you set the OutputDataType property to
Custom. The default is numerictype([],32,12).
2-524
vision.ImageFilter
img = im2single(rgb2gray(imread('peppers.png')));
hfir2d = vision.ImageFilter;
hfir2d.Coefficients = [1 0; 0 -.5];
fImg = step(hfir2d, img);
subplot(2,1,1);imshow(img);title('Original image')
subplot(2,1,2);imshow(fImg);title('Filtered image')
Algorithms This object implements the algorithm, inputs, and outputs described
on the 2-D FIR Filter block reference page. The object properties
correspond to the block parameters.
2-525
vision.ImageFilter.clone
Syntax C = clone(H)
2-526
vision.ImageFilter.getNumInputs
Syntax N = getNumInputs(H)
2-527
vision.ImageFilter.getNumOutputs
Syntax N = getNumOutputs(H)
2-528
vision.ImageFilter.isLocked
Syntax TF = isLocked(H)
2-529
vision.ImageFilter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-530
vision.ImageFilter.step
Syntax Y = step(H,I)
Y = step(H,I,COEFFS)
Y = step(H,I,HV,HH)
Y = step(H,...,PVAL)
Description Y = step(H,I) filters the input image I and returns the filtered image
Y.
Y = step(H,I,COEFFS) uses filter coefficients, COEFFS, to filter the
input image. This applies when you set the CoefficientsSource
property to Input port and the SeparableCoefficients property to
false.
Y = step(H,I,HV,HH) uses vertical filter coefficients, HV , and
horizontal coefficients, HH, to filter the input image. This applies when
you set the CoefficientsSource property to Input port and the
SeparableCoefficients property to true.
Y = step(H,...,PVAL) uses the input pad value PVAL to filter the
input image I. This applies when you set the OutputSize property to
either Full or Same as first input, the PaddingMethod property to
Constant, and the PaddingValueSource property to Input port.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-531
integralKernel
Description This object describes box filters to use with integral images.
Input Arguments
BBOX
M-by-4 matrix of bounding boxes. Each of the M number of
4-element row vectors [x y width height] define a bounding box.
The first two elements represent the coordinates of the upper-left
corner of the bounding box. The second two elements represent
the width and height of the bounding box.
WEIGHTS
M length vector of weights corresponding to the bounding boxes.
BoundingBoxes
2-532
integralKernel
Center
Center coordinates of the filter.
Size
Filter size.
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Use the format [x y width height] for the two bounding boxes.
2-533
integralKernel
% Note that this same filter could have been defined as:
% integralKernel([1,1,5,3;1,4,5,3;1,7,5,3], [1, -2, 1]);
% but it would be less efficient since it requires 3 bounding boxes.
References Viola, Paul and Michael J. Jones, “Rapid Object Detection using
a Boosted Cascade of Simple Features”, Proceedings of the 2001
IEEE Computer Society Conference on Computer Vision and Pattern
Recognition, 2001. Volume: 1, pp. 511–518.
2-534
integralKernel
2-535
integralKernel.transpose
2-536
vision.ImagePadder
Purpose Pad or crop input image along its rows, columns, or both
Description The ImagePadder object pads or crop input image along its rows,
columns, or both.
Properties Method
How to pad input image
Specify how to pad the input image as Constant | Replicate |
Symmetric | Circular. The default is Constant.
PaddingValueSource
How to specify pad value
Indicate how to specify the pad value as either Property | Input
port. This property applies when you set the Method property to
Constant. The default is Property.
PaddingValue
Pad value
2-537
vision.ImagePadder
Specify the constant scalar value with which to pad the image.
This property applies when you set the Method property to
Constant and the PaddingValueSource property to Property.
The default is 0. This property is tunable.
SizeMethod
How to specify output image size
Indicate how to pad the input image to obtain the output image
by specifying Pad size | Output size. When this property is
Pad size, the size of the padding in the vertical and horizontal
directions are specified. When this property is Output size, the
total number of output rows and output columns are specified.
The default is Pad size.
RowPaddingLocation
Location at which to add rows
Specify the direction in which to add rows to as Top | Bottom |
Both top and bottom | None. Set this property to Top to add
additional rows to the top of the image, Bottom to add additional
rows to the bottom of the image, Both top and bottom to add
additional rows to the top and bottom of the image, and None to
maintain the row size of the input image. The default is Both
top and bottom.
NumPaddingRows
Number of rows to add
Specify the number of rows to be added to the top, bottom,
or both sides of the input image as a scalar value. When the
RowPaddingLocation property is Both top and bottom, this
property can also be set to a two element vector, where the first
element controls the number of rows the System object adds to
the top of the image and the second element controls the number
of rows the System object adds to the bottom of the image. This
property applies when you set the SizeMethod property to Pad
2-538
vision.ImagePadder
2-539
vision.ImagePadder
property can also be set to a two element vector, where the first
element controls the number of columns the System object adds
to the left side of the image and the second element controls the
number of columns the System object adds to the right side of
the image. This property applies when you set the SizeMethod
property to Pad size and the NumPaddingColumns property is not
set to None. The default is 2.
NumOutputColumnsSource
How to specify number of output columns
Indicate how to specify the number of output columns as Property
| Next power of two. If you set this property to Next power
of two, the System object adds columns to the input until the
number of columns is equal to a power of two. This property
applies when you set the SizeMethod property to Output size.
The default is Property.
NumOutputColumns
Total number of columns in output
Specify the total number of columns in the output as a scalar
integer. If the specified number is smaller than the number of
columns of the input image, then image is cropped. This property
applies when you set the SizeMethod property to Output size
and the NumOutputColumnsSource property to Property. The
default is 10.
2-540
vision.ImagePadder
Examples Pad two rows to the bottom, and three columns to the right of an image.
Use the value of the last array element as the padding value.
Algorithms This object implements the algorithm, inputs, and outputs described on
the Image Pad block reference page. The object properties correspond
to the block parameters.
2-541
vision.ImagePadder.clone
Syntax C = clone(H)
2-542
vision.ImagePadder.getNumInputs
Syntax N = getNumInputs(H)
2-543
vision.ImagePadder.getNumOutputs
Syntax N = getNumOutputs(H)
2-544
vision.ImagePadder.isLocked
Syntax TF = isLocked(H)
2-545
vision.ImagePadder.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-546
vision.ImagePadder.step
Syntax Y = step(H,X)
Y = step(H,X,PAD)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-547
vision.KalmanFilter
Description The Kalman filter object is designed for tracking. You can use it to
predict a physical object’s future location, to reduce noise in the detected
location, or to help associate multiple physical objects with their
corresponding tracks. A Kalman filter object can be configured for each
physical object for multiple object tracking. To use the Kalman filter,
the object must be moving at constant velocity or constant acceleration.
The Kalman filter algorithm involves two steps, prediction and
correction (also known as the update step). The first step uses previous
states to predict the current state. The second step uses the current
measurement, such as object location, to correct the state. The Kalman
filter implements a discrete time, linear State-Space System.
Note To make configuring a Kalman filter easier, you can use the
configureKalmanFilter object to configure a Kalman filter. It sets
up the filter for tracking a physical object in a Cartesian coordinate
system, moving with constant velocity or constant acceleration. The
statistics are the same along all dimensions. If you need to configure a
Kalman filter with different assumptions, do not use the function, use
this object directly.
Variable Value
A [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1]
H [1 0 0 0; 0 1 0 0]
obj =
vision.KalmanFilter(StateTransitionModel,MeasurementModel)
2-548
vision.KalmanFilter
To Track Objects:
Use the predict and correct methods based on detection results.
[...] = predict(obj);
[...] = correct(obj,measurement);
• When the tracked object is not detected, call the predict method,
but not the correct method. When the tracked object is missing or
occluded, no measurement is available. Set the methods up with
the following logic:
[...] = predict(obj);
If measurement exists
[...] = correct(obj,measurement);
end
2-549
vision.KalmanFilter
[...] = predict(obj,t);
[...] = correct(obj,measurement);
If t=1, predict(obj,t) is the same as predict(obj).
Use the distance method to find the best matches. The computed
distance values describe how a set of measurements matches the
Kalman filter. You can thus select a measurement that best fits
the filter. This strategy can be used for matching object detections
against object tracks in a multiobject tracking problem. This distance
computation takes into account the covariance of the predicted state
and the process noise. The distance method can only be called after
the predict method.
Distance Equation
1
d( z) ( z Hx)T ( z Hx) ln
2-550
vision.KalmanFilter
State equation:
x(k) Ax(k 1) Bu(k 1) w(k 1)
Measurement
equation: z(k) Hx(k) v(k)
Variable Definition
Description
Variable Dimension
k Time. Scalar
x State. Gaussian vector with covariance M-element vector
P. [ x ~ N ( x, P) ]
P State estimation error covariance. M-by-M matrix
A State transition model. M-by-M matrix
B Control model. M-by-L matrix
u Control input. L-element vector
w Process noise; Guassian vector M-element vector
with zero mean and covariance Q.
[ w ~ N (0, Q) ]
Q Process noise covariance. M-by-M matrix
z Measurement. For example, location N-element vector
of detected object.
H Measurement model. N-by-M matrix
2-551
vision.KalmanFilter
Description
Variable Dimension
Properties StateTransitionModel
Model describing state transition between time steps (A)
Specify the transition of state between times as an M-by-M
matrix. After the object is constructed, this property cannot
be changed. This property relates to the A variable in the
“State-Space System” on page 2-551.
Default: [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1]
MeasurementModel
Model describing state to measurement transformation (H)
Specify the transition from state to measurement as an N-by-M
matrix. After the object is constructed, this property cannot
be changed. This property relates to the H variable in the
“State-Space System” on page 2-551.
Default: [1 0 0 0; 0 1 0 0]
ControlModel
Model describing control input to state transformation (B)
Specify the transition from control input to state as an M-by-L
matrix. After the object is constructed, this property cannot
be changed. This property relates to the B variable in the
“State-Space System” on page 2-551.
2-552
vision.KalmanFilter
Default: []
State
State (x)
Specify the state as a scalar or an M-element vector. If you specify
it as a scalar it will be extended to an M-element vector. This
property relates to the x variable in the “State-Space System”
on page 2-551.
Default: [0]
StateCovariance
State estimation error covariance (P)
Specify the covariance of the state estimation error as a scalar or
an M-by-M matrix. If you specify it as a scalar it will be extended
to an M-by-M diagonal matrix. This property relates to the P
variable in the “State-Space System” on page 2-551.
Default: [1]
ProcessNoise
Process noise covariance (Q)
Specify the covariance of process noise as a scalar or an M-by-M
matrix. If you specify it as a scalar it will be extended to an
M-by-M diagonal matrix. This property relates to the Q variable
in the “State-Space System” on page 2-551.
Default: [1]
MeasurementNoise
Measurement noise covariance (R)
Specify the covariance of measurement noise as a scalar or an
N-by-N matrix. If you specify it as a scalar it will be extended
2-553
vision.KalmanFilter
Default: [1]
detectedLocations{1} = [];
for idx = 16: 25
detectedLocations{idx} = [];
end
2-554
vision.KalmanFilter
xlabel('Time');
xlim([0,length(detectedLocation)]);
Create a 1-D, constant speed Kalman filter when the physical object
is first detected. Predict the location of the object based on previous
states. If the object is detected at the current time step, use its location
to correct the states.
kalman = [];
for idx = 1: length(detectedLocations)
location = detectedLocations{idx};
if isempty(kalman)
if ~isempty(location)
stateModel = [1 1; 0 1];
measurementModel = [1 0];
kalman = vision.KalmanFilter(stateModel, measurementModel, ...
'ProcessNoise', 1e-4, 'MeasurementNoise', 4);
kalman.State = [location, 0];
end
else
trackedLocation = predict(kalman);
if ~isempty(location)
plot(idx, location, 'k+');
d = distance(kalman, location);
title(sprintf('Distance: %f', d));
trackedLocation = correct(kalman, location);
else
title('Missing detection');
end
pause(0.2);
plot(idx, trackedLocation, 'ro');
end
end
legend('Detected locations', 'Predicted/corrected locations');
2-555
vision.KalmanFilter
x = 1;
len = 100;
z = x + 0.1 * randn(1, len);
Remove noise from the signal by using a Kalman filter. The state is
expected to be constant, and the measurement is the same as state.
stateTransitionModel = 1;
measurementModel = 1;
obj = vision.KalmanFilter(stateTransitionModel,measurementModel,'StateCov
Plot results
References Welch, Greg, and Gary Bishop, An Introduction to the Kalman Filter,
TR 95–041. University of North Carolina at Chapel Hill, Department of
Computer Science.
2-556
vision.KalmanFilter
2-557
vision.KalmanFilter.clone
Syntax C = clone(H)
2-558
vision.KalmanFilter.distance
2-559
vision.KalmanFilter.correct
2-560
vision.KalmanFilter.predict
2-561
vision.LocalMaximaFinder
2-562
vision.LocalMaximaFinder
Properties MaximumNumLocalMaxima
Maximum number of maxima to find
Specify the maximum number of maxima to find as a positive
scalar integer value. The default is 2.
NeighborhoodSize
Neighborhood size for zero-ing out values
Specify the size of the neighborhood around the maxima, over
which the System object zeros out values, as a 2-element vector of
positive odd integers. The default is [5 7].
ThresholdSource
Source of threshold
Specify how to enter the threshold value as Property, or Input
port. The default is Property.
Threshold
Value that all maxima should match or exceed
Specify the threshold value as a scalar of MATLAB built-in
numeric data type. This property applies when you set the
ThresholdSource property to Property. The default is 10. This
property is tunable.
HoughMatrixInput
Indicator of Hough Transform matrix input
Set this property to true if the input is antisymmetric about the
rho axis and the theta value ranges from − to radians, which
correspond to a Hough matrix. 2 2
When you set this property to true, the object assumes a Hough
matrix input . The block applies additional processing, specific to
Hough transform on the right and left boundaries of the input
matrix.
2-563
vision.LocalMaximaFinder
I = [0 0 0 0 0 0 0 0 0 0 0 0; ...
0 0 0 1 1 2 3 2 1 1 0 0; ...
0 0 0 1 2 3 4 3 2 1 0 0; ...
0 0 0 1 3 5 7 5 3 1 0 0; ... % local max at x=7, y=4
0 0 0 1 2 3 4 3 2 1 0 0; ...
0 0 0 1 1 2 3 2 1 1 0 0; ...
0 0 0 0 0 0 0 0 0 0 0 0];
hLocalMax = vision.LocalMaximaFinder;
hLocalMax.MaximumNumLocalMaxima = 1;
hLocalMax.NeighborhoodSize = [3 3];
hLocalMax.Threshold = 1;
2-564
vision.LocalMaximaFinder
location = step(hLocalMax, I)
Algorithms This object implements the algorithm, inputs, and outputs described
on the Find Local Maxima block reference page. The object properties
correspond to the block parameters.
2-565
vision.LocalMaximaFinder.clone
Purpose Create local maxima finder object with same property values
Syntax C = clone(H)
2-566
vision.LocalMaximaFinder.getNumInputs
Syntax N = getNumInputs(H)
2-567
vision.LocalMaximaFinder.getNumOutputs
Syntax N = getNumOutputs(H)
2-568
vision.LocalMaximaFinder.isLocked
Syntax TF = isLocked(H)
2-569
vision.LocalMaximaFinder.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-570
vision.LocalMaximaFinder.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-571
vision.MarkerInserter
Description The MarkerInserter object can draw circle, x-mark, plus sign, star, or
rectangle markers in a 2-D grayscale or truecolor RGB image. The
output image can then be displayed or saved to a file.
To insert a marker:
2 Call the step method with the input image, I, the marker inserter
object, markerInserter, points PTS, and any optional properties. See
the syntax below for using the step method.
2-572
vision.MarkerInserter
Properties Shape
Shape of marker
Specify the type of marker to draw as Circle | X-mark | Plus,
Star | Square.
Default: Circle
Size
Size of marker
Specify the size of the marker, in pixels, as a scalar value greater
than or equal to 1. This property is tunable.
Default: 3
Fill
Enable marker fill
Set this property to true to fill the marker with an intensity value
or a color. This property applies when you set the Shape property
to Circle or Square.
Default: false
BorderColorSource
Border color source
Specify how the marker’s border color is provided as Input port,
Property. This property applies either when you set the Shape
property to X-mark, Plus, or Star, or when you set the Shape
2-573
vision.MarkerInserter
2-574
vision.MarkerInserter
Default: Property
FillColor
Fill color of marker
Specify the color to fill the marker as Black | White | Custom. If
this property is set to Custom, the CustomFillColor property
is used to specify the value. This property applies when the
FillColorSource property is enabled and set to Property.
Default: Black
CustomFillColor
Intensity or color value for marker’s interior
Specify an intensity or color value to fill the marker. If the input
is an intensity image, this property can be set to a scalar intensity
value for one marker or R-element vector where R is the number
of markers. If the input is a color image, this property can be set
to a P-element vector where P is the number of color planes or a
P-by-R matrix where P is the number of color planes and R is
the number of markers. This property applies when you set the
FillColor property to Custom. This property is tunable when the
Antialiasing property is false.
Default: [200 120 50]
Opacity
Opacity of shading inside marker
Specify the opacity of the shading inside the marker by a scalar
value between 0 and 1, where 0 is transparent and 1 is opaque.
This property applies when you set the Fill property to true.
This property is tunable.
Default: 0.6
ROIInputPort
Enable defining a region of interest to draw marker
2-575
vision.MarkerInserter
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as Ceiling | Convergent | Floor
| Nearest | Round | Simplest | Zero. This property applies
when you set the Fill property to true and/or the Antialiasing
property to true.
Default: Floor
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap | Saturate. This property
applies when you set the Fill property to true and/or the
Antialiasing property to true.
Default: Wrap
OpacityDataType
Opacity word length
2-576
vision.MarkerInserter
2-577
vision.MarkerInserter
when you set the Fill property to true and/or the Antialiasing
property to true.
Default: Same as product
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the Fill property to true and/or the Antialiasing property
to true, and the AccumulatorDataType property to Custom.
Default: numerictype([],32,14)
markerInserter = vision.MarkerInserter('Shape','Plus','BorderColor','whit
I = imread('cameraman.tif');
Pts = int32([10 10; 20 20; 30 30]);
J = step(markerInserter, I, Pts);
imshow(J);
2-578
vision.MarkerInserter
markerInserter = vision.MarkerInserter('Shape','X-mark','BorderColor',
RGB = imread('autumn.tif');
Pts = int32([20 20; 40 40; 60 60]);
J = step(markerInserter, RGB, Pts);
imshow(J);
2-579
vision.MarkerInserter.clone
Syntax C = clone(H)
2-580
vision.MarkerInserter.getNumInputs
Syntax N = getNumInputs(H)
2-581
vision.MarkerInserter.getNumOutputs
Syntax N = getNumOutputs(H)
2-582
vision.MarkerInserter.isLocked
Syntax TF = isLocked(H)
2-583
vision.MarkerInserter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-584
vision.MarkerInserter.step
Syntax J = step(markerInserter,I,PTS)
J = step(markerInserter,I,PTS,ROI)
J = step(markerInserter,I,PTS,...,CLR)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
Input Arguments
H
Shape inserter object with shape and properties specified.
2-585
vision.MarkerInserter.step
I
Input image.
PTS
Input M-by-2 matrix of M number of [x y] coordinates describing
the location for markers. This property must be an integer value.
If you enter non-integer value, the object rounds it to the nearest
integer.
x1 y1
x y2
2
xM yM
RGB
Scalar, vector, or matrix describing one plane of the RGB input
video stream.
ROI
Input 4-element vector of integers [x y width height], that define
a rectangular area in which to draw the shapes. The first two
elements represent the one-based coordinates of the upper-left
2-586
vision.MarkerInserter.step
corner of the area. The second two elements represent the width
and height of the area.
CLR
This port can be used to dynamically specify shape color.
P-element vector or an M-by-P matrix, where M is the number of
shapes, and P, the number of color planes. You can specify a color
(RGB), for each shape, or specify one color for all shapes. The data
type for the CLR input must be the same as the input image.
Output Arguments
J
Output image. The markers are embedded on the output image.
2-587
vision.Maximum
Properties ValueOutputPort
Output maximum value
Set this property to true to output the maximum value of the
input. This property applies when you set the RunningMaximum
property to false.
Default:true.
RunningMaximum
Calculate over single input or multiple inputs
When you set this property to true, the object computes the
maximum value over a sequence of inputs. When you set this
property to false, the object computes the maximum value over
the current input.
Default: false.
2-588
vision.Maximum
IndexOutputPort
Output the index of the maximum value
Set this property to true to output the index of the maximum
value of the input. This property applies only when you set the
RunningMaximum property to false.
Default:true.
ResetInputPort
Additional input to enable resetting of running maximum
Set this property to true to enable resetting of the running
maximum. When you set this property to true, a reset input must
be specified to the step method to reset the running maximum.
This property applies only when you set the RunningMaximum
property to true.
Default: false.
ResetCondition
Condition that triggers resetting of running maximum
Specify the event that resets the running maximum as Rising
edge, Falling edge, Either edge, or Non-zero. This property
applies only when you set the ResetInputPort property to true.
Default: Non-zero.
IndexBase
Numbering base for index of maximum value
Specify the numbering used when computing the index of the
maximum value as starting from either One or Zero. This property
applies only when you set the IndexOutputPort property to true.
Default: One.
Dimension
Dimension to operate along
2-589
vision.Maximum
2-590
vision.Maximum
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent |
Floor | Nearest | Round | Simplest | Zero.
Default: Floor.
OverflowAction
Action to take when integer input is out-of-range
2-591
vision.Maximum
2-592
vision.Maximum
Examples Determine the maximum value and its index in a grayscale image.
img = im2single(rgb2gray(imread('peppers.png')));
hmax = vision.Maximum;
[m, ind] = step(hmax, img);
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D Maximum block reference page.
2-593
vision.Maximum.clone
Syntax C = clone(H)
2-594
vision.Maximum.getNumInputs
Syntax N = getNumInputs(H)
2-595
vision.Maximum.getNumOutputs
Syntax N = getNumOutputs(H)
2-596
vision.Maximum.isLocked
Syntax TF = isLocked(H)
2-597
vision.Maximum.reset
Syntax reset(H)
Description reset(H) resets the computation of the running maximum for the
Maximum object H.
2-598
vision.Maximum.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-599
vision.Maximum.step
Description [VAL,IND] = step(H,X) returns the maximum value, VAL, and the
index or position of the maximum value, IND, along a dimension of X
specified by the value of the Dimension property.
VAL = step(H,X) returns the maximum value, VAL, of the input X.
When the RunningMaximum property is true, VAL corresponds to the
maximum value over a sequence of inputs.
IND = step(H,X) returns the zero- or one-based index IND of
the maximum value. To enable this type of processing, set the
IndexOutputPort property to true and the ValueOutputPort and
RunningMaximum properties to false.
VAL = step(H,X,R) computes the maximum value, VAL, over a
sequence of inputs, and resets the state of H based on the value of
reset signal, R, and the ResetCondition property. To enable this
type of processing, set the RunningMaximum property to true and the
ResetInputPort property to true.
[...] = step(H,I,ROI) computes the maximum of an input image,
I, within the given region of interest, ROI. To enable this type of
processing, set the ROIProcessing property to true and the ROIForm
property to Lines, Rectangles or Binary mask.
[...] = step(H,I,LABEL,LABELNUMBERS) computes the maximum of
an input image, I, for a region whose labels are specified in the vector
LABELNUMBERS. To enable this type of processing, set the ROIProcessing
property to true and the ROIForm property to Label matrix.
2-600
vision.Maximum.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-601
vision.Mean
Description The Mean object finds the mean of an input or sequence of inputs.
Properties RunningMean
Calculate over single input or multiple inputs
When you set this property to true, the object calculates the
mean over a sequence of inputs. When you set this property to
false, the object computes the mean over the current input. The
default is false.
ResetInputPort
Additional input to enable resetting of running mean
Set this property to true to enable resetting of the running
mean. When you set this property to true, a reset input must be
specified to the step method to reset the running mean. This
property applies only when you set the RunningMean property
to true. The default is false.
ResetCondition
Condition that triggers resetting of running mean
2-602
vision.Mean
Specify the event that resets the running mean as Rising edge,
Falling edge, Either edge, or Non-zero. This property applies
only when you set the ResetInputPort property to true. The
default is Non-zero.
Dimension
Dimension to operate along
Specify how the mean calculation is performed over the data as
All, Row, Column, or Custom. This property applies only when you
set the RunningMean property to false. The default is All.
CustomDimension
Numerical dimension to calculate over
Specify the integer dimension, indexed from one, of the input
signal over which the object calculates the mean. The value of this
property cannot exceed the number of dimensions in the input
signal. This property only applies when you set the Dimension
property to Custom. The default is 1.
ROIProcessing
Enable region-of-interest processing
Set this property to true to enable calculation of the mean within
a particular region of an image. This property applies when you
set the Dimension property to All and the RunningMean property
to false. The default is false.
ROIForm
Type of region of interest
Specify the type of region of interest as Rectangles, Lines, Label
matrix, or Binary mask. This property applies only when you set
the ROIProcessing property to true. The default is Rectangles.
ROIPortion
Calculate over entire ROI or just perimeter
2-603
vision.Mean
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Action to take when integer input is out-of-range
2-604
vision.Mean
2-605
vision.Mean
img = im2single(rgb2gray(imread('peppers.png')));
hmean = vision.Mean;
m = step(hmean,img);
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D Mean block reference page.
2-606
vision.Mean.clone
Syntax C = clone(H)
Description C = clone(H) creates a Mean object C, with the same property values as
H. The clone method creates a new unlocked object with uninitialized
states.
2-607
vision.Mean.getNumInputs
Syntax N = getNumInputs(H)
2-608
vision.Mean.getNumOutputs
Syntax N = getNumOutputs(H)
2-609
vision.Mean.isLocked
Syntax TF = isLocked(H)
2-610
vision.Mean.reset
Syntax reset(H)
Description reset(H) resets the computation of the running mean for the Mean
object H.
2-611
vision.Mean.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-612
vision.Mean.step
Syntax Y = step(H,X)
Y = step(H,X,R)
Y = step(H,X,ROI)
Y = step(H,X,LABEL,LABELNUMBERS)
[Y,FLAG] = step(H,X,ROI)
[Y,FLAG] = step(H,X,LABEL,LABELNUMBERS)
2-613
vision.Mean.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-614
vision.Median
Properties SortMethod
Sort method
Specify the sort method used for calculating the median as Quick
sort or Insertion sort.
Dimension
Dimension with which to operate along
Specify how the calculation is performed over the data as All,
Row, Column, or Custom. The default is All
CustomDimension
Numerical dimension over which to calculate
Specify the integer dimension of the input signal over which the
object calculates the mean. The value of this property cannot
exceed the number of dimensions in the input signal. This
2-615
vision.Median
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor.
OverflowAction
Action to take when integer input is out-of-range
Specify the overflow action as Wrap or Saturate. The default is
Wrap.
ProductDataType
Product output word and fraction lengths
Specify the product output fixed-point data type as Same as
input or Custom. The default is Same as input.
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object. This property applies when you set the ProductDataType
property to Custom. The default is numerictype(true,32,30).
AccumulatorDataType
Data type of accumulator
Specify the accumulator fixed-point data type as Same as input,
or Custom. The default is Same as input.
CustomAccumulatorDataType
Accumulator word and fraction lengths
2-616
vision.Median
img = im2single(rgb2gray(imread('peppers.png')));
hmdn = vision.Median;
2-617
vision.Median
med = step(hmdn,img);
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D Median block reference page. The object properties correspond
to the block parameters.
2-618
vision.Median.clone
Syntax C = clone(H)
2-619
vision.Median.getNumInputs
Syntax N = getNumInputs(H)
2-620
vision.Median.getNumOutputs
Syntax N = getNumOutputs(H)
2-621
vision.Median.isLocked
Syntax TF = isLocked(H)
2-622
vision.Median.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-623
vision.Median.step
Syntax Y = step(H,X)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-624
vision.MedianFilter
Properties NeighborhoodSize
Size of neighborhood to compute the median
Specify the size of the neighborhood over which the median filter
computes the median. When you set this property to a positive
integer, the integer represents the number of rows and columns
in a square matrix. When you set this property to a two-element
vector, the vector represents the number of rows and columns
in a rectangular matrix. The median filter does not support
fixed-point properties when both neighborhood dimensions are
odd. The default is [3 3].
OutputSize
Output matrix size
2-625
vision.MedianFilter
2-626
vision.MedianFilter
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. The default is
Floor. This property applies only when the NeighborhoodSize
property corresponds to even neighborhood options.
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as one of Wrap | Saturate. The default
is Wrap. This property is applies only when the NeighborhoodSize
property corresponds to even neighborhood options.
AccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point data type as one of Same as
input | Custom. The default is Same as input. This property
applies only when the NeighborhoodSize property corresponds
to even neighborhood options.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies only
when the AccumulatorDataType property is Custom and the
NeighborhoodSize property corresponds to even neighborhood
options. The default is numerictype([],32,30).
2-627
vision.MedianFilter
OutputDataType
Output word and fraction lengths
Specify the output fixed-point data type as Same as inputor
Custom. This property applies only when the NeighborhoodSize
property corresponds to even neighborhood options. The default
is Same as input.
CustomOutputDataType
Output word and fraction lengths
Specify the output fixed-point type as a scaled numerictype object
with a Signedness of Auto. This property applies only when the
OutputDataType property is Custom and the NeighborhoodSize
property corresponds to even neighborhood options. The default is
numerictype([],16,15).
2-628
vision.MedianFilter
I = imread('pout.tif');
I = imnoise(I, 'salt & pepper')
Algorithms This object implements the algorithm, inputs, and outputs described
on the Median Filter block reference page. The object properties
correspond to the block parameters.
2-629
vision.MedianFilter.clone
Syntax C = clone(H)
2-630
vision.MedianFilter.getNumInputs
Syntax N = getNumInputs(H)
2-631
vision.MedianFilter.getNumOutputs
Syntax N = getNumOutputs(H)
2-632
vision.MedianFilter.isLocked
Syntax TF = isLocked(H)
2-633
vision.MedianFilter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-634
vision.MedianFilter.step
Syntax I2 = step(H,I1)
I2 = step(H,I1,PVAL)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-635
vision.Minimum
Properties ValueOutputPort
Output minimum value
Set this property to true to output the minimum value of the
input. This property applies when you set the RunningMinimum
property to false.
Default: true
RunningMinimum
Calculate over single input or multiple inputs
When you set this property to true, the object computes the
minimum value over a sequence of inputs. When you set this
property to false, the object computes the minimum value over
the current input.
Default: false
2-636
vision.Minimum
IndexOutputPort
Output the index of the minimum value
Set this property to true to output the index of the minimum
value of the input. This property applies only when you set the
RunningMinimum property to false.
Default: true
ResetInputPort
Additional input to enable resetting of running minimum
Set this property to true to enable resetting of the running
minimum. When you set this property to true, a reset input must
be specified to the step method to reset the running minimum.
This property applies only when you set the RunningMinimum
property to true.
Default: false
ResetCondition
Condition that triggers resetting of running minimum
Specify the event that resets the running minimum as Rising
edge, Falling edge, Either edge, or Non-zero. This property
applies only when you set the ResetInputPort property to true.
Default: Non-zero
Dimension
Dimension to operate along
Specify how the minimum calculation is performed over the data
as All, Row, Column, or Custom. This property applies only when
you set the RunningMinimum property to false.
Default:Column.
CustomDimension
Numerical dimension to calculate over
2-637
vision.Minimum
Specify the integer dimension of the input signal over which the
object finds the minimum. The value of this property cannot
exceed the number of dimensions in the input signal. This
property only applies when you set the Dimension property to
Custom.
Default:1.
ROIProcessing
Enable region-of-interest processing
Set this property to true to enable calculation of the minimum
value within a particular region of an image. This property
applies when you set the Dimension property to All and the
RunningMinimum property to false.
Default: false.
ROIForm
Type of region of interest
Specify the type of region of interest as Rectangles, Lines, Label
matrix, or Binary mask. This property applies only when you set
the ROIProcessing property to true.
Default: Rectangles.
ROIPortion
Calculate over entire ROI or just perimeter
Specify whether to calculate the minimum over the Entire ROI
or the ROI perimeter. This property applies only when you set
the ROIForm property to Rectangles.
Default: Entire ROI.
ROIStatistics
Calculate statistics for each ROI or one for all ROIs
Specify whether to calculate Individual statistics for each
ROI or a Single statistic for all ROIs. This property applies
2-638
vision.Minimum
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent |
Floor | Nearest | Round | Simplest | Zero.
Default: Floor.
OverflowAction
Action to take when integer input is out-of-range
Specify the overflow action as Wrap or Saturate.
Default: Wrap.
ProductDataType
Data type of product
Specify the product fixed-point data type as Same as input or
Custom.
Default:Same as input.
2-639
vision.Minimum
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object. This property applies only when you set the
AccumulatorDataType property to Custom.
Default:numerictype(true,32,30).
AccumulatorDataType
Data type of accumulator
Specify the accumulator fixed-point data type as Same as
product, Same as input, or Custom.
Default: Same as product.
CustomAccumulatorDataType
Accumulator word and fraction lengths
Specify the accumulator fixed-point type as a scaled
numerictype object. This property applies only when you set the
AccumulatorDataType property to Custom.
Default:numerictype(true,32,30).
2-640
vision.Minimum
Examples Determine the minimum value and its index in a grayscale image.
img = im2single(rgb2gray(imread('peppers.png')));
hmax = vision.Minimum;
[m, ind] = step(hmax, img);
Algorithms This object implements the algorithm, inputs, and outputs described on
the 2-D Minimum block reference page.
2-641
vision.Minimum.clone
Syntax C = clone(H)
2-642
vision.Minimum.getNumInputs
Syntax N = getNumInputs(H)
2-643
vision.Minimum.getNumOutputs
Syntax N = getNumOutputs(H)
2-644
vision.Minimum.isLocked
Syntax TF = isLocked(H)
2-645
vision.Minimum.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-646
vision.Minimum.reset
Syntax reset(H)
Description reset(H) resets computation of the running minimum for the Minimum
object H.
2-647
vision.Minimum.step
Description [VAL,IND] = step(H,X) returns the minimum value, VAL, and the
index or position of the minimum value, IND, along a dimension of X
specified by the value of the Dimension property.
VAL = step(H,X) returns the minimum value, VAL, of the input X.
When the RunningMinimum property is true, VAL corresponds to the
minimum value over a sequence of inputs.
IND = step(H,X) returns the zero- or one-based index IND of
the minimum value. To enable this type of processing, set the
IndexOutputPort property to true and the ValueOutputPort and
RunningMinimum properties to false.
VAL = step(H,X,R) computes the minimum value, VAL, over a sequence
of inputs, and resets the state of H based on the value of reset signal, R,
and the ResetCondition property. To enable this type of processing,
set the RunningMinimum property to true and the ResetInputPort
property to true.
[...] = step(H,I,ROI) computes the minimum of an input image,
I, within the given region of interest, ROI. To enable this type of
processing, set the ROIProcessing property to true and the ROIForm
property to Lines, Rectangles or Binary mask.
[...] = step(H,I,LABEL,LABELNUMBERS) computes the minimum of
an input image, I, for a region whose labels are specified in the vector
LABELNUMBERS. To enable this type of processing, set the ROIProcessing
property to true and the ROIForm property to Label matrix.
2-648
vision.Minimum.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-649
vision.MorphologicalBottomHat
Properties ImageType
Specify type of input image or video stream
Specify the type of the input image as Intensity or Binary. The
default is Intensity.
NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element values
as one of Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that you can specify structuring
elements only by using the Neighborhood property. You can not
specify structuring elements as inputs to the step method. The
default is Property.
Neighborhood
Neighborhood or structuring element values
2-650
vision.MorphologicalBottomHat
I = im2single(imread('blobs.png'));
hbot = vision.MorphologicalBottomHat('Neighborhood',strel('disk', 5))
J = step(hbot,I);
figure;
subplot(1,2,1),imshow(I); title('Original image');
subplot(1,2,2),imshow(J);
title('Bottom-hat filtered image');
Algorithms This object implements the algorithm, inputs, and outputs described on
the Bottom-hat block reference page. The object properties correspond
to the block parameters.
2-651
vision.MorphologicalBottomHat
2-652
vision.MorphologicalBottomHat.clone
Purpose Create morphological bottom hat filter with same property values
Syntax C = clone(H)
2-653
vision.MorphologicalBottomHat.getNumInputs
Syntax N = getNumInputs(H)
2-654
vision.MorphologicalBottomHat.getNumOutputs
Syntax N = getNumOutputs(H)
2-655
vision.MorphologicalBottomHat.isLocked
Syntax TF = isLocked(H)
2-656
vision.MorphologicalBottomHat.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-657
vision.MorphologicalBottomHat.step
Syntax Y = step(H,I)
Y = step(H,I,NHOOD)
2-658
vision.MorphologicalClose
Properties NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element
values as Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that structuring elements can
only be specified using Neighborhood property and they cannot be
used as input to the step method. The default is Property.
Neighborhood
Neighborhood or structuring element values
2-659
vision.MorphologicalClose
img = im2single(imread('blobs.png'));
hclosing = vision.MorphologicalClose;
hclosing.Neighborhood = strel('disk', 10);
closed = step(hclosing, img);
figure;
Algorithms This object implements the algorithm, inputs, and outputs described
on the Closing block reference page. The object properties correspond
to the block parameters.
2-660
vision.MorphologicalClose
2-661
vision.MorphologicalClose.clone
Syntax C = clone(H)
2-662
vision.MorphologicalClose.getNumInputs
Syntax N = getNumInputs(H)
2-663
vision.MorphologicalClose.getNumOutputs
Syntax N = getNumOutputs(H)
2-664
vision.MorphologicalClose.isLocked
Syntax TF = isLocked(H)
2-665
vision.MorphologicalClose.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-666
vision.MorphologicalClose.step
Syntax IC = step(H,I)
IC = step(H,I,NHOOD)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-667
vision.MorphologicalDilate
Properties NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element
values as Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that structuring elements can
only be specified using Neighborhood property and they cannot be
used as input to the step method. The default is Property.
Neighborhood
Neighborhood or structuring element values
This property is applicable when the NeighborhoodSource
property is set to Property. If you are specifying a neighborhood,
this property must be a matrix or vector of 1s and 0s. If you are
2-668
vision.MorphologicalDilate
x = imread('peppers.png');
hcsc = vision.ColorSpaceConverter;
hcsc.Conversion = 'RGB to intensity';
hautothresh = vision.Autothresholder;
hdilate = vision.MorphologicalDilate('Neighborhood', ones(5,5));
x1 = step(hcsc, x);
x2 = step(hautothresh, x1);
y = step(hdilate, x2);
figure;
2-669
vision.MorphologicalDilate
Algorithms This object implements the algorithm, inputs, and outputs described
on the Dilation block reference page. The object properties correspond
to the block parameters.
2-670
vision.MorphologicalDilate.clone
Syntax C = clone(H)
2-671
vision.MorphologicalDilate.getNumInputs
Syntax N = getNumInputs(H)
2-672
vision.MorphologicalDilate.getNumOutputs
Syntax N = getNumOutputs(H)
2-673
vision.MorphologicalDilate.isLocked
Syntax TF = isLocked(H)
2-674
vision.MorphologicalDilate.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-675
vision.MorphologicalDilate.step
Syntax ID = step(H,I)
ID = step(H,I,NHOOD)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-676
vision.MorphologicalErode
Properties NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element
values as Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that structuring elements can
only be specified using Neighborhood property and they cannot be
used as input to the step method. The default is Property.
Neighborhood
Neighborhood or structuring element values
This property is applicable when the NeighborhoodSource
property is set to Property. If you are specifying a neighborhood,
this property must be a matrix or vector of 1s and 0s. If you are
2-677
vision.MorphologicalErode
x = imread('peppers.png');
hcsc = vision.ColorSpaceConverter;
hcsc.Conversion = 'RGB to intensity';
hautothresh = vision.Autothresholder;
herode = vision.MorphologicalErode('Neighborhood', ones(5,5));
x1 = step(hcsc, x); % convert input to intensity
x2 = step(hautothresh, x1); % convert input to binary
y = step(herode, x2); % Perform erosion on input
figure;
2-678
vision.MorphologicalErode
Algorithms This object implements the algorithm, inputs, and outputs described
on the Erosion block reference page. The object properties correspond
to the block parameters.
2-679
vision.MorphologicalErode.clone
Syntax C = clone(H)
2-680
vision.MorphologicalErode.getNumInputs
Syntax N = getNumInputs(H)
2-681
vision.MorphologicalErode.getNumOutputs
Syntax N = getNumOutputs(H)
2-682
vision.MorphologicalErode.isLocked
Syntax TF = isLocked(H)
2-683
vision.MorphologicalErode.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-684
vision.MorphologicalErode.step
Syntax IE = step(H,I)
IE = step(H,I,NHOOD)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-685
vision.MorphologicalOpen
Properties NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element
values as Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that structuring elements can
only be specified using Neighborhood property and they cannot be
used as input to the step method. The default is Property.
Neighborhood
2-686
vision.MorphologicalOpen
img = im2single(imread('blobs.png'));
hopening = vision.MorphologicalOpen;
hopening.Neighborhood = strel('disk', 5);
opened = step(hopening, img);
figure;
2-687
vision.MorphologicalOpen
Algorithms This object implements the algorithm, inputs, and outputs described
on the Opening block reference page. The object properties correspond
to the block parameters.
2-688
vision.MorphologicalOpen.clone
Syntax C = clone(H)
2-689
vision.MorphologicalOpen.getNumInputs
Syntax N = getNumInputs(H)
2-690
vision.MorphologicalOpen.getNumOutputs
Syntax N = getNumOutputs(H)
2-691
vision.MorphologicalOpen.isLocked
Syntax TF = isLocked(H)
2-692
vision.MorphologicalOpen.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-693
vision.MorphologicalOpen.step
Syntax IO = step(H,I)
IO = step(H,I,NHOOD)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-694
vision.MorphologicalTopHat
Properties ImageType
Specify type of input image or video stream
Specify the type of input image or video stream as Intensity or
Binary. The default is Intensity.
NeighborhoodSource
Source of neighborhood values
Specify how to enter neighborhood or structuring element
values as Property or Input port. If set to Property, use the
Neighborhood property to specify the neighborhood or structuring
element values. Otherwise, specify the neighborhood using an
input to the step method. Note that structuring elements can
only be specified using the Neighborhood property. You cannot
use the structuring elements as an input to the step method.
The default is Property.
Neighborhood
Neighborhood or structuring element values
2-695
vision.MorphologicalTopHat
I = im2single(imread('rice.png'));
htop = vision.MorphologicalTopHat('Neighborhood',strel('disk', 12));
2-696
vision.MorphologicalTopHat
Algorithms This object implements the algorithm, inputs, and outputs described
on the Top-hat block reference page. The object properties correspond
to the block parameters.
2-697
vision.MorphologicalTopHat.clone
Purpose Create morphological top hat filter with same property values
Syntax C = clone(H)
2-698
vision.MorphologicalTopHat.getNumInputs
Syntax N = getNumInputs(H)
2-699
vision.MorphologicalTopHat.getNumOutputs
Syntax N = getNumOutputs(H)
2-700
vision.MorphologicalTopHat.isLocked
Syntax TF = isLocked(H)
2-701
vision.MorphologicalTopHat.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-702
vision.MorphologicalTopHat.step
Syntax Y = step(H,I)
Y = step(H,I,NHOOD)
Description Y = step(H,I) top-hat filters the input image, I , and returns the
filtered image Y.
Y = step(H,I,NHOOD) filters the input image, I using the input NHOOD
as the neighborhood when you set the NeighborhoodSource property to
Input port. The object returns the filtered image in the output Y.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-703
vision.VideoFileReader
Purpose Read video frames and audio samples from video file
Description The VideoFileReader object reads video frames, images, and audio
samples from a video file. The object can also read image files.
Video:
MPEG (.mpeg)
MPEG-2 (.mp2)
MPEG-1.mpg
2-704
vision.VideoFileReader
Note MJ2 files with bit depth higher than 8-bits is not supported by
vision.VideoFileReader. Use VideoReader and VideoWriter for
higher bit depths.
2-705
vision.VideoFileReader
read video frames and/or audio samples from the input video file,
FILENAME. Every call to the step method returns the next video frame.
videoFReader = vision.VideoFileReader(Filename,Name,Value)
configures the video file reader properties, specified as one or more
name-value pair arguments. Unspecified properties have default values.
To read a file:
1 Define and set up your video file reader object using the constructor.
2 Call the step method with the input filename, FILENAME, the video
file reader object, videoFReader, and any optional properties. See
the syntax below for using the step method.
2-706
vision.VideoFileReader
Properties Filename
Name of video file
Specify the name of the video file as a string. The full path for the
file needs to be specified only if the file is not on the MATLAB
path.
Default: vipmen.avi
PlayCount
Number of times to play file
Specify a positive integer or inf to represent the number of times
to play the file.
Default: inf
AudioOutputPort
Output audio data
Use this property to control the audio output from the video file
reader. This property applies only when the file contains both
audio and video streams.
Default: false
ImageColorSpace
RGB, YCbCr, or intensity video
Specify whether you want the video file reader object to output
RGB, YCbCr 4:2:2 or intensity video frames. This property applies
only when the file contains video. This property can be set to RGB,
Intensity, or YCbCr 4:2:2.
Default: RGB
VideoOutputDataType
2-707
vision.VideoFileReader
2-708
vision.VideoFileReader
2-709
vision.VideoFileReader.clone
Purpose Create multimedia file reader object with same property values
Syntax C = clone(H)
2-710
vision.VideoFileReader.getNumInputs
Syntax N = getNumInputs(H)
2-711
vision.VideoFileReader.getNumOutputs
Syntax N = getNumOutputs(H)
2-712
vision.VideoFileReader.info
Syntax S = info(H)
[VideoWidthInPixels, VideoHeightInPixels]
VideoFormat Video signal format.
2-713
vision.VideoFileReader.isDone
Syntax TF = isDone(H)
2-714
vision.VideoFileReader.isLocked
Syntax TF = isLocked(H)
2-715
vision.VideoFileReader.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-716
vision.VideoFileReader.reset
Purpose Reset internal states of multimedia file reader to read from beginning
of file
Syntax reset(H)
Description reset(H) resets the VideoFileReader object to read from the beginning
of the file.
2-717
vision.VideoFileReader.step
Syntax I = step(H)
[Y,Cb,Cr] = step(H)
[I,AUDIO] = step(H)
[Y,Cb,Cr,AUDIO] = step(H)
[..., EOF] = step(H)
Description Use the step method with the video file reader object and any optional
properties to output the next video frame.
I = step(H) outputs next video frame.
[Y,Cb,Cr] = step(H) outputs next frame of YCbCr 4:2:2 video in the
color components Y, Cb, and Cr. This syntax requires that you set the
ImageColorSpace property to ’YCbCr 4:2:2’.
[I,AUDIO] = step(H) outputs next video frame, I, and one frame
of audio samples, AUDIO. This syntax requires that you set the
AudioOutputPort property to true.
[Y,Cb,Cr,AUDIO] = step(H) outputs next frame of YCbCr 4:2:2 video
in the color components Y, Cb, and Cr, and one frame of audio samples
in AUDIO. This syntax requires that you set the AudioOutputPort
property to true, and the ImageColorSpace property to ’YCbCr 4:2:2’.
[..., EOF] = step(H) returns the end-of-file indicator, EOF. The
object sets EOF to true each time the output contains the last audio
sample and/or video frame.
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-718
vision.VideoFileWriter
Description The VideoFileWriter object writes video frames and audio samples to
a video file. .mwv files can be written only on Windows. The video and
audio can be compressed. The available compression types depend on
the encoders installed on the platform.
Note This block supports code generation for platforms that have file
I/O available. You cannot use this block with Real-Time Windows
Target software, because that product does not support file I/O.
The generated code for this object relies on prebuilt library files. You
can run this code outside the MATLAB environment, or redeploy it,
but be sure to account for these extra library files when doing so. The
packNGo function creates a single zip file containing all of the pieces
required to run or rebuild this code. See packNGo for more information.
To run an executable file that was generated from an object, you may
need to add precompiled shared library files to your system path. See
“MATLAB Coder” and “Simulink Shared Library Dependencies” for
details.
This object allows you to write .wma/.wmv streams to disk or across a
network connection. Similarly, the vision.VideoFileReader object
allows you to read .wma/.wmv streams to disk or across a network
connection. If you want to play an .mp3/.mp4 file, but you do not have
the codecs, you can re-encode the file as .wma/.wmv, which is supported
by the Computer Vision System Toolbox.
2-719
vision.VideoFileWriter
To write to a file:
1 Define and set up your video file writer object using the constructor.
2 Call the step method with the optional output filename, FILENAME,
the video file writer object, videoFWriter, and any optional
properties. See the syntax below for using the step method.
2-720
vision.VideoFileWriter
Properties Filename
Video output file name
Specify the name of the video file as a string.
Default: output.avi
FileFormat
Output file format
Specify the format of the file that is created. On Windows
platforms, this may be AVI or WMV. On other platforms, this
value is restricted to AVI. These abbreviations correspond to the
following file formats:
Default: .avi
AudioInputPort
Write audio data
2-721
vision.VideoFileWriter
2-722
vision.VideoFileWriter
y = vision.VideoFileWriter
y.VideoCompressor='
2-723
vision.VideoFileWriter
Specify the color space of AVI files as RGB or YCbCr 4:2:2. This
property applies when you set the FileFormat property to AVI
and only on Windows platforms.
Default: RGB
Methods
videoFReader = vision.VideoFileReader('viplanedeparture.avi');
videoFWriter = vision.VideoFileWriter('myFile.avi','FrameRate',videoFRead
Write the first 50 frames from original file into a newly created AVI file.
for i=1:50
videoFrame = step(videoFReader);
step(videoFWriter, videoFrame);
end
release(videoFReader);
release(videoFWriter);
2-724
vision.VideoFileWriter.clone
Purpose Create video file writer object with same property values
Syntax C = clone(H)
2-725
vision.VideoFileWriter.getNumInputs
Syntax N = getNumInputs(H)
2-726
vision.VideoFileWriter.getNumOutputs
Syntax N = getNumOutputs(H)
2-727
vision.VideoFileWriter.isLocked
Syntax TF = isLocked(H)
2-728
vision.VideoFileWriter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-729
vision.VideoFileWriter.step
Syntax step(videoFWriter,I)
step(videoFWriter,Y,Cb,Cr)
step(videoFWriter,I,AUDIO)
step(videoFWriter,Y,Cb,Cr,AUDIO)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-730
ocrText
Description The ocr function returns the ocrText object. The object contains
the recognized text and metadata collected during optical character
recognition (OCR). You can access the information with the ocrText
object properties. You can also locate text that matches a specific
pattern with the object’s locateText method.
2-731
ocrText
2-732
ocrText
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'MathWorks', 'IgnoreCase', true);
Iocr = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(Iocr);
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'www.*com','UseRegexp', true);
img = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(img);
2-733
ocrText
2-734
ocrText.locateText
2-735
ocrText.locateText
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'MathWorks', 'IgnoreCase', true);
Iocr = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(Iocr);
2-736
ocrText.locateText
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'www.*com','UseRegexp', true);
img = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(img);
2-737
ocrText.locateText
2-738
vision.OpticalFlow
Description The OpticalFlow System object estimates object velocities from one
image or video frame to another. It uses either the Horn-Schunck or
the Lucas-Kanade method.
To estimate velocity:
2 Call the step method with the input image, I, the optical flow object,
opticalFlow, and any optional properties. See the syntax below for
using the step method.
2-739
vision.OpticalFlow
Properties Method
Optical flow computation algorithm
Specify the algorithm to compute the optical flow as one of
Horn-Schunck | Lucas-Kanade.
Default: Horn-Schunck
ReferenceFrameSource
Source of reference frame for optical flow calculation
Specify computing optical flow as one of Property | Input
port. When you set this property to Property, you can use the
ReferenceFrameDelay property to determine a previous frame
with which to compare. When you set this property to Input
port, supply an input image for comparison.
This property applies when you set the Method property to
Horn-Schunck. This property also applies when you set the Method
property to Lucas-Kanade and the TemporalGradientFilter
property to Difference filter [-1 1].
Default: Property
ReferenceFrameDelay
Number of frames between reference frame and current frame
Specify the number of frames between the reference and current
frame as a positive scalar integer. This property applies when
you set the ReferenceFrameSource property to Current frame
and N-th frame back.
Default: 1
2-740
vision.OpticalFlow
Smoothness
Expected smoothness of optical flow
Specify the smoothness factor as a positive scalar number. If
the relative motion between the two images or video frames is
large, specify a large positive scalar value. If the relative motion
is small, specify a small positive scalar value. This property
applies when you set the Method property to Horn-Schunck. This
property is tunable.
Default: 1
IterationTerminationCondition
Condition to stop iterative solution computation
Specify when the optical flow iterative solution stops. Specify
as one of Maximum iteration count | Velocity difference
threshold | Either . This property applies when you set the
Method property to Horn-Schunck.
Default: Maximum iteration count
MaximumIterationCount
Maximum number of iterations to perform
Specify the maximum number of iterations to perform in the
optical flow iterative solution computation as a positive scalar
integer. This property applies when you set the Method property
to Horn-Schunck and the IterationTerminationCondition
property to either Maximum iteration count or Either. This
property is tunable.
Default: 10
VelocityDifferenceThreshold
Velocity difference threshold
Specify the velocity difference threshold to stop the optical flow
iterative solution computation as a positive scalar number.
This property applies when you set the Method property to
2-741
vision.OpticalFlow
2-742
vision.OpticalFlow
2-743
vision.OpticalFlow
Default: false
NoiseReductionThreshold
Threshold for noise reduction
Specify the motion threshold between each image or video frame
as a positive scalar number. The higher the number, the less small
movements impact the optical flow calculation. This property
applies when you set the Method property to Lucas-Kanade. This
property is tunable.
Default: 0.0039
Fixed-Point Properties
RoundingMethod
Rounding mode for fixed-point operations
Specify the rounding method as one of Ceiling | Convergent
| Floor | Nearest | Round | Simplest | Zero. This property
applies when you set the Method property to Lucas-Kanade and
the TemporalGradientFilter property to Difference filter
[-1 1].
Default: Nearest
OverflowAction
Overflow mode for fixed-point operations
Specify the overflow action as Wrap or Saturate. This property
applies when you set the Method property to Lucas-Kanade and
the TemporalGradientFilter property to Difference filter
[-1 1].
Default: Saturate
ProductDataType
Product word and fraction lengths
2-744
vision.OpticalFlow
2-745
vision.OpticalFlow
2-746
vision.OpticalFlow
2-747
vision.OpticalFlow
Set up objects.
videoReader = vision.VideoFileReader('viptraffic.avi','ImageColorSpace','
converter = vision.ImageDataTypeConverter;
opticalFlow = vision.OpticalFlow('ReferenceFrameDelay', 1);
opticalFlow.OutputValue = 'Horizontal and vertical components in complex
shapeInserter = vision.ShapeInserter('Shape','Lines','BorderColor','Custo
videoPlayer = vision.VideoPlayer('Name','Motion Vector');
Convert the image to single precision, then compute optical flow for
the video. Generate coordinate points and draw lines to indicate flow.
Display results.
while ~isDone(videoReader)
frame = step(videoReader);
im = step(converter, frame);
of = step(opticalFlow, im);
lines = videooptflowlines(of, 20);
if ~isempty(lines)
out = step(shapeInserter, im, lines);
step(videoPlayer, out);
end
end
2-748
vision.OpticalFlow
release(videoPlayer);
release(videoReader);
Algorithms To compute the optical flow between two images, you must solve the
following optical flow constraint equation:
I x u + I y v + It = 0
• Horn-Schunck Method
• Lucas-Kanade Method
Horn-Schunck Method
By assuming that the optical flow is smooth over the entire image,
the Horn-Schunck method computes an estimate of the velocity field,
⎧⎪⎛ ∂u ⎞2 ⎛ ∂u ⎞2 ⎛ ∂v ⎞2 ⎛ ∂v ⎞2 ⎫⎪
∫∫ x y t ∫∫ ⎨⎪⎜⎝ ∂x ⎟⎠ + ⎜⎝ ∂y ⎟⎠ + ⎜⎝ ∂x ⎟⎠ + ⎜⎝ ∂y ⎟⎠ ⎬⎪dxdy
2
E= ( I u + I v + I ) dxdy + α
⎩ ⎭
∂u ∂u
In this equation, ∂x and ∂y are the spatial derivatives of the optical
velocity component u, and α scales the global smoothness term. The
2-749
vision.OpticalFlow
k I x [ I x u xk, y + I y v xk, y + It ]
uxk,+y1 = u x, y −
α 2 + I x2 + I 2y
k I y[ I x u xk, y + I y v xk, y + It ]
vxk,+y1 = v x, y −
α 2 + I x2 + I 2y
In this equation, ⎡uxk, y vxk, y ⎤ is the velocity estimate for the pixel at
⎣ ⎦
⎡ k k ⎤
(x,y), and ⎢⎣u x, y v x, y ⎥⎦ is the neighborhood average of ⎡uxk, y vxk, y ⎤ .
⎣ ⎦
For k=0, the initial velocity is 0.
When you choose the Horn-Schunck method, u and v are solved as
follows:
Lucas-Kanade Method
To solve the optical flow constraint equation for u and v, the
Lucas-Kanade method divides the original image into smaller sections
2-750
vision.OpticalFlow
∑ W 2[ I xu + I yv + It ]2
x∈Ω
⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥ ⎡u⎤ = − ⎡⎢∑ W 2 I x It ⎤⎥
⎢ ⎢ ⎥
⎢∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦ ⎣ v ⎦ ⎢⎣∑ W 2 I y It ⎥⎦
⎣
If you are working with fixed-point data types, the kernel values are
signed fixed-point values with word length equal to 16 and fraction
length equal to 15.
2-751
vision.OpticalFlow
4 Solve the 2-by-2 linear equations for each pixel using the following
method:
⎡ a b⎤ ⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥
• If A = ⎢ ⎥=⎢
⎣ b c ⎦ ⎢⎣ ∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦
a+c 4b2 + (a − c)2
Then the eigenvalues of A are λ i = ± ; i = 1, 2
2 2
Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, the system of equations are solved using
Cramer’s rule.
2-752
vision.OpticalFlow
Derivative of Gaussian
If you set the temporal gradient filter to Derivative of Gaussian, u
and v are solved using the following steps. You can see the flow chart
for this process at the end of this section:
4 Solve the 2-by-2 linear equations for each pixel using the following
method:
2-753
vision.OpticalFlow
⎡ a b⎤ ⎡ ∑ W 2 I x2 ∑ W 2 I x I y ⎤⎥
• If A = ⎢ ⎥=⎢
⎣ b c ⎦ ⎢⎣ ∑ W 2 I y I x ∑ W 2 I 2y ⎥⎦
a+c 4b2 + (a − c)2
Then the eigenvalues of A are λ i = ± ; i = 1, 2
2 2
• When the object finds the eigenvalues, it compares them to the
threshold, τ , that corresponds to the value you enter for the
NoiseReductionThreshold parameter. The results fall into one of
the following cases:
Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, so the object solves the system of equations using
Cramer’s rule.
References
[1] Barron, J.L., D.J. Fleet, S.S. Beauchemin, and T.A. Burkitt.
Performance of optical flow techniques. CVPR, 1992.
2-754
vision.OpticalFlow.clone
Syntax C = clone(H)
2-755
vision.OpticalFlow.getNumInputs
Syntax N = getNumInputs(H)
2-756
vision.OpticalFlow.getNumOutputs
Syntax N = getNumOutputs(H)
2-757
vision.OpticalFlow.isLocked
Syntax isLocked(h)
2-758
vision.OpticalFlow.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-759
vision.OpticalFlow.step
Purpose Estimate direction and speed of object motion between video frames
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-760
vision.PeopleDetector
Description The people detector object detects people in an input image using the
Histogram of Oriented Gradient (HOG) features and a trained Support
Vector Machine (SVM) classifier. The object detects unoccluded people
in an upright position.
To detect people:
1 Define and set up your people detector object using the constructor.
2 Call the step method with the input image, I, and the people detector
object, peopleDetector. See the syntax below for using the step
method.
2-761
vision.PeopleDetector
Properties ClassificationModel
Name of classification model
Specify the model as either 'UprightPeople_128x64' or
'UprightPeople_96x48'. The pixel dimensions indicate the
image size used for training.
The images used to train the models include background pixels
around the person. Therefore, the actual size of a detected person
is smaller than the training image size.
Default: 'UprightPeople_128x64'
ClassificationThreshold
People classification threshold
Specify a nonnegative scalar threshold value. Use this threshold
to control the classification of individual image subregions during
multiscale detection. The threshold controls whether a subregion
gets classified as a person. You can increase this value when
there are many false detections. The higher the threshold value,
the more stringent the requirements are for the classification.
Vary the threshold over a range of values to find the optimum
value for your data set. Typical values range from 0 to 4. This
property is tunable.
Default: 1
2-762
vision.PeopleDetector
MinSize
Smallest region containing a person
Specify a two-element vector, [height width], in pixels for the
smallest region containing a person. When you know the
minimum person size to detect, you can reduce computation time.
To do so, set this property to a value larger than the image size
used to train the classification model. When you do not specify
this property, the object sets it to the image size used to train the
classification model. This property is tunable.
Default: []
MaxSize
Largest region containing a person
Specify a two-element vector, [height width], in pixels for the
largest region containing a person. When you know the maximum
person size to detect, you can reduce computation time. To do
so, set this property to a value smaller than the size of the input
image. When you do not specify this property, the object sets it to
the input image size. This property is tunable.
Default: []
ScaleFactor
Multiscale object detection scaling
Specify a factor, with a value greater than 1.0001, to
incrementally scale the detection resolution between MinSize and
MaxSize. You can set the scale factor to an ideal value using:
size(I)/(size(I)-0.5)
round(TrainingSize*(ScaleFactorN))
2-763
vision.PeopleDetector
Default: 1.05
WindowStride
Detection window stride
Specify a scalar or a two-element vector [x y] in pixels for the
detection window stride. The object uses the window stride to
slide the detection window across the image. When you specify
this value as a vector, the first and second elements are the stride
size in the x and y directions. When you specify this value as a
scalar, the stride is the same for both x and y. Decreasing the
window stride can increase the detection accuracy. However,
doing so increases computation time. Increasing the window
stride beyond [8 8] can lead to a greater number of missed
detections. This property is tunable.
Default: [8 8]
MergeDetections
Merge detection control
Specify a logical scalar to control whether similar detections
are merged. Set this property to true to merge bounding boxes
using a mean-shift based algorithm. Set this property to false
to output the unmerged bounding boxes.
Default: true
2-764
vision.PeopleDetector
1
Create a people detector, and load the input image.
peopleDetector = vision.PeopleDetector;
I = imread('visionteam1.jpg');
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBor
Draw detected bounding boxes, and insert scores using the inserter
objects.
2-765
vision.PeopleDetector
I = step(shapeInserter, I, int32(bboxes));
I = step(scoreInserter, I, scores, int32(bboxes(:,1:2)));
figure, imshow(I)
title('Detected people and detection scores');
2-766
vision.PeopleDetector.clone
Syntax C = clone(H)
2-767
vision.PeopleDetector.isLocked
Syntax TF = isLocked(H)
2-768
vision.PeopleDetector.release
Syntax release(H)
2-769
vision.PeopleDetector.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-770
vision.PointTracker
Description The point tracker object tracks a set of points using the
Kanade-Lucas-Tomasi (KLT), feature-tracking algorithm. You can use
the point tracker for video stabilization, camera motion estimation, and
object tracking. It works particularly well for tracking objects that do
not change shape and for those that exhibit visual texture. The point
tracker is often used for short-term tracking as part of a larger tracking
framework.
As the point tracker algorithm progresses over time, points can be lost
due to lighting variation, out of plane rotation, or articulated motion.
To track an object over a long period of time, you may need to reacquire
points periodically.
2-771
vision.PointTracker
1 Define and set up your point tracker object using the constructor.
2 Call the step method with the input image, I, and the point tracker
object, pointTracker. See the following syntax for using the step
method.
After initializing the tracking process, use the step method to track the
points in subsequent video frames. You can also reset the points at any
time by using the setPoints method.
[points,point_validity] = step(pointTracker,I) tracks
the points in the input frame, I using the point tracker object,
pointTracker. The output points contain an M-by-2 array of [x y]
coordinates that correspond to the new locations of the points in the
input frame, I. The output, point_validity provides an M-by-1
logical array, indicating whether or not each point has been reliably
tracked.
A point can be invalid for several reasons. The point can become
invalid if it falls outside of the image. Also, it can become invalid if
the spatial gradient matrix computed in its neighborhood is singular.
If the bidirectional error is greater than the MaxBidirectionalError
threshold, this condition can also make the point invalid.
[points,point_validity,scores] = step(pointTracker,I)
additionally returns the confidence score for each point. The M-by-1
output array, scores, contains values between 0 and 1. These values
correspond to the degree of similarity between the neighborhood around
the previous location and new location of each point. These values are
computed as a function of the sum of squared differences between the
previous and new neighborhoods. The greatest tracking confidence
corresponds to a perfect match score of 1.
2-772
vision.PointTracker
Properties NumPyramidLevels
Number of pyramid levels
Specify an integer scalar number of pyramid levels. The point
tracker implementation of the KLT algorithm uses image
pyramids. The object generates an image pyramid, where each
level is reduced in resolution by a factor of two compared to the
previous level. Selecting a pyramid level greater than 1, enables
the algorithm to track the points at multiple levels of resolution,
starting at the lowest level. Increasing the number of pyramid
levels allows the algorithm to handle larger displacements of
points between frames. However, computation cost also increases.
Recommended values are between 1 and 4.
2-773
vision.PointTracker
Default: 3
MaxBidirectionalError
Forward-backward error threshold
Specify a numeric scalar for the maximum bidirectional error. If
the value is less than inf, the object tracks each point from the
2-774
vision.PointTracker
Default: inf
BlockSize
Size of neighborhood
Specify a two-element vector, [height, width] to represent the
neighborhood around each point being tracked. The height and
width must be odd integers. This neighborhood defines the area
for the spatial gradient matrix computation. The minimum value
for BlockSize is [5 5]. Increasing the size of the neighborhood,
increases the computation time.
MaxIterations
2-775
vision.PointTracker
Default: 30
Create System objects for reading and displaying video and for drawing
a bounding box of the object.
videoFileReader = vision.VideoFileReader('visionface.avi');
videoPlayer = vision.VideoPlayer('Position', [100, 100, 680, 520]);
Read the first video frame, which contains the object, define the region.
objectFrame = step(videoFileReader);
objectRegion = [264, 122, 93, 93];
2-776
vision.PointTracker
region.
figure; imshow(objectFrame);
objectRegion=round(getPosition(imrect))
while ~isDone(videoFileReader)
2-777
vision.PointTracker
frame = step(videoFileReader);
[points, validity] = step(tracker, frame);
out = insertMarker(frame, points(validity, :), '+');
step(videoPlayer, out);
end
release(videoPlayer);
release(videoFileReader);
References Lucas, Bruce D. and Takeo Kanade. “An Iterative Image Registration
Technique with an Application to Stereo Vision,”Proceedings of the 7th
International Joint Conference on Artificial Intelligence, April, 1981,
pp. 674–679.
Tomasi, Carlo and Takeo Kanade. Detection and Tracking of Point
Features, Computer Science Department, Carnegie Mellon University,
April, 1991.
Shi, Jianbo and Carlo Tomasi. “Good Features to Track,” IEEE
Conference on Computer Vision and Pattern Recognition, 1994, pp.
593–600.
Kalal, Zdenek, Krystian Mikolajczyk, and Jiri Matas.
“Forward-Backward Error: Automatic Detection of Tracking Failures,”
Proceedings of the 20th International Conference on Pattern Recognition,
2010, pages 2756–2759, 2010.
2-778
vision.PointTracker.initialize
Syntax initialize(H,POINTS,I)
2-779
vision.PointTracker.setPoints
Syntax setPoints(H,POINTS)
setPoints(H,POINTS,POINT_VALIDITY)
Description setPoints(H,POINTS) sets the points for tracking. The method sets the
M-by-2 POINTS array of [x y] coordinates with the points to track. This
method can be used if the points need to be re-detected because too
many of them have been lost during tracking.
setPoints(H,POINTS,POINT_VALIDITY) additionally lets you
mark points as either valid or invalid. The input logical vector
POINT_VALIDITY of length M, contains the true or false value
corresponding to the validity of the point to be tracked. The length M
corresponds to the number of points. A false value indicates an invalid
point, and it should not be tracked. You can use this method with
the vision.GeometricTransformEstimator object to determine the
transformation between the point locations in the previous and current
frames, and then mark the outliers as invalid.
2-780
vision.PointTracker.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-781
vision.PSNR
Description The PSNR object computes the peak signal-to-noise ratio (PSNR)
between images. This ratio is often used as a quality measurement
between an original and a compressed image.
Examples Compute the PSNR between an original image and its reconstructed
image.
hdct2d = vision.DCT;
2-782
vision.PSNR
hidct2d = vision.IDCT;
hpsnr = vision.PSNR;
I = double(imread('cameraman.tif'));
J = step(hdct2d, I);
J(abs(J) < 10) = 0;
It = step(hidct2d, J);
psnr = step(hpsnr, I,It)
imshow(I, [0 255]), title('Original image');
figure, imshow(It,[0 255]), title('Reconstructed image');
Algorithms This object implements the algorithm, inputs, and outputs described
on the PSNR block reference page. The object properties correspond
to the block parameters.
2-783
vision.PSNR.clone
Purpose Create peak signal to noise ratio object with same property values
Syntax C = clone(H)
Description C = clone(H) creates a PSNR System object C, with the same property
values as H. The clone method creates a new unlocked object.
2-784
vision.PSNR.getNumInputs
Syntax N = getNumInputs(H)
2-785
vision.PSNR.getNumOutputs
Syntax N = getNumOutputs(H)
2-786
vision.PSNR.isLocked
Syntax TF = isLocked(H)
2-787
vision.PSNR.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-788
vision.PSNR.step
Syntax Y = step(H,X1,X2)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-789
vision.Pyramid
2 Call the step method with the input image, I and the pyramid object,
gaussPyramid. See the syntax below for using the step method.
Properties Operation
Reduce or expand the input image
Specify whether to reduce or expand the input image as Reduce
or Expand. If this property is set to Reduce, the object applies
a lowpass filter and then downsamples the input image. If this
2-790
vision.Pyramid
Fixed-Point Properties
RoundingMethod
2-791
vision.Pyramid
2-792
vision.Pyramid
2-793
vision.Pyramid
I = im2single(imread('cameraman.tif'));
J = step(gaussPyramid, I);
Display results.
2-794
vision.Pyramid.clone
Syntax C = clone(H)
2-795
vision.Pyramid.getNumInputs
Syntax N = getNumInputs(H)
2-796
vision.Pyramid.getNumOutputs
Syntax N = getNumOutputs(H)
2-797
vision.Pyramid.isLocked
Syntax TF = isLocked(H)
2-798
vision.Pyramid.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-799
vision.Pyramid.step
Syntax J = step(gaussPyramid,I)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-800
vision.ShapeInserter
To insert a shape:
2 Call the step method with the input image, I, the shape inserter
object, shapeInserter, points PTS, and any optional properties. See
the syntax below for using the step method.
2-801
vision.ShapeInserter
Properties Shape
Shape to draw
You can specify the type of shape as Rectangles, Lines, Polygons,
or Circles. When you specify the type of shape to draw, you must
also specify the location. The PTS input specifies the location of
the points. The table shows the format for the points input for
the different shapes. For a more detailed explanation on how to
specify shapes and lines, see “Draw Shapes and Lines”.
2-802
vision.ShapeInserter
Default: Rectangles
Fill
Enable filling shape
Set this property to true to fill the shape with an intensity value
or a color. This property only applies for the 'Rectangles',
'Polygons', and 'Circles' shapes.
Default: false
BorderColorSource
Source of border color
Specify how the shape’s border color is provided as Input port
or Property. This property applies when you set the Shape
property to Lines or, when you do not set the Shape property to
Lines and you set the Fill property to false. When you set
theBorderColorSource property to Input port, a border color
vector must be provided as an input to the System object’s step
method.
2-803
vision.ShapeInserter
Default: Property
BorderColor
Border color of shape
Specify the appearance of the shape’s border as Black, White,
or Custom. When you set this property to Custom, you can use
the CustomBorderColor property to specify the value. This
property applies when you set the BorderColorSource property
to Property.
Default: Black
CustomBorderColor
Intensity or color value for shape’s border
Specify an intensity or color value for the shape’s border. For an
intensity image input, this property can be set to either a scalar
intensity value for one shape, or an R-element vector where R
specifies the number of shapes. For a color input image, you can
set this property to:
2-804
vision.ShapeInserter
Default: Property
FillColor
Fill color of shape
Specify the intensity of the shading inside the shape as Black,
White, or Custom. When you set this property to Custom, you can
use the CustomFillColor property to specify the value. This
property applies when set the FillColorSource property to
Property.
Default: Black
CustomFillColor
Intensity or color value for shape’s interior
Specify an intensity or color value for the shape’s interior. For
an intensity input image, you can set this property to a scalar
intensity value for one shape, or an R-element vector where R
specifies the number of shapes. For a color input image, you can
set this property to:
2-805
vision.ShapeInserter
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
Specify the rounding method as Ceiling, Convergent, Floor,
Nearest, Round, Simplest, or Zero. This property applies when
you set the Fill property to true and/or the Antialiasing
property to true.
Default: Floor
OverflowAction
Overflow action for fixed-point operations
Specify the overflow action as Wrap , or Saturate. This property
applies when you set the Fill property to true and/or the
Antialiasing property to true.
2-806
vision.ShapeInserter
Default: Wrap
OpacityDataType
Opacity word length
Specify the opacity fixed-point data type as Same word length
as input, or Custom. This property applies when you set the
Fill property to true.
Default: Custom
CustomOpacityDataType
Opacity word length
Specify the opacity fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the Fill property to true and the OpacityDataType property
to Custom.
Default: numerictype([],16)
ProductDataType
Product word and fraction lengths
Specify the product fixed-point data type as Same as first
input, or Custom. This property applies when you set the Fill
property to true and/or the Antialiasing property to true.
Default: Custom
CustomProductDataType
Product word and fraction lengths
Specify the product fixed-point type as a scaled numerictype
object with a Signedness of Auto. This property applies when you
set the Fill property to true and/or the Antialiasing property
to true, and the ProductDataType property to Custom.
Default: numerictype(true,32,14)
AccumulatorDataType
2-807
vision.ShapeInserter
2-808
vision.ShapeInserter
shapeInserter = vision.ShapeInserter;
I = imread('cameraman.tif');
J = step(shapeInserter, I, rectangle);
imshow(J);
yellow = uint8([255 255 0]); % [R G B]; class of yellow must match cla
shapeInserter = vision.ShapeInserter('Shape','Circles','BorderColor',
I = imread('cameraman.tif');
2-809
vision.ShapeInserter
imshow(J);
shapeInserter = vision.ShapeInserter('Shape','Polygons','BorderColor','Cu
I = imread('autumn.tif');
J = step(shapeInserter, I, polygon);
imshow(J);
2-810
vision.ShapeInserter.clone
Syntax C = clone(H)
2-811
vision.ShapeInserter.getNumInputs
Syntax N = getNumInputs(H)
2-812
vision.ShapeInserter.getNumOutputs
Syntax N = getNumOutputs(H)
2-813
vision.ShapeInserter.isLocked
Syntax TF = isLocked(H)
2-814
vision.ShapeInserter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-815
vision.ShapeInserter.step
Syntax J = step(shapeInserter,I,PTS)
J = step(shapeInserter,I,PTS,ROI)
J = step(shapeInserter,I,PTS,...,CLR)
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
Input shapeInserter
Arguments Shape inserter object with shape and properties specified.
I
2-816
vision.ShapeInserter.step
PTS
Input matrix coordinates describing location and dimension of
shape. This property must be an integer value. If you enter
non-integer value, the object rounds it to the nearest integer.
You can specify the type of shape as Rectangles, Lines, Polygons,
or Circles. When you specify the type of shape to draw, you must
also specify the location. The PTS input specifies the location of
the points. The table shows the format for the points input for
the different shapes. For a more detailed explanation on how to
specify shapes and lines, see “Draw Shapes and Lines”.
Depending on the shape you choose by setting the Shape property,
the input matrix PTS must be in one of the following formats:
2-817
vision.ShapeInserter.step
x1 y1 width1 height1
Polygons x
M-by-2L y2 width2 height2
matrix
2
x11 y11 x12 y12 x1 L y1 L
xxM yM width height
y21 x22 M y22 M x2 L y2 L
21
Each row
of the matrix
corresponds to a different
xM1 andyM1 xM 2 yM 2 xML yML
rectangle of the same
form as
Each rowthe
of vector for a
the matrix
single rectangle.
corresponds The [x y]
to a different
coordinates
polygon and correspond
of the sametoform
Circles M-by-3 matrix
thethe
as upper-left corner
vector for of the
a single
rectangle Lwith
polygon. respect
is the number to the
of
x1origin.
image
vertices. y1 The radius 1 and
width
x
2 must
height y2 be radius
greater 2 than
zero.
xM yM radiusM
Each row of the matrix
corresponds to a different
circle and of the same form as
the vector for a single circle.
2-818
vision.ShapeInserter.step
The table below shows the data types required for the inputs,
I and PTS.
RGB
Scalar, vector, or matrix describing one plane of the RGB input
video stream.
ROI
Input 4-element vector of integers [x y width height], that define
a rectangular area in which to draw the shapes. The first two
elements represent the one-based coordinates of the upper-left
corner of the area. The second two elements represent the width
and height of the area.
CLR
This port can be used to dynamically specify shape color.
P-element vector or an M-by-P matrix, where M is the number of
shapes, and P, the number of color planes. You can specify a color
(RGB), for each shape, or specify one color for all shapes. The data
type for the CLR input must be the same as the input image.
2-819
vision.ShapeInserter.step
Output J
Arguments Output image. The shapes are embedded on the output image.
2-820
vision.StandardDeviation
Properties RunningStandardDeviation
Enable calculation over successive calls to step method
Set this property to true to enable the calculation of standard
deviation over successive calls to the step method. The default is
false.
ResetInputPort
Reset in running standard deviation mode
Set this property to true to enable resetting the running
standard deviation. When the property is set to true, a reset
input must be specified to the step method to reset the running
standard deviation. This property applies when you set the
RunningStandardDeviation property to true. The default is
false.
ResetCondition
2-821
vision.StandardDeviation
2-822
vision.StandardDeviation
2-823
vision.StandardDeviation
img = im2single(rgb2gray(imread('peppers.png')));
hstd2d = vision.StandardDeviation;
std = step(hstd2d,img);
Algorithms This object implements the algorithm, inputs, and outputs described
on the Standard Deviation block reference page. The object properties
correspond to the block parameters.
2-824
vision.StandardDeviation.clone
Syntax C = clone(H)
2-825
vision.StandardDeviation.getNumInputs
Syntax N = getNumInputs(H)
2-826
vision.StandardDeviation.getNumOutputs
Syntax N = getNumOutputs(H)
2-827
vision.StandardDeviation.isLocked
Syntax TF = isLocked(H)
2-828
vision.StandardDeviation.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-829
vision.StandardDeviation.reset
Syntax reset(H)
2-830
stereoParameters
Syntax stereoParams =
stereoParameters(cameraParameters1,cameraParameters2,
rotationOfCamera2,translationOfCamera2)
Construction stereoParams =
stereoParameters(cameraParameters1,cameraParameters2,
rotationOfCamera2,translationOfCamera2) returns an object that
contains parameters of a stereo system.
2-831
stereoParameters
P1’ * FundamentalMatrix * P2 0
2-832
stereoParameters
P1’ * EssentialMatrix * P2 0
P1, the point in image 1 in world units, corresponds to the point,
P2, in image 2.
2-833
stereoParameters
numImages = 10;
images1 = cell(1, numImages);
images2 = cell(1, numImages);
for i = 1:numImages
images1{i} = fullfile(matlabroot, 'toolbox', 'vision','visiondemos'
images2{i} = fullfile(matlabroot, 'toolbox', 'vision','visiondemos'
end
showReprojectionErrors(params);
2-834
stereoParameters
References
[1] Zhang, Z. “A flexible new technique for camera calibration”. IEEE
Transactions on Pattern Analysis and Machine Intelligence, Vol. 22, No.
11, pp. 1330–1334, 2000.
2-835
stereoParameters
Concepts • “”
2-836
vision.StandardDeviation.step
Syntax Y = step(H,X)
Y = step(H,X,R)
Y = step(H,X,ROI)
Y = step(H,X,LABEL,LABELNUMBERS)
[Y, FLAG] = step(H,X,ROI)
[Y, FLAG] = step(H,X,LABEL,LABELNUMBERS)
2-837
vision.StandardDeviation.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-838
vision.TemplateMatcher
Description The template matcher object locates a template in an image. Use the
step syntax below with input image I, template T, template matcher
object, H, and any optional properties.
LOC = step(H,I,T) computes the [x y] location coordinates, LOC, of the
best template match between the image matrix, I, and the template
matrix, T. The step method outputs the coordinates relative to the top
left corner of the image. The LOC [x y] coordinates correspond to the
center of the template. The object centers the location slightly different
for templates with an odd or even number of pixels, (see the table below
for details). The object computes the location by shifting the template in
single-pixel increments throughout the interior of the image.
METRIC = step(H,I,T) computes the match metric values for input
image, I, with T as the template. This applies when you set the
OutputValue property to Metric matrix.
LOC = step(H,I,T,ROI) computes the location of the best template
match, LOC, in the specified region of interest, ROI. This applies when
you set the OutputValue property to Best match location and the
ROIInputPort property to true. The input ROI must be a four element
vector, [x y width height], where the first two elements represent the [x
y] coordinates of the upper-left corner of the rectangular ROI.
[LOC,ROIVALID] = step(H,I,T,ROI) computes the location of the best
template match, LOC, in the specified region of interest, ROI. The step
method also returns a logical flag ROIVALID indicating if the specified
ROI is outside the bounds of the input image I. This applies when you
set the OutputValue property to Best match location, and both the
ROIInputPort and ROIValidityOutputPort properties to true.
[LOC,NVALS,NVALID] = step(H,I,T) returns the location of the
best template match LOC, the metric values around the best match
NVALS, and a logical flag NVALID. A false value for NVALID indicates
that the neighborhood around the best match extended outside the
borders of the metric value matrix NVALS. This applies when you
2-839
vision.TemplateMatcher
2-840
vision.TemplateMatcher
Properties Metric
Metric used for template matching
2-841
vision.TemplateMatcher
2-842
vision.TemplateMatcher
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
2-843
vision.TemplateMatcher
2-844
vision.TemplateMatcher
2-845
vision.TemplateMatcher
htm=vision.TemplateMatcher;
hmi = vision.MarkerInserter('Size', 10, ...
'Fill', true, 'FillColor', 'White', 'Opacity', 0.75); I = imread('boa
% Input image
I = I(1:200,1:200,:);
imshow(T); title('Template');
figure; imshow(J); title('Marked target');
Algorithms This object implements the algorithm, inputs, and outputs described
on the Template Matching block reference page. The object properties
correspond to the block parameters.
2-846
vision.TemplateMatcher.clone
Syntax C = clone(H)
2-847
vision.TemplateMatcher.getNumInputs
Syntax N = getNumInputs(H)
2-848
vision.TemplateMatcher.getNumOutputs
Syntax N = getNumOutputs(H)
2-849
vision.TemplateMatcher.isLocked
Syntax TF = isLocked(H)
2-850
vision.TemplateMatcher.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-851
vision.TemplateMatcher.step
2-852
vision.TemplateMatcher.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-853
vision.TextInserter
Description The text inserter System object draws text in an image. The output
image can then be displayed or saved to a file. It can draw one or more
arbitrary ASCII strings at multiple locations in an image. The object
uses the FreeType 2.3.5 library, an open-source font engine, to produce
stylized text bitmaps. To learn more about the FreeType Project, visit
http://www.freetype.org/. The text inserter object does not support
character sets other than ASCII.
To insert text:
2 Call the step method with the input image, I, the text inserter
object, txtInserter, and any optional properties. See the syntax
below for using the step method.
2-854
vision.TextInserter
Properties Text
Text string to draw on image or video stream
Specify the text string to be drawn on image or video stream as
a single text string or a cell array of strings. The string(s) can
2-855
vision.TextInserter
2-856
vision.TextInserter
Opacity
Opacity of text
Specify the opacity of the text as numeric scalar between 0 and 1.
This property applies when you set the OpacitySource property
to Property. The default is 1. This property is tunable.
TransposedInput
Specifies if input image data order is row major
Set this property to true to indicate that the input image data
order is row major.
The default is false.
Font
Font face of text
Specify the font of the text as the available fonts installed on the
system.
FontSize
Font size in points
Specify the font size as any positive integer value. The default
is 12.
Antialiasing
Perform smoothing algorithm on text edges
Set this property to true to smooth the edges of the text. The
default is true.
2-857
vision.TextInserter
1
Set up text [red, green, blue] formatted color and [x y] location.
I = imread('peppers.png');
J = step(textInserter, I);
imshow(J);
2-858
vision.TextInserter
I = imread('peppers.png');
imshow(J);
I = imread('peppers.png');
2-859
vision.TextInserter
imshow(J);
2-860
vision.TextInserter.clone
Syntax C = clone(H)
2-861
vision.TextInserter.getNumInputs
Syntax N = getNumInputs(H)
2-862
vision.TextInserter.getNumOutputs
Syntax N = getNumOutputs(H)
2-863
vision.TextInserter.isLocked
Syntax TF = isLocked(H)
2-864
vision.TextInserter.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-865
vision.TextInserter.step
Description TXTIMG = step(H,IMG) draws the specified text onto input image IMG
and returns the modified image Y . The image IMG can either be an
M-by-N matrix of intensity values or an M-by-N-by-P array color video
signal where P is the number of color planes.
TXTIMG = step(H,IMG) draws the specified text onto input image IMG
and returns the modified image TXTIMG. The image IMG can either be an
M-by-N matrix of intensity values or an M-by-N-by-P array color video
signal where P is the number of color planes.
TXTIMG = step(H,IMG,CELLIDX) draws the text string selected by
index, CELLIDX, when you set the Text property to a cell array of
strings. For example, if you set the Text property to {’str1’,’str2’}, and
the CELLIDX property to 1, the step method inserts the string ’str1’ in
the image. Values of CELLIDX outside of valid range result in no text
drawn on the image.
TXTIMG = step(H,IMG,VARS) uses the data in VARS for variable
substitution, when the Text property contains ANSI C printf-style
format specifications (%d, %.2f, etc.). VARS is a scalar or a vector having
length equal to the number of format specifiers in each element in the
specified text string.
TXTIMG = step(H,IMG,COLOR) uses the given scalar or 3-element
vector COLOR for the text intensity or color respectively, when you set
the ColorSource property to Input port.
2-866
vision.TextInserter.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-867
vision.Variance
Properties RunningVariance
Enable calculation over successive calls to step method
Set this property to true to enable the calculation of the variance
over successive calls to the step method. The default is false.
ResetInputPort
Enable resetting via an input in running variance mode
Set this property to true to enable resetting the running variance.
When the property is set to true, a reset input must be specified
to the step method to reset the running variance. This property
applies when you set the RunningVariance property to true. The
default is false.
ResetCondition
Reset condition for running variance mode
2-868
vision.Variance
2-869
vision.Variance
Fixed-Point Properties
RoundingMethod
Rounding method for fixed-point operations
2-870
vision.Variance
2-871
vision.Variance
2-872
vision.Variance
img = im2single(rgb2gray(imread('peppers.png')));
hvar2d = vision.Variance;
var2d = step(hvar2d,img);
2-873
vision.Variance.clone
Syntax C = clone(H)
2-874
vision.Variance.getNumInputs
Syntax N = getNumInputs(H)
2-875
vision.Variance.getNumOutputs
Syntax N = getNumOutputs(H)
2-876
vision.Variance.isLocked
Syntax TF = isLocked(H)
2-877
vision.Variance.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-878
vision.Variance.reset
Syntax reset(H)
Description reset(H) resets the internal states of System object H to their initial
values.
2-879
vision.Variance.step
Syntax Y = step(H,X)
Y = step(H,X,R)
Y = step(H,X,ROI)
Y = step(H,X,LABEL,LABELNUMBERS)
[Y,FLAG] = step(H,X,ROI)
[Y,FLAG] = step(H,X,LABEL,LABELNUMBERS)
Description Y = step(H,X) computes the variance of input X. When you set the
RunningVariance property to true, the output Y corresponds to the
standard deviation of the input elements over successive calls to the
step method.
Y = step(H,X,R) computes the variance of the input elements X over
successive calls to the step method, and optionally resets its state
based on the value of the reset signal R, the ResetInputPort property
and the ResetCondition property. This option applies when you set the
RunningVariance property to true and the ResetInputPort to true.
Y = step(H,X,ROI) computes the variance of input image X within the
given region of interest ROI when you set the ROIProcessing property to
true and the ROIForm property to Lines, Rectangles or Binary mask.
Y = step(H,X,LABEL,LABELNUMBERS) computes the variance of input
image X for region labels contained in vector LABELNUMBERS, with matrix
LABEL marking pixels of different regions. This option applies when you
set the ROIProcessing property to true and the ROIForm property to
Label matrix.
[Y,FLAG] = step(H,X,ROI) also returns the output FLAG, which
indicates whether the given region of interest is within the image
bounds. This applies when you set both the ROIProcessing and the
ValidityOutputPort properties to true and the ROIForm property to
Lines, Rectangles or Binary mask.
[Y,FLAG] = step(H,X,LABEL,LABELNUMBERS) also returns the FLAG,
which indicates whether the input label numbers are valid. This applies
2-880
vision.Variance.step
Note The object performs an initialization the first time the step
method is executed. This initialization locks nontunable properties and
input specifications, such as dimensions, complexity, and data type
of the input data. If you change a nontunable property or an input
specification, the System object issues an error. To change nontunable
properties or inputs, you must first call the release method to unlock
the object.
2-881
vision.VideoPlayer
Description The VideoPlayer object can play a video or display image sequences.
Note If you own the MATLAB Coder product, you can generate C or
C++ code from MATLAB code in which an instance of this system object
is created. When you do so, the scope system object is automatically
declared as an extrinsic variable. In this manner, you are able to
see the scope display in the same way that you would see a figure
using the plot function, without directly generating code from it. For
the full list of system objects supporting code generation, see “Code
Generation Support, Usage Notes, and Limitations” in the MATLAB
Coder documentation.
1 Define and set up your video player object using the constructor.
2 Call the step method with the shape inserter object, textInserter,
and any optional properties. See the syntax below for using the step
method.
Properties Name
Caption display on video player window
2-882
vision.VideoPlayer
2-883
vision.VideoPlayer
videoFReader = vision.VideoFileReader('viplanedeparture.avi');
videoPlayer = vision.VideoPlayer;
Play video. Every call to the step method reads another frame.
while ~isDone(videoFReader)
frame = step(videoFReader);
step(videoPlayer,frame);
end
release(videoFReader);
release(videoPlayer);
2-884
vision.VideoPlayer.clone
Syntax C = clone(H)
2-885
vision.VideoPlayer.getNumInputs
Syntax N = getNumInputs(H)
2-886
vision.VideoPlayer.getNumOutputs
Syntax N = getNumOutputs(H)
2-887
vision.VideoPlayer.isLocked
Syntax TF = isLocked(H)
2-888
vision.VideoPlayer.release
Syntax release(H)
Note You can use the release method on a System object in code
generated from MATLAB, but once you release its resources, you cannot
use that System object again.
2-889
vision.VideoPlayer.reset
Syntax reset(H)
Description reset(H) resets the displayed frame number of the video player to zero.
2-890
vision.VideoPlayer.step
Syntax step(videoPlayer,I)
2-891
vision.VideoPlayer.show
Syntax show(H)
2-892
vision.VideoPlayer.hide
Syntax hide(H)
2-893
matlab.System
Description matlab.System is the base class for System objects. In your class
definition file, you must subclass your object from this base class (or
from another class that derives from this base class). Subclassing
allows you to use the implementation and service methods provided by
this base class to build your object. Type this syntax as the first line
of your class definition file to directly inherit from the matlab.System
base class, where ObjectName is the name of your object:
2-894
matlab.System
Attributes In addition to the attributes available for MATLAB objects, you can
apply the following attributes to any property of a custom System object.
2-895
matlab.System
methods (Access=protected)
% stepImpl method is called by the step method.
function y = stepImpl(~,x)
y = x + 1;
end
end
end
hAdder = AddOne;
x = 1;
y = step(hAdder,x)
properties (Nontunable)
InitialValue
2-896
matlab.System
end
2-897
matlab.System.cloneImpl
Syntax cloneImpl(obj)
Input obj
Arguments System object handle of object to clone.
methods (Access=protected)
function obj2 = cloneImpl(obj1)
s = saveObject (obj1);
obj2 = loadObject(s);
end
end
2-898
matlab.System.cloneImpl
2-899
matlab.System.getDiscreteStateImpl
Syntax s = getDiscreteStateImpl(obj)
Input obj
Arguments System object handle
Output s
Arguments Struct of state values.
methods (Access=protected)
function s = getDiscreteStateImpl(obj)
end
end
2-900
matlab.System.getDiscreteStateImpl
2-901
matlab.System.getInputNamesImpl
Input obj
Arguments System object handle
Output name1,name2,...
Arguments Names of the inputs for the specified object.
methods (Access=protected)
function varargout = getInputNamesImpl(obj)
numInputs = getNumInputs(obj);
varargout = cell(1,numInputs);
varargout{1} = 'upper';
2-902
matlab.System.getInputNamesImpl
if numInputs > 1
varargout{2} = 'lower';
end
end
end
2-903
matlab.System.getNumInputsImpl
Input obj
Arguments System object handle
Output num
Arguments Number of inputs expected by the step method for the specified
object.
Default: 1
2-904
matlab.System.getNumInputsImpl
methods (Access=protected)
function num = getNumInputsImpl(obj)
num = 2;
end
end
methods (Access=protected)
function num = getNumInputsImpl(~)
num = 0;
end
end
2-905
matlab.System.getNumOutputsImpl
Input obj
Arguments System object handle
Output num
Arguments Number of outputs to be returned by the step method for the
specified object.
2-906
matlab.System.getNumOutputsImpl
methods (Access=protected)
function num = getNumOutputsImpl(~)
num = 0;
end
end
2-907
matlab.System.getOutputNamesImpl
Input obj
Arguments System object handle
Output name1,name2,...
Arguments Names of the outputs for the specified object.
methods (Access=protected)
function outputName = getOutputNamesImpl(~)
outputName = 'count';
end
end
2-908
matlab.System.getOutputNamesImpl
2-909
matlab.System.infoImpl
Syntax s = infoImpl(obj,varargin)
Input obj
Arguments System object handle
varargin
Allows variable number of inputs
methods (Access=protected)
function s = infoImpl(obj)
s = struct('Count',obj.pCount);
end
end
2-910
matlab.System.isInactivePropertyImpl
Input obj
Arguments System object handle
prop
Public, non-state property name
Output flag
Arguments Logical scalar value indicating whether the input property prop is
inactive for the current object configuration.
methods (Access=protected)
function flag = isInactivePropertyImpl(obj,propertyName)
2-911
matlab.System.isInactivePropertyImpl
if strcmp(propertyName,'InitialValue')
flag = obj.UseRandomInitialValue;
else
flag = false;
end
end
end
2-912
matlab.System.loadObjectImpl
Syntax loadObjectImpl(obj)
Input obj
Arguments System object handle
methods(Access=protected)
function loadObjectImpl(obj, s, wasLocked)
% Load child System objects
obj.child = matlab.System.loadObject(s.child);
2-913
matlab.System.loadObjectImpl
[email protected](obj,s,wasLocked);
end
end
2-914
matlab.System.processTunedPropertiesImpl
Syntax processTunedPropertiesImpl(obj)
You cannot modify any tunable properties in this method if its System
object will be used in the Simulink MATLAB System block.
Tips Use this method when a tunable property affects a different property
value. For example, two property values determine when to calculate
a lookup table. You want to perform that calculation when either
property changes. You also want the calculation to be done only once if
both properties change before the next call to the step method.
Input obj
Arguments System object handle
methods (Access=protected)
function processTunedPropertiesImpl(obj)
% Generate a lookup table of note frequencies
obj.pLookupTable = obj.MiddleC * (1+log(1:obj.NumNotes)/log(12))
2-915
matlab.System.processTunedPropertiesImpl
end
end
2-916
matlab.System.releaseImpl
Syntax releaseImpl(obj)
Input obj
Arguments System object handle
methods (Access=protected)
function releaseImpl(obj)
fclose(obj.pFileID);
end
end
2-917
matlab.System.resetImpl
Syntax resetImpl(obj)
Description resetImpl(obj) defines the state reset equations for the System object.
Typically you reset the states to a set of initial values. This is useful for
initialization at the start of simulation.
resetImpl is called by the reset method. It is also called by the setup
method, after the setupImpl method.
You cannot modify any tunable properties in this method if its System
object will be used in the Simulink MATLAB System block.
Input obj
Arguments System object handle
methods (Access=protected)
function resetImpl(obj)
obj.pCount = 0;
end
end
2-918
matlab.System.saveObjectImpl
Syntax saveObjectImpl(obj)
Input obj
Arguments System object handle
methods(Access=protected)
function s = saveObjectImpl(obj)
2-919
matlab.System.saveObjectImpl
s = [email protected](obj);
s.child = matlab.System.saveObject(obj.child);
s.protected = obj.protected;
s.pdependentprop = obj.pdependentprop;
if isLocked(obj)
s.state = obj.state;
end
end
end
2-920
matlab.System.setProperties
Syntax setProperties(obj,numargs,name1,value1,name2,value2,...)
setProperties(obj,numargs,arg1,...,argm,name1,value1,name2,value2,...,
'ValueOnlyPropName1','ValueOnlyPropName2',...,
'ValueOnlyPropNamem')
Description setProperties(obj,numargs,name1,value1,name2,value2,...)
provides the name-value pair inputs to the System object constructor.
Use this syntax if every input must specify both name and value.
setProperties(obj,numargs,arg1,...,argm,name1,value1,name2,value2,...,
'ValueOnlyPropName1','ValueOnlyPropName2',...,
'ValueOnlyPropNamem') provides the value-only inputs, followed by
the name-value pair inputs to the System object during object
construction. Use this syntax if you want to allow users to specify one
or more inputs by their values only.
Input obj
Arguments System objectSystem object handle
numargs
Number of inputs passed in by the object constructor
name1,name2,...
Name of property
value1,value2,...
Value of the property
arg1,arg2,...
2-921
matlab.System.setProperties
methods
function obj = MyFile(varargin)
setProperties(obj,nargin,varargin{:},'VProp1','VProp2');
end
end
2-922
matlab.System.setupImpl
Syntax setupImpl(obj)
setupImpl(obj,input1,input2,...)
Note You can omit this method from your class definition file if your
System object does not require any setup tasks.
Do not use setupImpl to initialize or reset states. For states, use the
resetImpl method.
You cannot modify any tunable properties in this method if its System
object will be used in the Simulink MATLAB System block.
2-923
matlab.System.setupImpl
Input obj
Arguments System object handle
input1,input2,...
Inputs to the stepImpl method
methods (Access=protected)
function setupImpl(obj)
obj.pFileID = fopen(obj.Filename,'wb');
if obj.pFileID < 0
error('Opening the file failed');
end
end
end
2-924
matlab.System.setupImpl
end
function y = stepImpl(obj,u)
y = obj.myState;
obj.myState = u;
end
end
end
2-925
matlab.System.stepImpl
Tips The number of input arguments and output arguments must match the
values returned by the getNumInputsImpl and getNumOutputsImpl
methods, respectively
Input obj
Arguments System object handle
input1,input2,...
Inputs to the step method
Output output
Arguments Output returned from the step method.
methods (Access=protected)
function [y1,y2] = stepImpl(obj,x1,x2)
y1 = x1 + 1;
2-926
matlab.System.stepImpl
y2 = x2 + 1;
end
end
2-927
matlab.System.validateInputsImpl
Syntax validateInputsImpl(obj,input1,input2,...)
Input obj
Arguments System object handle
input1,input2,...
Inputs to the setup method
methods (Access=protected)
function validateInputsImpl(~,x)
if ~isnumeric(x)
error('Input must be numeric');
end
end
end
2-928
matlab.System.validateInputsImpl
2-929
matlab.System.validatePropertiesImpl
Syntax validatePropertiesImpl(obj)
Input obj
Arguments System object handle
methods (Access=protected)
function validatePropertiesImpl(obj)
if obj.useIncrement && obj.increment < 0
error('The increment value must be positive');
end
end
end
2-930
matlab.System.validatePropertiesImpl
2-931
matlab.system.display.Header
Syntax matlab.system.display.Header(N1,V1,...Nn,Vn)
matlab.system.display.Header(Obj,...)
You can use mfilename('class') from within this method to get the
name of the System object. If you set any Name-Value pairs, those
property values override the default settings.
2-932
matlab.system.display.Header
methods(Static,Access=protected)
function header = getHeaderImpl
header = matlab.system.display.Header(mfilename('class'), ...
'Title','AlternativeTitle',...
'Text','An alternative class description');
end
end
2-933
matlab.system.display.Header.getHeaderImpl
Description header = getHeaderImpl returns the header to display for the System
object. If you do not specify the getHeaderImpl method, no title or text
appears for the header in the block dialog box.
getHeaderImpl is called by the MATLAB System block
Note You must set Access=protected and Static for this method.
Output header
Arguments Header text
methods(Static,Access=protected)
function header = getHeaderImpl
header = matlab.system.display.Header('EnhancedCounter',...
'Title','Enhanced Counter');
end
end
2-934
matlab.system.display.Section
Syntax matlab.system.display.Section(N1,V1,...Nn,Vn)
matlab.system.display.Section(Obj,...)
Note Certain properties are not eligible for display either in a dialog
box or in the System object summary on the command-line. Property
types that cannot be displayed are: hidden, abstract, private or
protected access, discrete state, and continuous state. Dependent
properties do not display in a dialog box, but do display in the
command-line summary.
2-935
matlab.system.display.Section
You can use mfilename('class') from within this method to get the
name of the System object. If you set any Name-Value pairs, those
property values override the default settings.
Methods
methods(Static,Access=protected)
function groups = getPropertyGroupsImpl
valueGroup = matlab.system.display.Section(...
'Title','Value parameters',...
'PropertyList',{'StartValue','EndValue'});
thresholdGroup = matlab.system.display.Section(...
'Title','Threshold parameters',...
'PropertyList',{'Threshold','UseThreshold'});
groups = [valueGroup,thresholdGroup];
end
end
When you specify the System object in the MATLAB System block, the
resulting dialog box appears as follows.
2-936
matlab.system.display.Section
2-937
matlab.system.display.Section.getPropertyGroupsImpl
Note You must set Access=protected and Static for this method.
Output group
Arguments Property group or groups
methods(Static, Access=protected)
function groups = getPropertyGroupsImpl
2-938
matlab.system.display.Section.getPropertyGroupsImpl
valueGroup = matlab.system.display.Section(...
'Title','Value parameters',...
'PropertyList',{'StartValue','EndValue'});
thresholdGroup = matlab.system.display.Section(...
'Title','Threshold parameters',...
'PropertyList',{'Threshold','UseThreshold'});
mainGroup = matlab.system.display.SectionGroup(...
'Title','Main', ...
'Sections',[valueGroup,thresholdGroup]);
initGroup = matlab.system.display.SectionGroup(...
'Title','Initial conditions', ...
'PropertyList',{'IC1','IC2','IC3'});
groups = [mainGroup,initGroup];
end
end
2-939
matlab.system.display.Section.getPropertyGroupsImpl
2-940
matlab.system.display.Section.getPropertyGroupsImpl
2-941
matlab.system.display.SectionGroup
Syntax matlab.system.display.SectionGroup(N1,V1,...Nn,Vn)
matlab.system.display.SectionGroup(Obj,...)
2-942
matlab.system.display.SectionGroup
You can use mfilename('class') from within this method to get the
name of the System object. If you set any Name-Value pairs, those
property values override the default settings.
Methods
thresholdGroup = matlab.system.display.Section(...
'Title','Threshold parameters',...
'PropertyList',{'Threshold','UseThreshold'});
mainGroup = matlab.system.display.SectionGroup(...
'Title','Main', ...
'Sections',[valueGroup,thresholdGroup]);
initGroup = matlab.system.display.SectionGroup(...
'Title','Initial conditions', ...
'PropertyList',{'IC1','IC2','IC3'});
groups = [mainGroup,initGroup];
end
end
2-943
matlab.system.display.SectionGroup
The resulting dialog appears as follows when you add the object to
Simulink with the MATLAB System block.
2-944
matlab.system.display.SectionGroup
2-945
matlab.system.mixin.CustomIcon
2-946
matlab.system.mixin.CustomIcon.getIconImpl
Input obj
Arguments System object handle
Output icon
Arguments String or cell array of strings to display as the block icon. Each
cell is displayed as a separate line.
methods (Access=protected)
function icon = getIconImpl(~)
icon = {'Enhanced','Counter'};
end
end
2-947
matlab.system.mixin.CustomIcon.getIconImpl
2-948
matlab.system.mixin.FiniteSource
2-949
matlab.system.mixin.FiniteSource.isDoneImpl
Input obj
Arguments System object handle
Output status
Arguments Logical value, true or false, that indicates if an end-of-data
condition has occurred or not, respectively.
methods (Access=protected)
function bdone = isDoneImpl(obj)
bdone = obj.NumIters==8;
end
end
2-950
matlab.system.mixin.FiniteSource.isDoneImpl
2-951
matlab.system.mixin.Nondirect
• System object supports code generation and does not inherit from
the Propagates mixin — Simulink automatically infers the direct
feedthrough settings from the System object code.
• System object supports code generation and inherits from the
Propagates mixin — Simulink does not automatically infer the
direct feedthrough settings. Instead, it uses the value returned by
the isInputDirectFeedthroughImpl method.
• System object does not support code generation — Default
isInputDirectFeedthrough method returns false, indicating that
direct feedthrough is not enabled. To override the default behavior,
implement the isInputDirectFeedthroughImpl method in your
class definition file.
2-952
matlab.system.mixin.Nondirect
To use this mixin, you must subclass from this class in addition to
subclassing from the matlab.System base class. Type the following
syntax as the first line of your class definition file, where ObjectName
is the name of your object:
2-953
matlab.system.mixin.Nondirect.isInputDirectFeedthroughImpl
Description [flag1,...,flagN] =
isInputDirectFeedthroughImpl(obj,u1,u2,...,uN) indicates
whether each input is a direct feedthrough input. If direct feedthrough
is true, the output depends on the input at each time instant.
• System object supports code generation and does not inherit from
the Propagates mixin — Simulink automatically infers the direct
feedthrough settings from the System object code.
• System object supports code generation and inherits from the
Propagates mixin — Simulink does not automatically infer the
direct feedthrough settings. Instead, it uses the value returned by
the isInputDirectFeedthroughImpl method.
• System object does not support code generation — Default
isInputDirectFeedthrough method returns false, indicating that
direct feedthrough is not enabled. To override the default behavior,
implement the isInputDirectFeedthroughImpl method in your
class definition file.
2-954
matlab.system.mixin.Nondirect.isInputDirectFeedthroughI
Input obj
Arguments System object handle
u1,u2,...,uN
Specifications of the inputs to the algorithm or step method.
Output flag1,...,flagN
Arguments Logical value or either true or false. This value indicates
whether the corresponding input is direct feedthrough or not,
respectively. The number of outputs must match the number of
outputs returned by the getNumOutputs method.
methods (Access=protected)
function flag = isInputDirectFeedthroughImpl(~,~)
flag = false;
end
end
2-955
matlab.system.mixin.Nondirect.outputImpl
You cannot modify any tunable properties in this method if its System
object will be used in the Simulink MATLAB System block.
Input obj
Arguments System object handle
u1,u2,...uN
Inputs from the algorithm or step method. The number of inputs
must match the number of inputs returned by the getNumInputs
method. Nondirect feedthrough inputs are ignored during normal
execution of the System object. However, for code generation, you
must provide these inputs even if they are empty.
Output y1,y2,...yN
Arguments Outputs calculated from the specified algorithm. The number
of outputs must match the number of outputs returned by the
getNumOutputs method.
2-956
matlab.system.mixin.Nondirect.outputImpl
methods (Access=protected)
function [y] = outputImpl(obj, ~)
y = obj.PreviousInput(end);
end
end
2-957
matlab.system.mixin.Nondirect.updateImpl
Syntax updateImpl(obj,u1,u2,...,uN)
You cannot modify any tunable properties in this method if its System
object will be used in the Simulink MATLAB System block.
Input obj
Arguments System object handle
u1,u2,...uN
Inputs to the algorithm or step method. The number of inputs
must match the number of inputs returned by the getNumInputs
method.
methods (Access=protected)
2-958
matlab.system.mixin.Nondirect.updateImpl
function updateImpl(obj,u)
obj.PreviousInput = [u obj.PreviousInput(1:end-1)];
end
end
2-959
matlab.system.mixin.Propagates
2-960
matlab.system.mixin.Propagates
Note If your System object has exactly one input and one output
and no discrete property states, you do not have to implement any of
these methods. Default values are used when you subclass from the
matlab.system.mixin.Propagates mixin.
2-961
matlab.system.mixin.Propagates.getDiscreteStateSpecificationI
Input obj
Arguments System object handle
name
Name of discrete state property of the System object
Output sz
Arguments Vector containing the length of each dimension of the property.
Default: [1 1]
dt
2-962
matlab.system.mixin.Propagates.getDiscreteStateSpecifica
Default: double
cp
Complexity of the property as a scalar, logical value, where true
= complex and false = real.
Default: false
methods (Access=protected)
function [sz,dt,cp] = getDiscreteStateSpecificationImpl(~,name)
sz = [1 1];
dt = 'double';
cp = false;
end
end
2-963
matlab.system.mixin.Propagates.getOutputDataTypeImpl
Input obj
Arguments System object handle
Output dt_1,dt_2,...
Arguments Data type of the property. For built-in data types, dt is a string.
For fixed-point data types, dt is a numerictype object.
2-964
matlab.system.mixin.Propagates.getOutputDataTypeImpl
methods (Access=protected)
function dt_1 = getOutputDataTypeImpl(~)
dt_1 = 'double';
end
end
2-965
matlab.system.mixin.Propagates.getOutputSizeImpl
Input obj
Arguments System object handle
Output sz_1,sz_2,...
Arguments Vector containing the size of each output port.
2-966
matlab.system.mixin.Propagates.getOutputSizeImpl
methods (Access=protected)
function sz_1 = getOutputSizeImpl(obj)
sz_1 = [1 1];
end
end
2-967
matlab.system.mixin.Propagates.isOutputComplexImpl
Input obj
Arguments System object handle
Output cp_1,cp_2,...
Arguments Logical, scalar value indicating whether the specific output port is
complex (true) or real (false).
2-968
matlab.system.mixin.Propagates.isOutputComplexImpl
2-969
matlab.system.mixin.Propagates.isOutputFixedSizeImpl
Input obj
Arguments System object handle
Output flag_1,flag2,...
Arguments Logical, scalar value indicating whether the specific output port is
fixed size (true) or variable size (false).
2-970
matlab.system.mixin.Propagates.isOutputFixedSizeImpl
methods (Access=protected)
function c1 = isOutputFixedSizeImpl(obj)
c1 = true;
end
end
2-971
matlab.system.mixin.Propagates.propagatedInputComplexity
Input obj
Arguments System object handle
index
Index of the desired step method input
Output flag
Arguments Whether the specified input argument is complex-valued
2-972
matlab.system.mixin.Propagates.propagatedInputComple
methods (Access=protected)
function outcomplx = isOutputComplexImpl(obj)
outcomplx = propagatedInputComplexity(obj,2);
end
end
2-973
matlab.system.mixin.Propagates.propagatedInputDataType
Syntax dt = propagatedInputDataType(obj,index)
Input obj
Arguments System object handle
index
Index of the desired step method input
Output dt
Arguments String, or numerictype object for fixed-point inputs, indicating the
data type of the object’s input argument
2-974
matlab.system.mixin.Propagates.propagatedInputDataTy
methods (Access=protected)
function dt = getOutputDataTypeImpl(obj)
if strcmpi(propagatedInputDataType(obj,2),'double')
dt = 'int32';
else
dt = propagatedInputDataType(obj,2);
end
end
end
2-975
matlab.system.mixin.Propagates.propagatedInputFixedSize
Input obj
Arguments System object handle
index
Index of the desired step method input
Output flag
Arguments Whether the specified input argument is fixed-size or not
2-976
matlab.system.mixin.Propagates.propagatedInputFixedSi
methods (Access=protected)
function outtype = isOutputFixedSizeImpl(obj)
outtype = propagatedInputFixedSize(obj,3)
end
end
2-977
matlab.system.mixin.Propagates.propagatedInputSize
Syntax sz = propagatedInputSize(obj,index)
Input obj
Arguments System object handle
index
Index of the desired step method input
Output sz
Arguments Size of the specified input
methods (Access=protected)
2-978
matlab.system.mixin.Propagates.propagatedInputSize
2-979
matlab.system.StringSet
• The string property that holds the current string can have any name.
• The property that holds the StringSet must use the same name as
the string property with the suffix “Set” appended to it. The string
set property is an instance of the matlab.system.StringSet class.
• Valid strings, defined in the StringSet, must be declared using a cell
array. The cell array cannot be empty nor can it have any empty
strings. Valid strings must be unique and are case-insensitive.
• The string property must be set to a valid StringSet value.
properties
Flavor='Chocolate';
end
properties (Hidden,Transient)
FlavorSet = ...
matlab.system.StringSet({'Vanilla','Chocolate'});
2-980
matlab.system.StringSet
end
2-981
matlab.system.StringSet
2-982
3
Functions Alphabetical
assignDetectionsToTracks
cameraCalibrator
configureKalmanFilter
detectBRISKFeatures
detectCheckerboardPoints
detectFASTFeatures
detectHarrisFeatures
detectMinEigenFeatures
detectMSERFeatures
detectSURFFeatures
disparity
epipolarLine
estimateCameraParameters
estimateFundamentalMatrix
estimateGeometricTransform
estimateUncalibratedRectification
extractFeatures
extractHOGFeatures
extrinsics
generateCheckerboardPoints
integralFilter
integralImage
insertMarker
insertObjectAnnotation
insertShape
insertText
isEpipoleInImage
isfilterseparable
3 Functions Alphabetical
lineToBorderPoints
matchFeatures
mplay
ocr
reconstructScene
rectifyStereoImages
showExtrinsics
showMatchedFeatures
showReprojectionErrors
trainCascadeObjectDetector
trainingImageLabeler
undistortImage
vision.getCoordinateSystem
vision.setCoordinateSystem
visionlib
3-2
assignDetectionsToTracks
Syntax [assignments,unassignedTracks,
unassignedDetections] = assignDetectionsToTracks( costMatrix,
costOfNonAssignment)
[assignments,unassignedTracks,
unassignedDetections] = assignDetectionsToTracks(costMatrix,
unassignedTrackCost,unassignedDetectionCost)
[assignments,unassignedTracks, unassignedDetections]
= assignDetectionsToTracks(costMatrix,
unassignedTrackCost,unassignedDetectionCost) specifies
the cost of unassigned tracks and detections separately. The
unassignedTrackCost must be a scalar value, or an M-element
vector, where M represents the number of tracks. For the M-element
vector, each element represents the cost of not assigning any detection
to that track. The unassignedDetectionCost must be a scalar value
or an N-element vector, where N represents the number of detections.
Code Generation Support:
Compile-time constant input: No restriction
Supports MATLAB Function block: Yes
“Code Generation Support, Usage Notes, and Limitations”
3-3
assignDetectionsToTracks
3-4
assignDetectionsToTracks
3-5
assignDetectionsToTracks
Data Types
int8 | uint8 | int16 | uint16 | int32 | uint32 | single |
double
3-6
assignDetectionsToTracks
3-7
assignDetectionsToTracks
Data Types
int8 | uint8 | int16 | uint16 | int32 | uint32 | single |
double
3-8
assignDetectionsToTracks
3-9
assignDetectionsToTracks
Data Types
int8 | uint8 | int16 | uint16 | int32 | uint32 | single |
double
3-10
assignDetectionsToTracks
3-11
assignDetectionsToTracks
Data Types
int8 | uint8 | int16 | uint16 | int32 | uint32 | single |
double
3-12
assignDetectionsToTracks
Set the locations of the objects detected in the current frame. For this
example, there are 2 tracks and 3 new detections. Thus, at least one of
the detections is unmatched, which can indicate a new track.
cost = zeros(size(predictions,1),size(detections,1));
for i = 1:size(predictions, 1)
diff = detections - repmat(predictions(i, :), [size(detections,
cost(i, :) = sqrt(sum(diff .^ 2, 2));
end
3-13
assignDetectionsToTracks
end
xlim([0, 4]);
ylim([0, 4]);
References
[1] Miller, Matt L., Harold S. Stone, and Ingemar J. Cox, “Optimizing
Murty’s Ranked Assignment Method,” IEEE Transactions on Aerospace
and Electronic Systems, 33(3), 1997.
3-14
cameraCalibrator
Syntax cameraCalibrator
cameraCalibrator CLOSE
Description cameraCalibrator invokes a camera calibration app. You can use this
app can be used to estimate camera intrinsic and extrinsic parameters.
This app can also be used to compute parameters needed to remove the
effects of lens distortion from an image.
cameraCalibrator CLOSE closes all open apps.
cameraCalibrator
3-15
configureKalmanFilter
Syntax kalmanFilter =
configureKalmanFilter(MotionModel,InitialLocation,
InitialEstimateError,MotionNoise,MeasurementNoise)
Description kalmanFilter =
configureKalmanFilter(MotionModel,InitialLocation,
InitialEstimateError,MotionNoise,MeasurementNoise) returns a
vision.KalmanFilter object configured to track a physical object. This
object moves with constant velocity or constant acceleration in an
M-dimensional Cartesian space. The function determines the number
of dimensions, M, from the length of the InitialLocation vector.
This function provides a simple approach for configuring the
vision.KalmanFilter object for tracking a physical object in a
Cartesian coordinate system. The tracked object may move with either
constant velocity or constant acceleration. The statistics are the same
along all dimensions. If you need to configure a Kalman filter with
different assumptions, use the vision.KalmanFilter object directly.
3-16
configureKalmanFilter
The value of this property affects the Kalman filter for the first few
detections. Later, the estimate error is determined by the noise and
input data. A larger value for the initial estimate error helps the
Kalman filter to adapt to the detection results faster. However, a larger
value also prevents the Kalman filter from removing noise from the
first few detections.
Specify the initial estimate error as a two-element vector for constant
velocity or a three-element vector for constant acceleration:
MotionModel InitialEstimateError
ConstantVelocity [LocationVariance, VelocityVariance]
ConstantAcceleration [LocationVariance, VelocityVariance,
AccelerationVariance]
Data Types
double | single
3-17
configureKalmanFilter
MotionModel InitialEstimateError
ConstantVelocity [LocationVariance, VelocityVariance]
ConstantAcceleration [LocationVariance, VelocityVariance,
AccelerationVariance]
Data Types
double | single
3-18
configureKalmanFilter
3-19
configureKalmanFilter
[InitialLocation(1), 0, 0, ...,
`ConstantAcceleration'
InitialLocation(M), 0, 0]
videoReader = vision.VideoFileReader('singleball.avi');
videoPlayer = vision.VideoPlayer('Position', [100, 100, 500, 400]);
foregroundDetector = vision.ForegroundDetector('NumTrainingFrames', 10, '
blobAnalyzer = vision.BlobAnalysis('AreaOutputPort', false, 'MinimumBlobA
Process each video frame to detect and track the ball. After reading
the current video frame, the example searches for the ball by using
background subtraction and blob analysis. When the ball is first
detected, the example creates a Kalman filter. The Kalman filter
determines the ball’s location, whether it is detected or not. If the ball is
detected, the Kalman filter first predicts its state at the current video
frame. The filter then uses the newly detected location to correct the
state, producing a filtered location. If the ball is missing, the Kalman
3-20
configureKalmanFilter
filter solely relies on its previous state to predict the ball’s current
location.
if ~isTrackInitialized
if isObjectDetected
kalmanFilter = configureKalmanFilter('ConstantAcceleration',d
isTrackInitialized = true;
end
label = ''; circle = [];
else
if isObjectDetected
% Reduce the measurement noise by calling predict, then corre
predict(kalmanFilter);
trackedLocation = correct(kalmanFilter, detectedLocation(1,:)
label = 'Corrected';
else % Object is missing
trackedLocation = predict(kalmanFilter);
label = 'Predicted';
end
circle = [trackedLocation, 5];
end
Release resources
release(videoPlayer);
3-21
configureKalmanFilter
release(videoReader);
3-22
detectBRISKFeatures
3-23
detectBRISKFeatures
3-24
detectBRISKFeatures
I = imread('cameraman.tif');
points = detectBRISKFeatures(I);
3-25
detectBRISKFeatures
References
[1] Leutenegger, S., M. Chli and R. Siegwart. “BRISK: Binary Robust
Invariant Scalable Keypoints”, Proceedings of the IEEE International
Conference, ICCV, 2011.
3-26
detectCheckerboardPoints
[imagePoints,boardSize,
imagesUsed] = detectCheckerboardPoints(imageFileNames)
[imagePoints,boardSize,imagesUsed] =
detectCheckerboardPoints(images)
[imagePoints,boardSize,
pairsUsed] = detectCheckerboardPoints(imageFileNames1,
imageFileNames2)
[imagePoints,boardSize,pairsUsed] =
detectCheckerboardPoints(images1,
images2)
[imagePoints,boardSize, imagesUsed] =
detectCheckerboardPoints(imageFileNames) detects a checkerboard
pattern in a set of input images, provided as an array of file names.
[imagePoints,boardSize,imagesUsed] =
detectCheckerboardPoints(images) detects a checkerboard pattern
in a set of input images, provided as an array of grayscale or truecolor
images.
[imagePoints,boardSize, pairsUsed] =
detectCheckerboardPoints(imageFileNames1, imageFileNames2)
detects a checkerboard pattern in stereo pairs of images, provided as
cell arrays of file names.
3-27
detectCheckerboardPoints
[imagePoints,boardSize,pairsUsed] =
detectCheckerboardPoints(images1, images2) detects a
checkerboard pattern in stereo pairs of images, provided as arrays of
grayscale or truecolor images.
images - Images
height-by-width-by-color channel-by-number of frames array
Images, specified as an H-by-W-by-B-by-F array containing a set of
grayscale or truecolor images. The input dimensions are:
3-28
detectCheckerboardPoints
3-29
detectCheckerboardPoints
For stereo pairs, imagePoints(:,:,:,1) are the points from the first set
of images, and imagePoints(:,:,:,2) are the points from the second set
of images. The output contains M number of [x y] coordinates. Each
coordinate represents a point where square corners are detected on
the checkerboard. The number of points the function returns depends
on the value of boardSize, which indicates the number of squares
detected. The function detects the points with sub-pixel accuracy.
The function calculates the number of points, M, as follows:
M = prod(boardSize-1).
imagePoints = []
boardSize = [0,0]
When you specify the imageFileNames input, the function can return
imagePoints as an M-by-2-by-N array. In this array, N represents the
number of images in which a checkerboard is detected.
3-30
detectCheckerboardPoints
3-31
detectCheckerboardPoints
3-32
detectCheckerboardPoints
3-33
detectCheckerboardPoints
3-34
detectCheckerboardPoints
for i = 1:5
imageFileName = sprintf('image%d.tif', i);
imageFileNames{i} = fullfile(matlabroot, 'toolbox', 'vision',...
'visiondemos', 'calibration', 'webcam', imageFileName);
end
3-35
detectCheckerboardPoints
imageFileNames = imageFileNames(imagesUsed);
for i = 1:numel(imageFileNames)
I = imread(imageFileNames{i});
subplot(2, 2, i);
imshow(I); hold on; plot(imagePoints(:,1,i), imagePoints(:,2,i), 'r
end
3-36
detectCheckerboardPoints
numImages = 4;
images1 = cell(1, numImages);
images2 = cell(1, numImages);
for i = 1:numImages
images1{i} = fullfile(matlabroot, 'toolbox', 'vision', 'vision
images2{i} = fullfile(matlabroot, 'toolbox', 'vision', 'vision
3-37
detectCheckerboardPoints
end
images1 = images1(pairsUsed);
figure;
for i = 1:numel(images1)
I = imread(images1{i});
subplot(2, 2, i);
imshow(I); hold on; plot(imagePoints(:,1,i,1), imagePoints(:,2,
end
annotation('textbox', [0 0.9 1 0.1], 'String', 'Camera 1', 'EdgeColor
3-38
detectCheckerboardPoints
images2 = images2(pairsUsed);
figure;
for i = 1:numel(images2)
I = imread(images2{i});
subplot(2, 2, i);
imshow(I); hold on; plot(imagePoints(:,1,i,2), imagePoints(:
end
3-39
detectCheckerboardPoints
3-40
detectFASTFeatures
Purpose Detect corners using FAST algorithm and return cornerPoints object
3-41
detectFASTFeatures
3-42
detectFASTFeatures
I = imread('cameraman.tif');
corners = detectFASTFeatures(I);
3-43
detectFASTFeatures
References
[1] Rosten, E., and T. Drummond. "Fusing Points and Lines for
High Performance Tracking," Proceedings of the IEEE International
Conference on Computer Vision, Vol. 2 (October 2005): pp. 1508–1511.
Related • “Find Corner Points using the Eigenvalue Algorithm” on page 3-51
Examples • “Find Corner Points Using the Harris–Stephens Algorithm” on page
3-47
3-44
detectHarrisFeatures
3-45
detectHarrisFeatures
3-46
detectHarrisFeatures
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
I = checkerboard;
corners = detectHarrisFeatures(I);
3-47
detectHarrisFeatures
References
[1] Harris, C., and M. Stephens, "A Combined Corner and Edge
Detector," Proceedings of the 4th Alvey Vision Conference, August 1988,
pp. 147-151.
Related • “Find Corner Points using the Eigenvalue Algorithm” on page 3-51
Examples • “Find Corner Points in an Image Using the FAST Algorithm” on
page 3-43
3-48
detectMinEigenFeatures
3-49
detectMinEigenFeatures
3-50
detectMinEigenFeatures
I = checkerboard;
corners = detectMinEigenFeatures(I);
3-51
detectMinEigenFeatures
References
[1] Shi, J., and C. Tomasi, "Good Features to Track," Proceedings of the
IEEE Conference on Computer Vision and Pattern Recognition, June
1994, pp. 593–600.
3-52
detectMSERFeatures
3-53
detectMSERFeatures
3-54
detectMSERFeatures
I = imread('cameraman.tif');
regions = detectMSERFeatures(I);
Visualize MSER regions which are described by pixel lists stored inside the
returned ’regions’ object.
3-55
detectMSERFeatures
3-56
detectMSERFeatures
3-57
detectMSERFeatures
The MSER object checks the variation of the region area size between
different intensity thresholds. The variation must be less than the
value of the MaxAreaVariation parameter to be considered stable.
At a high level, MSER can be explained, by thinking of the intensity
profile of an image representing a series of buckets. Imagine the tops of
the buckets flush with the ground, and a hose turned on at one of the
buckets. As the water fills into the bucket, it overflows and the next
bucket starts filling up. Smaller regions of water join and become bigger
bodies of water, and finally the whole area gets filled. As water is filling
up into a bucket, it is checked against the MSER stability criterion.
Regions appear, grow and merge at different intensity thresholds.
3-58
detectMSERFeatures
References
[1] Nister, D., and H. Stewenius, "Linear Time Maximally Stable
Extremal Regions", Lecture Notes in Computer Science. 10th European
Conference on Computer Vision, Marseille, France: 2008, no. 5303,
pp. 183–196.
[2] Matas, J., O. Chum, M. Urba, and T. Pajdla. "Robust wide baseline
stereo from maximally stable extremal regions." Proceedings of British
Machine Vision Conference, pages 384-396, 2002.
3-59
detectSURFFeatures
3-60
detectSURFFeatures
3-61
detectSURFFeatures
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
3-62
detectSURFFeatures
[2] Herbert, B., A. Ess, T. Tuytelaars, and L. Van Gool, SURF: “Speeded
Up Robust Features”, Computer Vision and Image Understanding
(CVIU), Vol. 110, No. 3, pp. 346--359, 2008.
3-63
detectSURFFeatures
3-64
disparity
I2 - Input image 2
M-by-N 2-D grayscale image
3-65
disparity
3-66
disparity
3-67
disparity
3-68
disparity
3-69
disparity
2 Compute the disparity for each of the pixels by using block matching
and the sum of absolute differences (SAD).
I1 = rgb2gray(imread('scene_left.png'));
I2 = rgb2gray(imread('scene_right.png'));
figure; imshowpair(I1,I2,'ColorChannels','red-cyan');
title('Red-cyan composite view of the stereo images');
3-70
disparity
Show the disparity map. Brighter pixels indicate objects which are closer
to the camera.
figure; imshow(mat2gray(disparityMap));
3-71
disparity
References
[1] Konolige, K., Small Vision Systems: Hardware and Implementation,
Proceedings of the 8th International Symposium in Robotic Research,
pages 203-212, 1997.
3-72
disparity
3-73
epipolarLine
Input F
Arguments A 3-by-3 fundamental matrix. If P1 represents a point in the first image
I1 that corresponds to P2, a point in the second image I2, then:
[P2,1] * F * [P1,1]’ = 0
F must be double or single.
points
An M-by-2 matrix, where each row contains the x and y coordinates of a
point in the image. M represents the number of points.
points must be a double, single, or integer value.
Output lines
Arguments An M-by-3 matrix, where each row must be in the format, [A,B,C]. This
corresponds to the definition of the line:
3-74
epipolarLine
A * x + B * y + C = 0.
M represents the number of lines.
Compute This example shows you how to compute the fundamental matrix. It uses
Fundamental the least median of squares method to find the inliers.
Matrix
The points, matched_points1 and matched_points2, have been putatively
matched.
load stereoPointPairs
[fLMedS, inliers] = estimateFundamentalMatrix(matchedPoints1, matc
I1 = imread('viprectification_deskLeft.png');
figure;
subplot(121); imshow(I1);
title('Inliers and Epipolar Lines in First Image'); hold on;
plot(matchedPoints1(inliers,1), matchedPoints1(inliers,2), 'go')
3-75
epipolarLine
Compute the intersection points of the lines and the image border.
3-76
epipolarLine
I2 = imread('viprectification_deskRight.png');
subplot(122); imshow(I2);
title('Inliers and Epipolar Lines in Second Image'); hold on;
plot(matchedPoints2(inliers,1), matchedPoints2(inliers,2), 'go')
3-77
epipolarLine
truesize;
3-78
epipolarLine
3-79
estimateCameraParameters
Syntax [cameraParams,imagesUsed] =
estimateCameraParameters(imagePoints,
worldPoints)
[stereoParams,pairsUsed] =
estimateCameraParameters(imagePoints,
worldPoints)
Description [cameraParams,imagesUsed] =
estimateCameraParameters(imagePoints, worldPoints) returns
cameraParams, a cameraParameters object containing estimates for
camera intrinsic and extrinsic parameters and distortion coefficients. It
also returns imagesUsed, a P-by-1 logical array, indicating which
images you used to estimate the camera parameters.
[stereoParams,pairsUsed] =
estimateCameraParameters(imagePoints, worldPoints) returns
stereoParams, a stereoParameters object containing parameters
of the stereo camera system. It also returns pairsUsed, a P-by-1
logical array, indicating which pairs you used to estimate the camera
parameters.
3-80
estimateCameraParameters
3-81
estimateCameraParameters
you set it to false, the image axes are exactly perpendicular. In this
case, the function sets the skew to zero.
3-82
estimateCameraParameters
Tangential distortion occurs when the lens and the image plane are
not parallel.
3-83
estimateCameraParameters
for i = 1:5
imageFileName = sprintf('image%d.tif', i);
imageFileNames{i} = fullfile(matlabroot, 'toolbox', 'vision','visio
end
3-84
estimateCameraParameters
subplot(1, 2, 1);
showReprojectionErrors(params);
3-85
estimateCameraParameters
subplot(1, 2, 2);
showReprojectionErrors(params, 'ScatterPlot');
3-86
estimateCameraParameters
Stereo Calibration
numImages = 10;
leftImages = cell(1, numImages);
rightImages = cell(1, numImages);
for i = 1:numImages
leftImages{i} = fullfile(matlabroot, 'toolbox', 'vision', 'visiond
rightImages{i} = fullfile(matlabroot, 'toolbox', 'vision', 'vision
3-87
estimateCameraParameters
end
im = imread(leftImages{i});
params = estimateCameraParameters(imagePoints, worldPoints);
showReprojectionErrors(params);
3-88
estimateCameraParameters
References
[1] Zhang, Z. “A flexible new technique for camera calibration”. IEEE
Transactions on Pattern Analysis and Machine Intelligence, Vol. 22,
No. 11, pp.1330–1334, 2000.
3-89
estimateCameraParameters
3-90
estimateFundamentalMatrix
Syntax estimateFundamentalMatrix
F =
estimateFundamentalMatrix(matchedPoints1,matchedPoints2)
[F,inliersIndex] =
estimateFundamentalMatrix(matchedPoints1,
matchedPoints2)
[F,inliersIndex,status] =
estimateFundamentalMatrix(matchedPoints1,
matchedPoints2)
[F,inliersIndex,status] =
estimateFundamentalMatrix(matchedPoints1,
matchedPoints2,Name,Value)
F =
estimateFundamentalMatrix(matchedPoints1,matchedPoints2)
returns the 3-by-3 fundamental matrix, F, using the least median
of squares (LMedS) method. The input points can be M-by-2
matrices of M number of [x y] coordinates, or SURFPoints,
MSERRegions, or cornerPoints object.
[F,inliersIndex] =
estimateFundamentalMatrix(matchedPoints1, matchedPoints2)
returns logical indices, inliersIndex, for the inliers used to compute
the fundamental matrix. The inliersIndex output is an M-by-1
vector. The function sets the elements of the vector to true when the
corresponding point was used to compute the fundamental matrix. The
elements are set to false if they are not used.
3-91
estimateFundamentalMatrix
[F,inliersIndex,status] =
estimateFundamentalMatrix(matchedPoints1, matchedPoints2)
returns a status code.
[F,inliersIndex,status] =
estimateFundamentalMatrix(matchedPoints1,
matchedPoints2,Name,Value) sets parameters for finding outliers and
computing the fundamental matrix F, with each specified parameter set
to the specified value with one or more comma-separated parameters,
specified as name-value pairs.
Code Generation Support:
Compile-time constant input: Method, OutputClass, DistanceType,
and ReportRuntimeError.
Supports MATLAB Function block: Yes.
“Code Generation Support, Usage Notes, and Limitations”
3-92
estimateFundamentalMatrix
3-93
estimateFundamentalMatrix
3-94
estimateFundamentalMatrix
Data Types
char
3-95
estimateFundamentalMatrix
3-96
estimateFundamentalMatrix
status Value
0: No error.
1: Either matchedPoints1 or matchedPoints2 or both,
are not M-by-2 matrices.
2: matchedPoints1 and matchedPoints2 do not have
the same number of points.
3: matchedPoints1 and matchedPoints2 do not contain
enough points. Norm8Point, RANSAC, and MSAC require
at least 8 points, LMedS 16 points, and LTS requires
ceil(800/InlierPercentage).
4: Not enough inliers found.
Data Types
int32
load stereoPointPairs
fRANSAC = estimateFundamentalMatrix(matchedPoints1,matchedPoints2,'Met
load stereoPointPairs
3-97
estimateFundamentalMatrix
I1 = imread('viprectification_deskLeft.png');
I2 = imread('viprectification_deskRight.png');
figure;
showMatchedFeatures(I1, I2, matchedPoints1, matchedPoints2,'montage','Plo
title('Putative point matches');
figure;
showMatchedFeatures(I1, I2, matchedPoints1(inliers,:),matchedPoints2(inli
title('Point matches after outliers were removed');
load stereoPointPairs
inlierPts1 = matchedPoints1(knownInliers, :);
inlierPts2 = matchedPoints2(knownInliers, :);
fNorm8Point = estimateFundamentalMatrix(inlierPts1, inlierPts2,'Method','
3-98
estimateFundamentalMatrix
When you choose any other method, the function uses the following
algorithm to exclude outliers and compute the fundamental matrix
from inliers:
2 Set the loop counter n, to zero, and the number of loops N, to the
number of random trials specified.
N = min( N, log(1 p) ).
Where, p represents
log(1 rthe
8 confidence parameter you specified, and r is
)
calculated as follows:
N
sgn(dui,vi ), t) / N , where sgn(a, b) = 1 if
a≤b
and
0
otherwise.
i
3-99
estimateFundamentalMatrix
Distance Types
The function provides two distance types, algebraic distance and
Sampson distance, to measure the distance of a pair of points according
to a fundamental matrix. The following equations are used for each
type, with u representing matchedPoints1 and v representing
matchedPoints2.
Sampson distance: 1 1
d(ui , vi ) (vi FuiT )2
T 2 T 2 2
( Fui )1 ( Fui )2 (vi F )1 (vi F
Method
Measure of Fitness
LMedS
median(d ui, vi ); i 1 : N , the number of input points. The
smaller the value, the better the fitness.
RANSAC
N
sgn(dui,vi ), t) / N , wheresgn(a, b) = 1 if a ≤ b and 0
otherwise,
i t represents the specified threshold. The greater the
value, the better the fitness.
3-100
estimateFundamentalMatrix
Method
Measure of Fitness
MSAC
N
min(d(ui , vi ), t) . The smaller the value, the better the fitness.
i
LTS
References
[1] Hartley, R., A. Zisserman, Multiple View Geometry in Computer
Vision, Cambridge University Press, 2003.
3-101
estimateGeometricTransform
Syntax tform =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType)
[tform,inlierpoints1,
inlierpoints2] = estimateGeometricTransform(matchedPoints1,
matchedPoints2,transformType)
[ ___ ,status] =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType)
[ ___ ] =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType, Name,Value)
Description tform =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType) returns a 2-D geometric transform object,
tform. The tform object maps the inliers in matchedPoints1
to the inliers in matchedPoints2.
The matchedPoints1 and matchedPoints2 inputs can be
cornerPoints objects, SURFPoints objects, MSERRegions objects, or
M-by-2 matrices of [x,y] coordinates. You can set the transformType
input to either 'similarity', 'affine', or 'projective'.
[tform,inlierpoints1, inlierpoints2] =
estimateGeometricTransform(matchedPoints1,
matchedPoints2,transformType) returns the corresponding inlier
points in inlierpoints1 and inlierpoints2.
[ ___ ,status] =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType) returns a status code of 0, 1, or 2. If you do not
3-102
estimateGeometricTransform
request the status code output, the function returns an error for
conditions that cannot produce results.
[ ___ ] =
estimateGeometricTransform(matchedPoints1,matchedPoints2,
transformType, Name,Value) uses additional options specified by one
or more Name,Value pair arguments.
Code Generation Support:
Compile-time constant input: transformType
Supports MATLAB Function block: No
“Code Generation Support, Usage Notes, and Limitations”
3-103
estimateGeometricTransform
Data Types
char
3-104
estimateGeometricTransform
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
3-105
estimateGeometricTransform
status Description
0 No error.
1 matchedPoints1 and
matchedPoints2 inputs do
not contain enough points.
2 Not enough inliers found.
If you do not request the status code output, the function will throw
an error for the two conditions that cannot produce results.
Data Types
double
3-106
estimateGeometricTransform
ptsOriginal = detectSURFFeatures(original);
ptsDistorted = detectSURFFeatures(distorted);
[featuresOriginal, validPtsOriginal] = extractFeatures(original, pt
[featuresDistorted, validPtsDistorted] = extractFeatures(distorted, pt
Match features.
[tform,inlierPtsDistorted,inlierPtsOriginal] = estimateGeometricTransf
figure; showMatchedFeatures(original,distorted,inlierPtsOriginal,inlie
title('Matched inlier points');
outputView = imref2d(size(original));
Ir = imwarp(distorted, tform, 'OutputView', outputView);
figure; imshow(Ir); title('Recovered image');
References
[1] Hartley, R., and A. Zisserman, "Multiple View Geometry in
Computer Vision," Cambridge University Press, 2003.
3-107
estimateGeometricTransform
3-108
estimateUncalibratedRectification
Syntax [T1,T2] =
estimateUncalibratedRectification(F,inlierPoints1,
inlierPoints2,imagesize)
Description [T1,T2] =
estimateUncalibratedRectification(F,inlierPoints1,
inlierPoints2,imagesize) returns projective transformations for
rectifying stereo images. This function does not require either
intrinsic or extrinsic camera parameters. The input points
can be M-by-2 matrices of M number of [x y] coordinates, or
SURFPoints, MSERRegions, or cornerPoints object. F is a 3-by-3
fundamental matrix for the stereo images.
Code Generation Support:
Compile-time constant input: No restrictions
Supports MATLAB Function block: Yes
“Code Generation Support, Usage Notes, and Limitations”
Tips • An epipole may be located in the first image or the second image.
Applying the output uncalibrated rectification of T1 (or T2) to image
1 (or image 2) may result in an undesired distortion. You can check
for an epipole within an image by applying the isEpipoleInImage
function.
3-109
estimateUncalibratedRectification
Load the stereo images and feature points which are already matched.
3-110
estimateUncalibratedRectification
I1 = imread('yellowstone_left.png');
I2 = imread('yellowstone_right.png');
load yellowstone_inlier_points;
3-111
estimateUncalibratedRectification
Notice that the inlier points now reside on the same rows. This also
means that the epipolar lines are parallel to the x-axis.
References
[1] Hartley, R. and A. Zisserman, "Multiple View Geometry in
Computer Vision," Cambridge University Press, 2003.
3-112
extractFeatures
[features,validPoints] =
extractFeatures(I,points,Name,Value) uses additional options
specified by one or more Name,Value pair arguments.
Code Generation Support:
Generates platform-dependent library: Yes, for BRISK, FREAK, and
SURF methods only.
Compile-time constant input: Method
Supports MATLAB Function block: Yes, for Block method only.
“Code Generation Support, Usage Notes, and Limitations”
3-113
extractFeatures
3-114
extractFeatures
3-115
extractFeatures
3-116
extractFeatures
I = imread('cameraman.tif');
corners = detectHarrisFeatures(I);
[features, valid_corners] = extractFeatures(I, corners);
Display image.
3-117
extractFeatures
plot(valid_corners);
3-118
extractFeatures
Read image.
I = imread('cameraman.tif');
points = detectSURFFeatures(I);
[features, valid_points] = extractFeatures(I, points);
3-119
extractFeatures
Read image.
I = imread('cameraman.tif');
regions = detectMSERFeatures(I);
[features, valid_points] = extractFeatures(I, regions);
3-120
extractFeatures
plot(valid_points,'showOrientation',true);
References
[1] G. Bradski and A. Kaehler, Learning OpenCV : Computer Vision
with the OpenCV Library, O’Reilly, Sebastopol, CA, 2008.
[2] Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool,
SURF: Speeded Up Robust Features", Computer Vision and Image
Understanding (CVIU), Vol. 110, No. 3, pp. 346--359, 2008
3-121
extractFeatures
[3] Bay, Herbert, Andreas Ess, Tinne Tuytelaars, and Luc Van Gool,
"SURF: Speeded Up Robust Features", Computer Vision and Image
Understanding (CVIU), Vol. 110, No. 3, pp. 346--359, 2008.
3-122
extractHOGFeatures
3-123
extractHOGFeatures
3-124
extractHOGFeatures
3-125
extractHOGFeatures
3-126
extractHOGFeatures
img = imread('cameraman.tif');
3-127
extractHOGFeatures
figure;
imshow(img); hold on;
plot(hogVisualization);
I1 = imread('gantrycrane.png');
subplot(1,2,1);
imshow(I1);
subplot(1,2,2);
plot(visualization);
3-128
extractHOGFeatures
I2 = imread('gantrycrane.png');
corners = detectFASTFeatures(rgb2gray(I2));
strongest = selectStrongest(corners, 3);
figure;
imshow(I2); hold on;
plot(ptVis, 'Color','green');
References
[1] Dalal, N. and B. Triggs. "Histograms of Oriented Gradients for
Human Detection", IEEE Computer Society Conference on Computer
Vision and Pattern Recognition, Vol. 1 (June 2005), pp. 886–893.
3-129
extrinsics
Syntax [rotationMatrix,translationVector] =
extrinsics(imagePoints,
worldPoints,cameraParams)
Description [rotationMatrix,translationVector] =
extrinsics(imagePoints, worldPoints,cameraParams) returns the
translation and rotation of the camera, relative to the world coordinate
system defined by worldPoints.
3-130
extrinsics
numImages = 9;
files = cell(1, numImages);
for i = 1:numImages
files{i} = fullfile(matlabroot, 'toolbox', 'vision', 'visionde
end
3-131
extrinsics
3-132
extrinsics
Undistort image.
im = undistortImage(imOrig, cameraParams);
rotationMatrix =
translationVector =
3-133
generateCheckerboardPoints
Syntax [worldPoints] =
generateCheckerboardPoints(boardSize,squareSize)
Description [worldPoints] =
generateCheckerboardPoints(boardSize,squareSize) returns an
M-by-2 matrix containing M [x, y] corner coordinates for the squares on
a checkerboard. The point [0,0] corresponds to the lower-right corner
of the top-left square of the board.
3-134
generateCheckerboardPoints
3-135
generateCheckerboardPoints
3-136
generateCheckerboardPoints
M = (boardSize(1)-1) * (boardSize(2)-1)
I = checkerboard;
squareSize = 10;
worldPoints = generateCheckerboardPoints([8 8], squareSize);
Offset the points, placing the first point at the lower-right corner of the
first square.
3-137
generateCheckerboardPoints
3-138
integralFilter
Syntax J = integralFilter(intI,H)
This function uses integral images for filtering an image with box
filters. You can obtain the integral image, intI, by calling the
integralImage function. The filter size does not affect the speed of the
filtering operation. Thus, the integralFilter function is ideally suited
to use for fast analysis of images at different scales, as demonstrated
by the Viola-Jones algorithm [1].
Tips Because the integralFilter function uses correlation for filtering, the
filter is not rotated before computing the result.
Input intI
Arguments Integral image. You can obtain the integral image, intI, by calling
the integralImage function. The class for this value can be double
or single.
H
Filter object. You can obtain the filter object, H, by calling the
integralKernel function.
Output J
Arguments Filtered image. The filtered image, J, returns only the parts of
correlation that are computed without padding. The resulting size of
the filtered output equals:
3-139
integralFilter
Because the function uses correlation for filtering, the filter is not
rotated before computing the result.
I = imread('pout.tif');
figure; imshow(I);
intImage = integralImage(I);
J = integralFilter(intImage, avgH);
Cast the result back to the same class as the input image and display
the results.
I = imread('pout.tif');
intImage = integralImage(I);
3-140
integralFilter
Construct Haar-like wavelet filters. Use the dot notation to find the
vertical filter.
imtool(horiH.Coefficients, 'InitialMagnification','fit');
References
[1] Viola, Paul and Michael J. Jones, “Rapid Object Detection using
a Boosted Cascade of Simple Features”, Proceedings of the 2001
IEEE Computer Society Conference on Computer Vision and Pattern
Recognition, 2001. Volume: 1, pp.511–518.
3-141
integralImage
Syntax J = integralImage(I)
size(J) = size(I) +1
Such sizing facilitates easy computation of pixel sums along all image
boundaries. The integral image, J, is essentially a padded version of
the value cumsum(cumsum(I,2))."
An integral image lets you rapidly calculate summations over image
subregions. Use of integral images was popularized by the Viola-Jones
algorithm [1]. Integral images facilitate summation of pixels and can be
performed in constant time, regardless of the neighborhood size.
Code Generation Support:
Supports MATLAB Function block: Yes
Input I
Arguments Intensity image. This value can be any numeric class.
Output J
Arguments Integral image. The function zero-pads the top and left side of the
integral image. The class of the output is double.
3-142
integralImage
I = magic(5)
Compute the sum over the region using the integral image.
J = integralImage(I);
regionSum = J(eR+1,eC+1) - J(eR+1,sC) - J(sR,eC+1) + J(sR,sC)
3-143
integralImage
References
[1] Viola, Paul and Michael J. Jones, “Rapid Object Detection using
a Boosted Cascade of Simple Features”, Proceedings of the 2001
IEEE Computer Society Conference on Computer Vision and Pattern
Recognition, 2001. Volume: 1, pp.511–518.
3-144
insertMarker
3-145
insertMarker
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
'x-mark' 'x'
'plus' '+'
'star' '*'
'square' 's'
Data Types
char
3-146
insertMarker
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
I = imread('peppers.png');
3-147
insertMarker
imshow(RGB);
3-148
insertObjectAnnotation
insertObjectAnnotation(I,'rectangle',Position,Label)
insertObjectAnnotation(I,'circle',Position,Label)
RGB = insertObjectAnnotation(I,Shape,Position,Label,
Name,Value) uses additional options specified by one or more
Name,Value pair arguments.
insertObjectAnnotation(I,'rectangle',Position,Label) inserts
rectangles and corresponding labels at the location indicated by the
position matrix. The Position input must be an M-by-4 matrix, where
each row, M, specifies a rectangle as a four-element vector, [x y width
height]. The elements x and y indicate the upper-left corner of the
rectangle, and the width and height specify the size.
insertObjectAnnotation(I,'circle',Position,Label) inserts
circles and corresponding labels at the location indicated by the position
matrix. The Position input must be an M-by-3 matrix, where each
row, M, specifies a circle as a three-element vector, [x y r]. The elements
x and y indicate the center of the circle, and r specifies the radius.
3-149
insertObjectAnnotation
3-150
insertObjectAnnotation
3-151
insertObjectAnnotation
M-by-3 matrix of RGB values for each annotation. RGB values must
be in the range of the input image data type.
Supported color strings are: 'blue', 'green', 'cyan', 'red',
'magenta', 'black', and 'white'.
Data Types
char | uint8 | uint16 | int16 | double | single | cell
3-152
insertObjectAnnotation
I = imread('board.tif');
figure, imshow(I);
label_str = cell(3,1);
conf_val = [85.212 98.76 78.342];
for ii=1:3
label_str{ii} = ['Confidence: ' num2str(conf_val(ii),'%0.2f') '%']
end
Set the position and size of the three rectangles in the format [x y width
height].
3-153
insertObjectAnnotation
I = imread('coins.png');
figure, imshow(I);
Set up the circle annotations with labels. The first two arguments are
the (x,y) coordinates for the center of the circle, the third argument is
the radius.
3-154
insertShape
3-155
insertShape
x y width height .
x1 y1 width1 height1
x y2 width2 height2
2
xM yM widthM heightM
3-156
insertShape
{[x11,y11,x12,y12,...,x1p,y1p],
[x21,y21,x22,y22,.....,x2q,y2q], ...
[xM1,yM1,xM2,yM2,.......,xMr,yMr]}
3-157
insertShape
{[x11,y11,x12,y12,...,x1p,y1p],
[x21,y21,x22,y22,.....,x2q,y2q], ...
[xM1,yM1,xM2,yM2,.......,xMr,yMr]}
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
3-159
insertShape
I = imread('peppers.png');
3-160
insertShape
imshow(RGB);
3-161
insertShape
3-162
insertText
3-163
insertText
scalar | vector
Numeric value text, specified as a scalar or a vector. If a scalar value is
provided, it is used for all positions. The vector length must equal the
number of rows in the position matrix. Numeric values are converted
to a string using format ’%0.5g’, as used by sprintf.
Data Types
char
3-164
insertText
3-165
insertText
RGB values must be in the range of the image data type. Supported
color strings are: 'blue', 'green', 'red', 'cyan', 'magenta',
'yellow','black', and 'white'.
Data Types
cell | char | uint8 | uint16 | int16 | double | single
3-166
insertText
I = imread('peppers.png');
Insert text.
I = imread('board.tif');
text_str = cell(3,1);
conf_val = [85.212 98.76 78.342];
for ii=1:3
text_str{ii} = ['Confidence: ' num2str(conf_val(ii),'%0.2f') '%'];
end
3-167
insertText
Insert text.
3-168
isEpipoleInImage
Input F
Arguments A 3-by-3 fundamental matrix computed from stereo images. If P1
represents a point in the first image I1 that corresponds to P2, a point in
the second image I2, then:
[P2,1] * F * [P1,1]’ = 0
F must be double or single.
imageSize
The size of the image, and in the format returned by the function size.
3-169
isEpipoleInImage
Output isIn
Arguments Logical value set to true when the image contains an epipole, and set to
false when the image does not contain an epipole.
epipole
A 1-by-2 vector indicating the location of the epipole.
isIn =
epipole =
256.2989 99.8517
f = [0 0 1; 0 0 0; -1 0 0];
imageSize = [200, 300];
[isIn,epipole] = isEpipoleInImage(f',imageSize)
isIn =
3-170
isEpipoleInImage
epipole =
1.0e+308 *
0 1.7977
3-171
isfilterseparable
Syntax S = isfilterseparable(H)
[S, HCOL, HROW] = isfilterseparable(H)
3-172
isfilterseparable
Input H
Arguments H numeric or logical, 2-D, and nonsparse.
Output HCOL
Arguments HCOL is the same data type as input H when H is either single or double
floating point. Otherwise, HCOL becomes double floating point. If S is
true, HCOL is a vector of vertical filter coefficients. Otherwise, HCOL is
empty.
HROW
HROW is the same data type as input H when H is either single or double
floating point. Otherwise, HROW becomes double floating point. If S
is true, HROW is a vector of horizontal filter coefficients. Otherwise,
HROW is empty.
S
Logical variable that is set to true, when the filter is separable, and
false, when it is not.
Examples Determine if the Gaussian filter created using the fspecial function
is separable.
When you run this example, notice that hcol*hrow equals the
two_dimensional_filter. This result is expected for a Gaussian filter.
3-173
isfilterseparable
3-174
lineToBorderPoints
Input lines
Arguments Line matrix. An M-by-3 matrix, where each row must be in the format,
[A,B,C]. This matrix corresponds to the definition of the line:
A * x + B * y + C = 0.
M represents the number of lines.
lines must be double or single.
imageSize
Image size. This input must be in the format returned by the size
function.
imageSize must be double, single, or integer.
Output points
Arguments Output intersection points. An M-by-4 matrix. The function returns the
matrix in the format of [x1, y1, x2, y2]. In this matrix, [x1 y1] and [x2 y2]
are the two intersection points. When a line in the image and the image
border do not intersect, the function returns [-1,-1,-1,-1].
Examples Find the intersection points of a line in an image and the image border.
3-175
lineToBorderPoints
I = imread('rice.png');
figure; imshow(I); hold on;
% Compute the intersection points of the line and the image border.
points = lineToBorderPoints(aLine, size(I));
line(points([1,3]), points([2,4]));
3-176
matchFeatures
[indexPairs,matchmetric] =
matchFeatures(features1,features2) also returns the metric values
that correspond to the associated features indexed by indexPairs in a
P-by-1 matrix matchmetric.
[indexPairs,matchmetric] =
matchFeatures(features1,features2,Name, Value) uses additional
options specified by one or more Name,Value pair arguments.
Code Generation Support:
Generates platform-dependent library for MATLAB host.
Generates portable C code for non-host target.
Compile-time constant input: Method and Metric.
Supports MATLAB Function block: Yes
Generated code for this function uses a precompiled platform-specific
shared library.
“Code Generation Support, Usage Notes, and Limitations”
3-177
matchFeatures
features2 - Features
M2-by-N matrix | binaryFeatures object
Features set, specified as an M2-by-N matrix, where N is the length
of each feature vector or a binaryFeatures object. This object for
binary descriptors is produced using the Fast Retina Keypoint (FREAK)
descriptor.
3-178
matchFeatures
’MatchThreshold’ - Threshold
3-179
matchFeatures
percent value in the range (0, 100) | 10.0 for binary feature vectors;
1.0 non-binary feature vectors (default)
Threshold, specified as a scalar percent value in the range (0,100) for
selecting the strongest matches. Matches having a metric more than
this percent value from a perfect match are rejected. Increase this value
to return more matches.
3-180
matchFeatures
When you set this value to true, and features are not normalized in
advance, the function produces wrong results.
Note This parameter applies only when the input feature set,
features1 and features2, are not binaryFeatures objects.
3-181
matchFeatures
3-182
matchFeatures
I1 = rgb2gray(imread('viprectification_deskLeft.png'));
I2 = rgb2gray(imread('viprectification_deskRight.png'));
points1 = detectHarrisFeatures(I1);
points2 = detectHarrisFeatures(I2);
3-183
matchFeatures
3-184
matchFeatures
I1 = imread('cameraman.tif');
I2 = imresize(imrotate(I1,-20), 1.2);
points1 = detectSURFFeatures(I1);
3-185
matchFeatures
points2 = detectSURFFeatures(I2);
Retrieve the locations of matched points. The SURF feature vectors are
already normalized.
Display the matching points. The data still includes several outliers, but
you can see the effects of rotation and scaling on the display of matched
features.
figure; showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2);
legend('matched points 1','matched points 2');
3-186
matchFeatures
3-187
matchFeatures
References
[1] .2005 [43] Lewis J.P.: Fast Normalized Cross Correlation. Available
from:http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html
3-188
mplay
Syntax mplay
mplay('filename.avi')
mplay('filename.avi',FPS)
mplay(A)
mplay(A,FPS)
mplay({line_handles})
mplay({'block',PORT})
Description
Note The mplay function will be removed in a future release. Use the
implay function with functionality identical to mplay.
mplay opens an MPlay GUI that allows you to view video from files,
the MATLAB workspace, or Simulink signals. The MPlay GUI does
not play audio.
mplay('filename.avi') connects the MPlay GUI to the specified AVI
file.
mplay('filename.avi',FPS) plays the specified frame rate in frames
per second, (FPS). The FPS value equals that of the frame rate specified
in the file.
mplay(A) connects the MPlay GUI to the variable in the MATLAB
workspace, A.
mplay(A,FPS) plays the specified frame rate in frames per second, FPS.
The FPS value defaults to 20.
mplay({line_handles}) connects the MPlay GUI to one or three
Simulink signal lines to display, where all signals must originate from
the same block.
mplay({'block',PORT}) connects the MPlay GUI to the output signal
of the specified block, 'block', on output port port. All ports on the
specified block are selected if PORT is omitted.
3-189
mplay
Input A
Arguments A is a variable in the MATLAB workspace, which must have one of
the following formats:
• MATLAB movie structure
• Intensity video. This input is an M-by-N-by-T or M-by-N-by-1-by-T
array, where the size of each frame is M-by-N and there are T image
frames.
• RGB video array. This input is an M-by-N-by-3-by-T array, where the
size of each RGB image is M-by-N-by-3 and there are T image frames.
For performance considerations, the video input A data type converts
to uint8 as follows:
int32
uint32
Boolean
Fixed point
block
block is a full path to a specified Simulink block. To get the full block
path name of the currently selected Simulink block, issue the command
mplay({gcb,1}) on the MATLAB command line.
3-190
mplay
filename.avi
Filename.avi is a specified AVI file.
FPS
FPS stands for frames per second. You can specify the frame rate in
frames per second.
line_handles
line_handles are Simulink signal lines. To get the handles to the
Simulink signals, line_handles, issue the command mplay({gsl})
on the MATLAB command line.
port
port refers to a Simulink block output port number.
for i=length(x):-1:1
patch(sin(x)*radius(i),cos(x)*radius(i), ...
[abs(cos(x(i))) 0 0]);
F = getframe(gca);
video = cat(4,video,F.cdata); % video is MxNx3xT
end
3-191
mplay
mplay('vipwarnsigns.avi');
load cellsequence
mplay(cellsequence,10);
mplay({'vipmplaytut/Rotate'});
3-192
ocr
3-193
ocr
thresholding technique for the conversion. For best ocr results, the
height of a lowercase ‘x’, or comparable character in the input image,
must be greater than 20 pixels. From either the horizontal or vertical
axes, remove any text rotations greater than +/- 10 degrees, to improve
recognition results.
Data Types
single | double | int16 | uint8 | uint16 | logical
3-194
ocr
The table lists how the function treats the text for each TextLayout
setting.
’Language’ - Language
'English' (default) | 'Japanese' | string | cell array of strings
Language to recognize, specified as the comma-separated pair consisting
of ’Language’ and the string 'English', 'Japanese', or a cell array
of strings. You can also specify a path to add a custom language.
Specifying multiple languages enables simultaneous recognition of all
the selected languages. However, selecting more than one language
may reduce the accuracy and increase the time it takes to perform ocr.
You can use the ocr function with trained data files to perform text
recognition with custom languages. To use a custom language, specify
the path to the trained date file as the language string. You must
3-195
ocr
txt = ocr(img,'Language','path/to/tessdata/eng.traineddata');
The containing folder must always be the same for all the files specified
in the cell array. In the preceding example, all of the traineddata
files in the cell array are contained in the folder ‘path/to/tessdata’ .
Because the following code points to two different containing folders, it
does not work.
Note To use the ocr function with the downloaded language zipped
files, you must unzip all files.
3-196
ocr
The ocr function selects the best match from this set. Using a priori
knowledge about the characters in the input image helps to improve
text recognition accuracy. For example, if you set CharacterSet to
all numeric digits, '0123456789', the function attempts to match
each character to only digits. In this case, a non-digit character can
incorrectly get recognized as a digit.
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard)
recognizedText = ocrResults.Text;
figure;
imshow(businessCard);
text(600, 150, recognizedText, 'BackgroundColor', [1 1 1]);
ocrResults =
3 Apple Hi...'
CharacterBoundingBoxes: [103x4 double]
3-197
ocr
Read image.
I = imread('handicapSign.jpg');
3-198
ocr
figure; imshow(Iocr);
3-199
ocr
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard)
Iocr = insertObjectAnnotation(businessCard, 'rectangle', ...
ocrResults.WordBoundingBoxes, ...
ocrResults.WordConfidences);
figure; imshow(Iocr);
ocrResults =
3 Apple Hi...'
CharacterBoundingBoxes: [103x4 double]
CharacterConfidences: [103x1 single]
Words: {16x1 cell}
WordBoundingBoxes: [16x4 double]
WordConfidences: [16x1 single]
3-200
ocr
businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'MathWorks', 'IgnoreCase', true);
Iocr = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(Iocr);
3-201
ocr
References
[1] R. Smith. An Overview of the Tesseract OCR Engine, Proceedings
of the Ninth International Conference on Document Analysis and
Recognition (ICDAR 2007) Vol 2 (2007), pp. 629-633.
3-202
ocr
3-203
reconstructScene
3-204
reconstructScene
% Load stereoParams.
load('webcamsSceneReconstruction.mat');
3-205
reconstructScene
% Compute disparity.
disparityMap = disparity(rgb2gray(J1), rgb2gray(J2));
figure; imshow(disparityMap, [0, 64], 'InitialMagnification', 50);
% Segment out a person located between 3.2 and 3.7 meters away from the c
Z = pointCloud(:, :, 3);
mask = repmat(Z > 3200 & Z < 3700, [1, 1, 3]);
J1(~mask) = 0;
imshow(J1, 'InitialMagnification', 50);
3-206
reconstructScene
References
[1] G. Bradski and A. Kaehler, Learning OpenCV : Computer Vision
with the OpenCV Library, O’Reilly, Sebastopol, CA, 2008.
3-207
rectifyStereoImages
I2 - Input image 2
M-by-N-by-3 truecolor image | M-by-N 2-D truecolor image
3-208
rectifyStereoImages
3-209
rectifyStereoImages
output images are cropped to the size of the largest common rectangle
containing valid pixels.
3-210
rectifyStereoImages
numImages = 5;
leftImages = cell(1, numImages);
rightImages = cell(1, numImages);
for i = 1:numImages
leftImages{i} = fullfile(matlabroot, 'toolbox', 'vision', 'vis
rightImages{i} = fullfile(matlabroot, 'toolbox', 'vision','vis
end
I1 = imread(leftImages{1});
I2 = imread(rightImages{1});
figure;
imshowpair(J1_full, J2_full, 'falsecolor', 'ColorChannels', 'red-c
3-211
rectifyStereoImages
figure;
imshowpair(J1_valid, J2_valid, 'falsecolor', 'ColorChannels', 'red-cy
3-212
rectifyStereoImages
References
[1] G. Bradski and A. Kaehler, Learning OpenCV : Computer Vision
with the OpenCV Library, O’Reilly, Sebastopol, CA, 2008.
3-213
showExtrinsics
Syntax showExtrinsics(cameraParams)
showExtrinsics(cameraParams,view)
ax = showExtrinsics( ___ )
showExtrinsics( ___ ,Name,Value)
3-214
showExtrinsics
ax = showExtrinsics(cameraParams)
You can also use the gca function to get the current axes handle.
3-215
showExtrinsics
Example: showExtrinsics(cameraParams,'Parent',ax)
Example: ax = showExtrinsics(cameraParams)
for i = 1:5
imageFileName = sprintf('image%d.tif', i);
imageFileNames{i} = fullfile(matlabroot, 'toolbox', 'vision',...
'visiondemos', 'calibration', 'webcam', imageFileName);
end
squareSide = 25;
worldPoints = generateCheckerboardPoints(boardSize, squareSide);
figure; showExtrinsics(cameraParams);
3-216
showExtrinsics
3-217
showExtrinsics
numImages = 5;
images1 = cell(1, numImages);
images2 = cell(1, numImages);
for i = 1:numImages
images1{i} = fullfile(matlabroot, 'toolbox', 'vision', 'visiondemos
images2{i} = fullfile(matlabroot, 'toolbox', 'vision', 'visiondemos
3-218
showExtrinsics
end
squareSize = 108;
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
figure; showExtrinsics(cameraParams);
3-219
showExtrinsics
3-220
showExtrinsics
3-221
showMatchedFeatures
Syntax showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2)
showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2,method)
H = showMatchedFeatures( ___ )
Description showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2)
displays a falsecolor overlay of images I1 and I2 with a color-coded plot
of corresponding points connected by a line. matchedPoints1 and
matchedPoints2 contain the coordinates of corresponding points in I1
and I2. The input points can be M-by-2 matrices of M number of [x y]
coordinates, or SURFPoints, MSERRegions, or cornerPoints object.
showMatchedFeatures(I1,I2,matchedPoints1,matchedPoints2,method)
displays images I1 and I2 using the visualization style specified by the
method parameter.
3-222
showMatchedFeatures
I2 - Input image
numeric array
Input image two, specified as a numeric array.
3-223
showMatchedFeatures
Read images.
I1 = rgb2gray(imread('parkinglot_left.png'));
I2 = rgb2gray(imread('parkinglot_right.png'));
SURF features.
points1 = detectHarrisFeatures(I1);
points2 = detectHarrisFeatures(I2);
3-224
showMatchedFeatures
Extract features.
Match features.
figure; showMatchedFeatures(I1,I2,matched_pts1,matched_pts2,'montage')
Read images.
I1 = imread('cameraman.tif');
I2 = imresize(imrotate(I1,-20), 1.2);
SURF features.
points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);
Extract features.
Match features.
3-225
showMatchedFeatures
figure; showMatchedFeatures(I1,I2,matched_pts1,matched_pts2);
title('Putative point matches');
legend('matchedPts1','matchedPts2');
3-226
showReprojectionErrors
Syntax showReprojectionErrors(cameraParams)
showReprojectionErrors(cameraParams,view)
showReprojectionErrors( ___ ,Name,Value)
ax = showReprojectionErrors( ___ )
3-227
showReprojectionErrors
3-228
showReprojectionErrors
ax = showReprojectionErrors(cameraParams)
You can also use the gca function to get the current axes handle.
Example: showReprojectionErrors(cameraParams,'Parent',ax)
Example: ax = showReprojectionErrors(cameraParams)
for i = 1:5
imageFileName = sprintf('image%d.tif', i);
imageFileNames{i} = fullfile(matlabroot, 'toolbox', 'vision','vi
end
subplot(1, 2, 1);
3-229
showReprojectionErrors
showReprojectionErrors(params);
subplot(1, 2, 2);
showReprojectionErrors(params, 'ScatterPlot');
3-230
showReprojectionErrors
numImages = 10;
images1 = cell(1, numImages);
images2 = cell(1, numImages);
for i = 1:numImages
images1{i} = fullfile(matlabroot, 'toolbox', 'vision','visiondem
images2{i} = fullfile(matlabroot, 'toolbox', 'vision','visiondem
3-231
showReprojectionErrors
end
showReprojectionErrors(params);
3-232
showReprojectionErrors
3-233
trainCascadeObjectDetector
Syntax trainCascadeObjectDetector(outputXMLFilename,positiveInstances,
negativeImages)
trainCascadeObjectDetector(outputXMLFilename,'resume')
Description trainCascadeObjectDetector(outputXMLFilename,positiveInstances,
negativeImages) writes a trained cascade detector XML file with
the name, outputXMLFilename. The name specified by the
outputXMLFilename input must have an XML extension. For a
more detailed explanation on how this function works, refer to
“Train a Cascade Object Detector”.
trainCascadeObjectDetector(outputXMLFilename,'resume')
resumes an interrupted training session. The outputXMLFilename
input must match the output file name from the interrupted session.
All arguments saved from the earlier session are reused automatically.
3-234
trainCascadeObjectDetector
3-235
trainCascadeObjectDetector
3-236
trainCascadeObjectDetector
Data Types
single | double | int8 | int16 | int32 | int64 | uint8 |
uint16 | uint32 | uint64
FalseAlarmRateNumCascadeStages
3-237
trainCascadeObjectDetector
TruePositiveRateNumCascadeStages
3-238
trainCascadeObjectDetector
Load the positive samples data from a .mat file. The file names and
bounding boxes are contained in an array of structures named ’data’.
load('stopSigns.mat');
Training stage 1 of 5
[.....................................................................
Used 86 positive and 172 negative samples
Time to train stage 1: 1 seconds
3-239
trainCascadeObjectDetector
Training stage 2 of 5
[........................................................................
Used 86 positive and 172 negative samples
Time to train stage 2: 0 seconds
Training stage 3 of 5
[........................................................................
Used 86 positive and 172 negative samples
Time to train stage 3: 0 seconds
Training stage 4 of 5
[........................................................................
Used 86 positive and 172 negative samples
Time to train stage 4: 3 seconds
Training stage 5 of 5
[........................................................................
Used 86 positive and 172 negative samples
Time to train stage 5: 6 seconds
Training complete
detector = vision.CascadeObjectDetector('stopSignDetector.xml');
img = imread('stopSignTest.jpg');
3-240
trainCascadeObjectDetector
figure; imshow(detectedImg);
rmpath(imDir);
References
[1] Viola, P., and M. J. Jones, "Rapid Object Detection using a Boosted
Cascade of Simple Features". Proceedings of the 2001 IEEE Computer
Society Conference. Volume 1, 15 April 2001, pp. I-511–I-518.
3-241
trainCascadeObjectDetector
3-242
trainingImageLabeler
Syntax trainingImageLabeler
trainingImageLabeler CLOSE
trainingImageLabeler
3-243
undistortImage
Syntax J = undistortImage(I,cameraParams)
J = undistortImage(I,cameraParams,interp)
J = undistortImage( ___ ,Name,Value)
3-244
undistortImage
3-245
undistortImage
3-246
vision.getCoordinateSystem
Syntax vision.getCoordinateSystem(coordinateSystem)
Note When you set the coordinate system to RC, only your current
MATLAB session persists using the RC coordinate system. The
coordinate system resets to XY when you restart MATLAB.
vision.getCoordinateSystem
3-247
vision.setCoordinateSystem
Syntax vision.setCoordinateSystem(coordinateSystem)
Note When you set the coordinate system to RC, only your current
MATLAB session persists using the RC coordinate system. The
coordinate system resets to XY when you restart MATLAB.
Example Set the Computer Vision System Toolbox to the coordinate system prior
to R2011b.
vision.setCoordinateSystem('RC');
Set the Computer Vision System Toolbox to the new coordinate system.
vision.setCoordinateSystem('XY');
3-248
visionlib
Syntax visionlib
Description visionlib opens the top-level Computer Vision System Toolbox block
library model.
Examples View and gain access to the Computer Vision System Toolbox blocks:
visionlib
Alternatives To view and gain access to the Computer Vision System Toolbox blocks
using the Simulink library browser:
• Type simulink at the MATLAB command line, and then expand the
Computer Vision System Toolbox node in the library browser.
3-249