0% found this document useful (0 votes)
488 views1,889 pages

Computer Vision System Toolbox™ Reference PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
488 views1,889 pages

Computer Vision System Toolbox™ Reference PDF

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Vision System Toolbox™

Reference

R2014a
How to Contact MathWorks

www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support

[email protected] Product enhancement suggestions


[email protected] Bug reports
[email protected] Documentation error reports
[email protected] Order status, license renewals, passcodes
[email protected] Sales, pricing, and general information

508-647-7000 (Phone)

508-647-7001 (Fax)

The MathWorks, Inc.


3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Computer Vision System Toolbox™ Reference
© COPYRIGHT 2000–2014 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
the use, modification, reproduction, release, performance, display, and disclosure of the Program and
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Documentation, unused, to The MathWorks, Inc.

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

Blocks — Alphabetical List


1

Alphabetical List
2

Functions Alphabetical
3

v
vi Contents
1

Blocks — Alphabetical List


2-D Autocorrelation

Purpose Compute 2-D autocorrelation of input matrix

Library Statistics
visionstatistics

Description The 2-D Autocorrelation block computes the two-dimensional


autocorrelation of the input matrix. Assume that input matrix A has
dimensions (Ma, Na). The equation for the two-dimensional discrete
autocorrelation is

( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( A(m + i, n + j))
m =0 n =0

where 0 ≤ i < 2 Ma − 1 and 0 ≤ j < 2 Na − 1 .

The output of this block has dimensions (2 Ma − 1, 2 Na − 1) .

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

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D
Autocorrelation block for fixed-point signals.

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.

See Also 2-D Correlation Computer Vision System Toolbox


2-D Histogram Computer Vision System Toolbox
2-D Mean Computer Vision System Toolbox
2-D Median Computer Vision System Toolbox
2-D Standard Deviation Computer Vision System Toolbox
2-D Variance Computer Vision System Toolbox
2-D Maximum Computer Vision System Toolbox
2-D Minimum Computer Vision System Toolbox

1-7
2-D Convolution

Purpose Compute 2-D discrete convolution of two input matrices

Library Filtering
visionfilter

Description

The 2-D Convolution block computes the two-dimensional convolution


of two input matrices. Assume that matrix A has dimensions (Ma, Na)
and matrix B has dimensions (Mb, Nb). When the block calculates the
full output size, the equation for the 2-D discrete convolution is

( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) * B(i − m, j − n)
m =0 n =0

where 0 ≤ i < Ma + Mb − 1 and 0 ≤ j < Na + Nb − 1 .

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

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 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.

Note When you select the Output normalized convolution check


box, the block input cannot be fixed point.

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D Convolution
block for fixed-point signals.

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:

The resulting matrix is

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

In this case, it is always possible to extract the exact center of Cfull .


Therefore, the block outputs

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]

The second input matrix also represents an image and is defined as

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.

3 Multiply each element of the rotated I2 matrix by the element of


I1 underneath.

4 Sum the individual products from step 3.

Hence the (1,1) output element is


0 ⋅ 2 + 0 ⋅ 9 + 0 ⋅ 4 + 0 ⋅ 7 + 17 ⋅ 5 + 24 ⋅ 3 + 0 ⋅ 6 + 23 ⋅ 1 + 5 ⋅ 8 = 220 .

1-13
2-D Convolution

Values of rotated I2 matrix

2 9 4

7 5 3
Alignment of center
element of I2
6 1 8

17 24 1 8 15

23 5 7 14 16 Image pixel values

4 6 13 20 22

Alignment of I2 matrix
10 12 19 21 3

11 18 25 2 9

Computing the (1,1) Output of Convolution

The normalized convolution of the (1,1) output element is


220/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.3459, where
I1p = [0 0 0; 0 17 24; 0 23 5].

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.

The Product Output inherits 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.

Sign of Input I1 Sign of Input I2 Sign of Product


Output
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed

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

• When you select Same as product output, these


characteristics match those of the product output.
• 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 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.
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.
• 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.

See Also 2-D FIR Filter Computer Vision System Toolbox


software

1-19
2-D Correlation

Purpose Compute 2-D cross-correlation of two input matrices

Library Statistics
visionstatistics

1-20
2-D Correlation

Description

1-21

The 2-D Correlation block computes the two-dimensional


2-D Correlation

( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( B(m + i, n + j))
m =0 n =0

where 0 ≤ i < Ma + Mb − 1 and 0 ≤ j < Na + Nb − 1 .

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.

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D Correlation
block for fixed-point signals.

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:

The resulting matrix is

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:

In this case, it is always possible to extract the exact center of Cfull .


Therefore, the block outputs

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]

The second input matrix also represents an image and is defined as

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.

2 Multiply each weight in I2 by the element of I1 underneath.

3 Sum the individual products from step 2.

The (2,4) output element from the cross-correlation is


1 ⋅ 8 + 8 ⋅ 1 + 15 ⋅ 6 + 7 ⋅ 3 + 14 ⋅ 5 + 16 ⋅ 7 + 13 ⋅ 4 + 20 ⋅ 9 + 22 ⋅ 2 = 585 .

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

Image pixel values 23 5 7 14 16

4 6 13 20 22

Alignment of center
10 12 19 21 3 element of I2

11 18 25 2 9

Computing the (2,4) Output of Cross-Correlation

1-27
2-D Correlation

The normalized cross-correlation of the (2,4) output element is


585/sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))) = 0.8070, where
I1p = [1 8 15; 7 14 16; 13 20 22].

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.

The Product Output inherits 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
table below show all cases.

Sign of Input I1 Sign of Input I2 Sign of Product


Output
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed

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

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 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 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.
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.
• 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-33
2-D Correlation

See Also 2-D Autocorrelation Computer Vision System Toolbox


2-D Histogram Computer Vision System Toolbox
2-D Mean Computer Vision System Toolbox
2-D Median Computer Vision System Toolbox
2-D Standard Deviation Computer Vision System Toolbox
2-D Variance Computer Vision System Toolbox
2-D Maximum Computer Vision System Toolbox
2-D Minimum Computer Vision System Toolbox

1-34
2-D DCT

Purpose Compute 2-D discrete cosine transform (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

where C(m), C(n) = 1 / 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 point No
intensity values
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer

Output 2-D DCT of the input Same as Input port No

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.

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D DCT block
for fixed-point signals. Inputs are first cast to the output data type and
stored in the output buffer. Each butterfly stage processes signals in
the accumulator data type, with the final output of the butterfly being
cast back into the output data type.

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.

Sine and cosine computation


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

1-38
2-D DCT

trigonometric values before the simulation starts. In this case, the


block requires extra memory.

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

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 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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

• 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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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:

WLideal output = WLinput + floor(log 2 ( DCT length − 1)) + 1

FLideal output = FLinput

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

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

See Also 2-D IDCT Computer Vision System Toolbox software


2-D FFT Computer Vision System Toolbox software
2-D IFFT Computer Vision System Toolbox software

1-42
2-D FFT

Purpose Compute two-dimensional fast Fourier transform of input

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:

y = fft2(A) % Equivalent MATLAB code

Computing the FFT of each dimension of the input matrix is equivalent


to calculating the two-dimensional discrete Fourier transform (DFT),
which is defined by the following equation:

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

Output 2-D FFT of the Same as Input port Yes


input

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

lengths in both simulation and code generation. Generated code


using the FFTW implementation will be restricted to those computers
which are capable of running MATLAB. The input data type must be
floating-point.

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 Algorithms for Real or Complex Input Complexity


Floating-Point Signals

Other Parameter Settings Algorithms Used for IFFT Computation


Butterfly operation and radix-2 DIT

Radix-2 DIF

1-45
2-D FFT

Other Parameter Settings Algorithms Used for IFFT Computation


Butterfly operation and radix-2 DIT in conjunction
with the half-length and double-signal algorithms

Radix-2 DIF in conjunction with the half-length and


double-signal algorithms

Radix-2 Algorithms for Real or Complex Input Complexity


Fixed-Point Signals
Other Parameter Settings Algorithms Used for IFFT Computation
Butterfly operation and radix-2 DIT

Radix-2 DIF

Note The Input is conjugate symmetric parameter cannot be used


for fixed-point signals.

Radix-2 Optimization for the Table of Trigonometric Values


In certain situations, the block’s Radix–2 algorithm computes all the
possible trigonometric values of the twiddle factor

2πk
j
e K

where K is the greater value of either M or N and k = 0, , K − 1 .


The block stores these values in a table and retrieves them during
simulation. The number of table entries for fixed-point and
floating-point is summarized in the following table:

1-46
2-D FFT

Number of Table Entries for N-Point FFT


floating-point 3 N/4
fixed-point N

Fixed-Point Data Types


The following diagrams show the data types used in the FFT block for
fixed-point signals. You can set the sine table, accumulator, product
output, and output data types displayed in the diagrams in the FFT
dialog box as discussed in “Dialog Box” on page 1-49.
Inputs to the FFT 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 FFT and after each
butterfly stage in a decimation-in-frequency FFT.

1-47
2-D FFT

The multiplier output appears in the accumulator data type because


both of the inputs to the multiplier are complex. For details on the
complex multiplication performed, refer to “Multiplication Data Types”.

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 Radix-2 for bit-reversed processing, fixed


or floating-point data, or for 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. See “Radix-2
Implementation” on page 1-45.

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.

Linearly ordering the output requires extra data sorting


manipulation. For more information, see “Bit-Reversed Order”
on page 1-54.
Scale result by FFT length
When you select this parameter, the block divides the output of
the FFT by the FFT length. This option is useful when you want
the output of the FFT to stay in the same amplitude range as its
input. This is particularly useful when working with fixed-point
data types.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

— When you clear the Divide butterfly outputs by two


check box, the block computes the ideal output word and
fraction lengths according to the following equations:

WLideal output = WLinput + floor(log 2 ( FFT length − 1)) + 1

FLideal output = FLinput

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

Example Bit-Reversed Order


Two numbers are bit-reversed values of each other when the binary
representation of one is the mirror image of the binary representation
of the other. For example, in a three-bit system, one and four
are bit-reversed values of each other because the three-bit binary
representation of one, 001, is the mirror image of the three-bit binary

1-54
2-D FFT

representation of four, 100. The following diagram shows the row


indices in linear order. To put them in bit-reversed order

1 Translate the indices into their binary representation with the


minimum number of bits. In this example, the minimum number of
bits is three because the binary representation of 7 is 111.

2 Find the mirror image of each binary entry, and write it beside the
original binary representation.

3 Translate the indices back to their decimal representation.

The row indices now appear in bit-reversed order.

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

Input to FFT block


(must be linear order)
⎡7 6 7 1 3 6 2 3⎤
⎢1 3 7 8 7 0 1 6 ⎥⎥
⎢ Output in linear order
⎢4 4 3 1 3 5 1 6⎥
⎢ ⎥
⎢3 6 7 4 3 3 5 4⎥
⎢7 7 0 2 6 6 2 3⎥
⎢ ⎥
⎢6 5 2 1 4 4 4 7⎥
⎢3 1 6 0 1 5 1 6⎥
⎢ ⎥ Output in bit-reversed order
⎢⎣0 3 0 5 5 3 5 5 ⎥⎦

Output in linear order


1 2 3 4 5 6 7
Linearly ordered row 0
and column indices

0 ⎡ 245 13.9 − 0.4i 10 − 5i −15.9 + 21.6i −13 −15.9 − 21.6i 10 + 5i 13.9 ⎤


⎢ −4.3 − 10.3i −27.6 − 6.6i −5.6 + 13.1i 6.2 + 13i ⎥⎥
1 ⎢ −3.4 + 8.7i 1 .1 − i −2.6i −11.5 − 11i
2 ⎢ 18 − 5i −4.3 − 10.4i 19 − 24i 12.4 − 11.4i 6 − 3i −5.7 + 16.4i 5 + 4i 5 .5 + 1 .4 i ⎥
⎢ ⎥
3 ⎢ 8 .4 − 2 .4 i −0.6 + 2.7i −4.5 + 1.1i 17.6 + 9.4i 11 − 9i −2.2 − 13i −18.4 + 25.1i 34 + 0.5i ⎥
4 ⎢

−9 16.3 + 5.9i 14 − 31i 17.7 + 23.9i 1 17.7 − 23.9i 14 + 31i 16.3 − 5.9i ⎥

5 ⎢ 8 .4 + 2 .4 i 3.4 − 5.4i −18.4 − 25.1i −2.2 + 13.1i 11 + 9i 17.6 − 9.4i −4.5 − 1.1i −1 − 2.7i ⎥
6 ⎢ 18 + 5i

5 .5 − 1 .4 i 5 − 4i −5.7 − 16.4i 6 + 3i 12.5 + 11.3i 19 + 24i −4.3 + 10.4i ⎥

7 ⎢⎣ −4.4 + 10.3i 6.2 − 13i −11.5 + 11i 2 .6 i 1 .1 + i −3.4 − 8.7i −5.6 − 13.1i −27.6 + 6.6i ⎥⎦

Output in bit-reversed order

0 1 2 3 4 5 6 7
Bit-reversed row
and column indices

0 ⎡ 245 −13 10 − 5i 10 + 5i 13.9 − 0.4i −15.9 − 21.6i −15.9 + 21.6i 13.9 ⎤


⎢ ⎥
1 ⎢ −9 1 14 − 31i 14 + 31i 16.3 + 5.9i 17.7 − 23.9i 17.7 + 23.9i 16.3 − 5.9i ⎥
2 ⎢ 18 − 5i 6 − 3i 19 − 24i 5 + 4i −4.3 − 10.4i −5.7 + 16.4i 12.4 − 11.4i 5 .5 + 1 .4 i⎥
⎢ ⎥
3 ⎢ 18 + 5i 6 + 3i 5 − 4i 19 + 24i 5 .5 − 1 .4 i 12.5 + 11.3i −5.7 − 16.4i 34 + 0.5i ⎥
4 ⎢ −4.3 − 10.3i 1.1 − i −5.6 + 13.1i −11.5 − 11i −27.6 − 6.6i −2.6i −3.4 + 8.7i 6.2 + 13i ⎥
⎢ ⎥
5 ⎢ 8.4 + 2.4 4i 11 + 9i −18.4 − 25.1i −4.5 − 1.1i 3 .4 − 5 .4 i 17.6 − 9.4i −2.2 + 13i −1 − 2.7 7i ⎥
6 ⎢ 8 .4 − 2 .4 i 11 − 9i −4.5 + 1.1i −18.4 + 25.1i −0.6 + 2.7i −2.2 − 13i 17.6 + 9.4i 34 + 0.5i ⎥
7 ⎢ ⎥
⎢⎣ −4.4 + 10.3i 1 .1 + i −11.5 + 11i −5.6 − 13.1 6.2 − 13i −3.4 − 8.7i 2 .6 i −27.6 + 6.6i ⎥⎦

1-56
2-D FFT

References [1] FFTW (http://www.fftw.org)

[2] Frigo, M. and S. G. Johnson, “FFTW: An Adaptive Software


Architecture for the FFT,”Proceedings of the International Conference on
Acoustics, Speech, and Signal Processing, Vol. 3, 1998, pp. 1381-1384.

See Also 2-D DCT Computer Vision System Toolbox software


2-D IDCT Computer Vision System Toolbox software
2-D IFFT Computer Vision System Toolbox software
2-D IFFT Computer Vision System Toolbox software
bitrevorder Signal Processing Toolbox software
fft MATLAB
ifft MATLAB
“Simulink Coder” Simulink Coder

1-57
2-D FFT (To Be Removed)

Purpose Compute two-dimensional fast Fourier transform of input

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.

Refer to “FFT and IFFT Support for Non-Power-of-Two Transform


Length with FFTW Library” in the R2011b Release Notes for details
related to these changes.

1-58
2-D FIR Filter

Purpose Perform 2-D FIR filtering on input matrix

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

Use the Filtering based on parameter to specify the algorithm by


which the block filters the input matrix. If you select Convolution and
set the Output size parameter to Full, the block filters your input
using the following algorithm

( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) * H (i − m, j − n)
m =0 n =0

where 0 ≤ i < Ma + Mh − 1 and 0 ≤ j < Na + Nh − 1 . If you select


Correlation and set the Output size parameter to Full, the block
filters your input using the following algorithm

( Ma −1) ( Na −1)
C(i, j) = ∑ ∑ A(m, n) ⋅ conj( H (m + i, n + j))
m =0 n =0

where 0 ≤ i < Ma + Mh − 1 and 0 ≤ j < Na + Nh − 1 .


TThe imfilter function from the Image Processing Toolbox™ product
similarly performs N-D filtering of multidimensional images.

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D FIR Filter
block for fixed-point signals.

The result of each addition remains


in the accumulator data type

Input (A) data type


COMPLEX CAST ADDER CAST
MULTIPLIER Accumulator or Output (C)
Filter coefficient Product output Accumulator Accumulator data type
(H) data type data type data type data type

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

Separable filter coefficients


Select this 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.
Coefficient source
Specify how to define your filter coefficients. Select Specify via
dialog to enter your coefficients in the block parameters dialog
box. Select Input port to specify your filter coefficient matrix
using port H or ports HH and HV.
Coefficients
Enter your real or complex-valued filter coefficient matrix. This
parameter appears if you clear the Separable filter coefficients
check box and then select a Coefficient source of Specify via
dialog. Tunable.
Vertical coefficients (across height)
Enter the vector of vertical filter coefficients for your separable
filter. This parameter appears if you select the Separable filter
coefficients check box and then select aCoefficient source of
Specify via dialog.
Horizontal coefficients (across width)
Enter the vector of horizontal filter coefficients for your separable
filter. This parameter appears if you select the Separable filter
coefficients check box and then select aCoefficient source of
Specify via dialog.
Output size
This parameter controls the size of the filtered output. If you
choose Full, the output has dimensions (Ma+Mh-1, Na+Nh-1).
If you choose Same as input port I, the output has the same
dimensions as the input at port I If you choose Valid, output has
dimensions (Ma-Mh+1, Na-Nh+1).
Padding options
Specify how to pad the boundary of your input matrix. Select
Constant to pad your matrix with a constant value. Select
Replicate to pad your input matrix by repeating its border

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 fraction length of the coefficients 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 fixdt(1,16), you can enter the word length of
the coefficients, in bits. In this mode, the block automatically
sets the fraction length of the coefficients 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 fixdt(1,16,0), you can enter the word length
and the fraction length of the coefficients, in bits.
• When you select <data type expression>, you can enter the
data type expression.

The filter coefficients do not obey the Rounding mode and the
Overflow mode parameters; instead, they always saturated and
rounded to Nearest.

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

Sign of Input I1 Sign of Input I2 Sign of Product


Output
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

• When you select fixdt([],16,0), 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.

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.

1-69
2-D FIR Filter

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.

See Also imfilter Image Processing Toolbox

1-70
2-D Histogram

Purpose Generate histogram of input or sequence of inputs

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.

y = hist(u,n) % Equivalent MATLAB code

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

and centers located at

 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.

Resetting the Running Histogram


The block resets the running histogram whenever a reset event is
detected at the optional Rst port. The reset signal and the input data
signal must be the same rate.
You specify the reset event using the Reset port menu:

• None — Disables the Rst port

• Rising edge — Triggers a reset operation when the Rst input does
one of the following:
- Rises from a negative value to a positive value or zero
- Rises from zero to a positive value, where the rise is not a
continuation of a rise from a negative value to zero (see the
following figure)

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

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described earlier)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

Dialog The Main pane of the 2-D Histogram block dialog appears as follows.
Box

1-75
2-D Histogram

Lower limit of histogram


Enter a real-valued scalar for the lower boundary, Bm, of the
lowest-valued bin. NaN and inf are not valid values for Bm.
Tunable.

1-76
2-D Histogram

Upper limit of histogram


Enter a real-valued scalar for the upper boundary, BM, of the
highest-valued bin. NaN and inf are not valid values for BM.
Tunable.
Number of bins
The number of bins, n, in the histogram.
Find the histogram over
Specify whether the block finds the histogram over the entire
input or along each column of the input.

Note The option will be removed in a future release.

Normalized
When selected, the output vector, v, is normalized such that
sum(v) = 1.

Use of this parameter is not supported for fixed-point signals.


Running histogram
Set to enable the running histogram operation, and clear to enable
basic histogram operation. For more information, see “Basic
Operation” on page 1-72 and “Running Operation” on page 1-72.
Reset port
The type of event that resets the running histogram. For more
information, see “Resetting the Running Histogram” on page 1-73.
The reset signal and the input data signal must be the same rate.
This parameter is enabled only when you select the Running
histogram check box. For more information, see “Running
Operation” on page 1-72.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.

1-79
2-D Histogram

Supported Port Supported Data Types


Data
In • Double-precision floating point
Types
• Single-precision floating point
• Fixed point (signed and unsigned)
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Output • Double-precision floating point
• Single-precision floating point
• 32-bit unsigned integers
Rst • Double-precision floating point
• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

Examples Calculate Histogram of R, G, and B Values


The “Histogram Display” example uses the Histogram block to calculate
the histograms of R, G, and B values in each video frame.

See Also hist MATLAB

1-80
2-D Histogram (To Be Removed)

Purpose Generate histogram of each input matrix

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-81
2-D IDCT

Purpose Compute 2-D inverse discrete cosine transform (IDCT)

Library Transforms
visiontransforms

Description The 2-D IDCT block calculates the two-dimensional inverse


discrete cosine transform of the input signal. The equation for the
two-dimensional IDCT is

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

Output 2-D IDCT of the input Same as Input port No

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.

Fixed-Point Data Types


The following diagram shows the data types used in the 2-D IDCT block
for fixed-point signals. Inputs are first cast to the output data type and
stored in the output buffer. Each butterfly stage processes signals in
the accumulator data type, with the final output of the butterfly being
cast back into the output data type.

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.

Sine and cosine computation


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

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

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 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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

• 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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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:

WLideal output = WLinput + floor(log 2 ( DCT length − 1)) + 1

FLideal output = FLinput

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

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

See Also 2-D DCT Computer Vision System Toolbox software


2-D FFT Computer Vision System Toolbox software
2-D IFFT Computer Vision System Toolbox software

1-89
2-D IFFT

Purpose 2-D Inverse fast Fourier transform of input

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:

y = ifft2(A) % Equivalent MATLAB code

Computing the IFFT of each dimension of the input matrix is equivalent


to calculating the two-dimensional inverse discrete Fourier transform
(IDFT), which is defined by the following equation:

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

Output 2-D IFFT of the Same as Input port Yes


input

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

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 Algorithms for Real or Complex Input Complexity


Floating-Point Signals

Parameter Settings Algorithms Used for IFFT Computation


Butterfly operation and radix-2 DIT

Radix-2 DIF

Butterfly operation and radix-2 DIT in conjunction


with the half-length and double-signal algorithms

Radix-2 DIF in conjunction with the half-length and


double-signal algorithms

1-92
2-D IFFT

Radix-2 Algorithms for Real or Complex Input Complexity


Fixed-Point Signals
Other Parameter Settings Algorithms Used for IFFT Computation
Butterfly operation and radix-2 DIT

Radix-2 DIF

Note The Input is conjugate symmetric parameter cannot be used


for fixed-point signals.

Radix-2 Optimization for the Table of Trigonometric Values


In certain situations, the block’s Radix–2 algorithm computes all the
possible trigonometric values of the twiddle factor

2πk
j
e K

where K is the greater value of either M or N and k = 0, , K − 1 .


The block stores these values in a table and retrieves them during
simulation. The number of table entries for fixed-point and
floating-point is summarized in the following table:

Number of Table Entries for N-Point FFT


floating-point 3 N/4
fixed-point N

Fixed-Point Data Types


The following diagrams show the data types used in the IFFT block for
fixed-point signals. You can set the sine table, accumulator, product

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

The multiplier output appears in the accumulator data type because


both of the inputs to the multiplier are complex. For details on the
complex multiplication performed, refer to “Multiplication Data Types”
in the DSP System Toolbox documentation.

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 Radix-2 for bit-reversed processing, fixed


or floating-point data, or for 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. See “Radix-2
Implementation” on page 1-91.

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.

For more information ordering of the output, see “Bit-Reversed


Order” on page 1-54. The 2-D FFT block bit-reverses the order of
both the columns and the rows.
Input is conjugate symmetric
Select this option when the block inputs both floating point and
conjugate symmetric, and you want real-valued outputs. This
parameter cannot be used for fixed-point signals. Selecting this
check box optimizes the block’s computation method.

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

matrix produces real-valued output. Therefore, if the input to the


block is both floating point and conjugate symmetric, and you
select the this check box, the block produces real-valued outputs.

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 .

The scaled version of the IFFT multiplies the above unscaled

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

— When you clear the Divide butterfly outputs by two


check box, the block computes the ideal output word and
fraction lengths according to the following equations:

WLideal output = WLinput + floor(log 2 ( FFT length − 1)) + 1

FLideal output = FLinput

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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] FFTW (http://www.fftw.org)

[2] Frigo, M. and S. G. Johnson, “FFTW: An Adaptive Software


Architecture for the FFT,”Proceedings of the International Conference on
Acoustics, Speech, and Signal Processing, Vol. 3, 1998, pp. 1381-1384.

1-103
2-D IFFT

See Also 2-D DCT Computer Vision System Toolbox software


2-D FFT Computer Vision System Toolbox software
2-D IDCT Computer Vision System Toolbox software
2-D FFT Computer Vision System Toolbox software
2-D IFFT Computer Vision System Toolbox software
bitrevorder Signal Processing Toolbox software
fft MATLAB
ifft MATLAB
“Simulink Coder” Simulink

1-104
2-D IFFT (To Be Removed)

Purpose Compute 2-D IFFT of input

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.

Refer to “FFT and IFFT Support for Non-Power-of-Two Transform


Length with FFTW Library” in the R2011b Release Notes for details
related to these changes.

1-105
2-D Maximum

Purpose Find maximum values in input or sequence of inputs

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

Port Input/Output Supported Data Types


Input Scalar, vector or matrix of • Double-precision
intensity values floating point
• Single-precision
floating point
• Fixed point (signed and
unsigned)
• Boolean
• 8-, 16-, and 32-bit
signed integers
• 8-, 16-, and 32-bit
unsigned integers
Rst Scalar value • Double-precision
floating point

1-106
2-D Maximum

Port Input/Output Supported Data Types

• Single-precision
floating point
• Boolean
• 8-, 16-, and 32-bit
signed integers
• 8-, 16-, and 32-bit
unsigned integers

Val Maximum value output • Double-precision


based on the “Value Mode” floating point
on page 1-108
• Single-precision
floating point
• Fixed point (signed and
unsigned)
• Boolean
• 8-, 16-, and 32-bit
signed integers
• 8-, 16-, and 32-bit
unsigned integers
Idx One-based output location • Double-precision
of the maximum value floating point
based on the “Index Mode”
• 32-bit unsigned
on page 1-109
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:

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the maximum
value of each vector over the second dimension of the input. For an
M-by-N input matrix, the block outputs an M-by-1 column vector at
each sample time.
• Each column — The output at each sample time consists of a
1-by-N-by-P array, where each element contains the maximum value
of each vector over the first dimension of the input. For an M-by-N
input matrix, the block outputs a 1-by-N row vector at each sample
time.
In this mode, the block treats length-M unoriented vector inputs
as M-by-1 column vectors.
• Entire input — The output at each sample time is a scalar that
contains the maximum value in the M-by-N-by-P input matrix.
• Specified dimension — The output at each sample time depends on
Dimension. When you set Dimension to 1, the block output is the
same as when you select Each column. When you set Dimension
to 2, the block output is the same as when you select Each row.
When you set Dimension to 3, the block outputs an M-by-N
matrix containing the maximum value of each vector over the third
dimension of the input, at each sample time.

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:

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the index of the
maximum value of each vector over the second dimension of the
input. For an input that is an M-by-N matrix, the output at each
sample time is an M-by-1 column vector.
• Each column — The output at each sample time consists of a
1-by-N-by-P array, where each element contains the index of the
maximum value of each vector over the first dimension of the input.
For an input that is an M-by-N matrix, the output at each sample
time is a 1-by-N row vector.
In this mode, the block treats length-M unoriented vector inputs
as M-by-1 column vectors.
• Entire input — The output at each sample time is a 1-by-3 vector
that contains the location of the maximum value in the M-by-N-by-P

1-109
2-D Maximum

input matrix. For an input that is an M-by-N matrix, the output


will be a 1-by-2 vector of one-based [x y] location coordinates for the
maximum value.
• Specified dimension — The output at each sample time depends
on Dimension. If Dimension is set to 1, the output is the same as
when you select Each column. If Dimension is set to 2, the output
is the same as when you select Each row. If Dimension is set to
3, the output at each sample time is an M-by-N matrix containing
the indices of the maximum values of each vector over the third
dimension of the input.

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.

Value and Index Mode


When you set the Mode parameter to Value and Index, the block
outputs both the maxima and the indices.

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.

Resetting the Running Maximum


The block resets the running maximum whenever a reset event is
detected at the optional Rst port. The reset sample time must be a
positive integer multiple of the input sample time.
You specify the reset event in the Reset port menu:

• None — Disables the Rst port.

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

Not a rising edge because it is


Rising edge a continuation of a rise from
Rising edge a negative value to zero.

• 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

Falling edge Falling edge

Not a falling edge because it is


Falling edge a continuation of a fall from
Falling edge a positive value to zero.

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described above)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

Note When running simulations in the Simulink MultiTasking


mode, reset signals have a one-sample latency. Therefore, when the
block detects a reset event, there is a one-sample delay at the reset
port rate before the block applies the reset.

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.

Output = Single statistic for all ROIs

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

Output = Individual statistics for each ROI

Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.

Output = Single statistic for all ROIs

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.

Fixed-Point Data Types


The parameters on the Data Types pane of the block dialog 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.

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

• Value — Output the maximum value of each input matrix. For


more information, see “Value Mode” on page 1-108.
• Index— Output the one-based index location of the maximum
value. For more information, see “Index Mode” on page 1-109.
• Running — Track the maximum value of the input sequence
over time. For more information, see “Running Mode” on page
1-110.

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 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.

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.

See ROI Output Statistics on page 113 for details.


ROI portion to process
Specify whether you want to calculate the statistical value for the
entire ROI or just the ROI perimeter. This parameter applies only
when you set the ROI type parameter to 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
does not apply when you set the ROI type parameter, to Binary
mask.
Output flag indicating if ROI is within image bounds
When you select this check box, the Flag port appears on the
block. This check box applies only when you set the ROI type
parameter to Rectangles or Lines. For a description of the Flag
port output, see the tables in “ROI Processing” on page 1-112.

1-117
2-D Maximum

Output flag indicating if label numbers are valid


When you select this check box, the Flag port appears on the
block. This check box applies only when you set the ROI type
parameter to Label matrix. For a description of the Flag port
output, see the tables in “ROI Processing” on page 1-112.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.

1-119
2-D Maximum

Accumulator data type


Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-114 for illustrations depicting the use of the accumulator
data type in this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit: Same
as product output
• An expression that evaluates to a valid data type, for example,
fixdt([],16,0)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

See Also 2-D Mean Computer Vision


System Toolbox
2-D Minimum Computer Vision
System Toolbox
MinMax Simulink
max MATLAB

1-121
2-D Maximum (To Be Removed)

Purpose Find maximum values in an input or sequence of inputs

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-122
2-D Mean

Purpose Find mean value of each input matrix

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

Port Supported Data Types


Input • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Reset • Double-precision floating point
• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

1-123
2-D Mean

Port Supported Data Types


ROI Rectangles and lines:

• Double-precision floating point


• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

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

value over parameter. For example, consider a 3-dimensional input


signal of size M-by-N-by-P:

• Entire input — The output at each sample time is a scalar that


contains the mean value of the M-by-N-by-P input matrix.

y = mean(u(:)) % Equivalent MATLAB code

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the mean value of
each vector over the second dimension of the input. For an input that
is an M-by-N matrix, the output at each sample time is an M-by-1
column vector.

y = mean(u,2) % Equivalent MATLAB code

• Each column — The output at each sample time consists of a


1-by-N-by-P array, where each element contains the mean value of
each vector over the first dimension of the input. For an input that
is an M-by-N matrix, the output at each sample time is a 1-by-N
row vector.

y = mean(u) % Equivalent MATLAB code

In this mode, the block treats length-M unoriented vector inputs


as M-by-1 column vectors.
• Specified dimension — The output at each sample time depends
on the value of the Dimension parameter. If you set the Dimension
to 1, the output is the same as when you select Each column. If you
set the Dimension to 2, the output is the same as when you select
Each row. If you set the Dimension to 3, the output at each sample
time is an M-by-N matrix containing the mean value of each vector
over the third dimension of the input.

y = mean(u,Dimension) % Equivalent MATLAB code

The mean of a complex input is computed independently for the real


and imaginary components, as shown in the following figure.

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.

Resetting the Running Mean


The block resets the running mean whenever a reset event is detected
at the optional Rst port. The reset sample time must be a positive
integer multiple of the input sample time.
When a reset event occurs, the running mean for each channel is
initialized to the value in the corresponding channel of the current
input.
You specify the reset event by the Reset port parameter:

• None disables the Rst port.


• Rising edge — Triggers a reset operation when the Rst input does
one of the following:
- Rises from a negative value to a positive value or zero
- Rises from zero to a positive value, where the rise is not a
continuation of a rise from a negative value to zero (see the
following figure)

1-126
2-D Mean

Rising edge
Rising edge

Not a rising edge because it is


Rising edge a continuation of a rise from
Rising edge a negative value to zero.

• 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)

Falling edge Falling edge

Not a falling edge because it is


Falling edge a continuation of a fall from
Falling edge a positive value to zero.

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described earlier)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

1-127
2-D Mean

Note When running simulations in the Simulink MultiTasking mode,


reset signals have a one-sample latency. Therefore, when the block
detects a reset event, there is a one-sample delay at the reset port rate
before the block applies the reset.

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.

• A binary mask is a binary image that enables you to specify which


pixels to highlight, or select.
• In a label matrix, pixels equal to 0 represent the background, pixels
equal to 1 represent the first object, pixels equal to 2 represent the
second object, and so on. When the ROI type parameter is set to
Label matrix, the Label and Label Numbers ports appear on the
block. Use the Label Numbers port to specify the objects in the label
matrix for which the block calculates statistics. The input to this
port must be a vector of scalar values that correspond to the labeled
regions in the label matrix.
• For more information about the format of the input to the ROI port
when the ROI is a rectangle or a line, see the Draw Shapes reference
page.

For more information about the format of the input to the ROI port
when the ROI is a rectangle or a line, see the Draw Shapes block
reference page.

1-128
2-D Mean

Note For rectangular ROIs, use the ROI portion to process


parameter to specify whether to calculate the statistical value for the
entire ROI or just the ROI perimeter.

Use the Output parameter to specify the block output. The block can
output separate statistical values for each ROI or the statistical value
for all specified ROIs. This parameter is not available if, for the ROI
type parameter, you select Binary mask.
If, for the ROI type parameter, you select Rectangles or Lines, the
Output flag indicating if ROI is within image bounds check box
appears in the dialog box. If you select this check box, the Flag port
appears on the block. The following tables describe the Flag port output
based on the block parameters.

Output = Individual statistics for each ROI

Flag Description
Port
Output
0 ROI is completely outside the input image.
1 ROI is completely or partially inside the input image.

Output = Single statistic for all ROIs

Flag 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.

Output = Individual statistics for each ROI

Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.

Output = Single statistic for all ROIs

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.

Fixed-Point Data Types


The following diagram shows the data types used within the Mean
block for fixed-point signals.

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

Find the mean value over


Specify whether to find the mean value along rows, columns,
entire input, or the dimension specified in the Dimension
parameter. For more information, see “Basic Operation” on page
1-124.
Dimension
Specify the dimension (one-based value) of the input signal,
over which the mean is computed. The value of this parameter
cannot exceed the number of dimensions in the input signal. This
parameter is only visible when the Find the mean value over
parameter is set to Specified dimension.
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 mean 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

Output flag indicating if ROI is within image bounds

Output flag indicating if label numbers are valid

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 Output flag indicating if ROI is within image bounds


check box is only visible when you select Rectangles or Lines
as the ROI type.

The Output flag indicating if label numbers are valid check


box is only visible when you select Label matrix for the ROI
type parameter.

The Data Types pane of the Mean block dialog appears as follows.

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

• A rule that inherits a data type, for example, Inherit: Same


as input
• An expression that evaluates to a valid data type, for example,
fixdt([],16,0)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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.

See Also 2-D Maximum Computer Vision System Toolbox

2D-Median Computer Vision System Toolbox


2-D Minimum Computer Vision System Toolbox
2-D Standard Computer Vision System Toolbox
Deviation
mean MATLAB

1-137
2-D Mean (To Be Removed)

Purpose Find mean value of each input matrix

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-138
2-D Median

Purpose Find 2-D Median value of each input matrix

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:

1 The values are sorted.

2 If the number of values is odd, the median is the middle value.

3 If the number of values is even, the median is the average of the


two middle values.

For a given input u, the size of the output array y depends on the setting
of the Find the median value over parameter. For example, consider
a 3-dimensional input signal of size M-by-N-by-P:

• Entire input — The output at each sample time is a scalar that


contains the median value of the M-by-N-by-P input matrix.

y = median(u(:)) % Equivalent MATLAB code

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the median value of
each vector over the second dimension of the input. For an input that
is an M-by-N matrix, the output is an M-by-1 column vector.

y = median(u,2) % Equivalent MATLAB code

• Each column — The output at each sample time consists of a


1-by-N-by-P array, where each element contains the median value of
each vector over the first dimension of the input. For an input that
is an M-by-N matrix, the output at each sample time is a 1-by-N
row vector.

1-139
2-D Median

y = median(u) % Equivalent MATLAB code

For convenience, length-M 1-D vector inputs are treated as M-by-1


column vectors when the block is in this mode. Sample-based
length-M row vector inputs are also treated as M-by-1 column vectors.
• Specified dimension — The output at each sample time depends
on Dimension. If Dimension is set to 1, the output is the same as
when you select Each column. If Dimension is set to 2, the output
is the same as when you select Each row. If Dimension is set to 3,
the output at each sample time is an M-by-N matrix containing the
median value of each vector over the third dimension of the input.

y = median(u,Dimension) % Equivalent MATLAB code

The block sorts complex inputs according to their magnitude.

Fixed-Point Data Types


For fixed-point inputs, you can specify accumulator, product output,
and output data types as discussed in “Dialog Box” on page 1-141.
Not all these fixed-point parameters are applicable for all types of
fixed-point inputs. The following table shows when each kind of data
type and scaling is used.

Accumulator data Product output


Output data type type data type
Even M X X
Odd M X
Odd M and X X X
complex
Even M and X X X
complex

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.

Note Floating-point inheritance takes precedence over the data type


settings defined on this pane. When inputs are floating point, the block
ignores these settings, and all internal data types are floating point.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.
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

Supported Port Supported Data Types


Data
Input • Double-precision floating point
Types
• Single-precision floating point
• Fixed point (signed and unsigned)
• 8-, 16-, 32-, and 128-bit signed integers
• 8-, 16-, 32-, and 128-bit unsigned integers
Output • Double-precision floating point
• Single-precision floating point
• Fixed point (signed and unsigned)
• 8-, 16-, 32-, and 128-bit signed integers
• 8-, 16-, 32-, and 128-bit unsigned integers

Examples Calculate Median Value Over Entire Input

The ex_vision_2dmedian calculates the median value over the entire


input.

See Also 2-D Maximum Computer Vision System Toolbox


2-D Mean Computer Vision System Toolbox
2-D Minimum Computer Vision System Toolbox

1-146
2-D Median

2-D Standard Computer Vision System Toolbox


Deviation
2-D Variance Computer Vision System Toolbox
median MATLAB

1-147
2-D Minimum

Purpose Find minimum values in input or sequence of inputs

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

Length-M 1-D vector inputs are treated as M-by-1 column vectors.

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:

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the minimum value
of each vector over the second dimension of the input. For an M-by-N
input matrix, the block outputs an M-by-1 column vector at each
sample time.
• Each column — The output at each sample time consists of a
1-by-N-by-P array, where each element contains the minimum value
of each vector over the first dimension of the input. For an M-by-N
input matrix, the block outputs a 1-by-N row vector at each sample
time.
In this mode, the block treats length-M unoriented vector inputs
as M-by-1 column vectors.

1-149
2-D Minimum

• Entire input — The output at each sample time is a scalar that


contains the minimum value in the M-by-N-by-P input matrix.
• Specified dimension — The output at each sample time depends on
Dimension. When you set Dimension to 1, the block output is the
same as when you select Each column. When you set Dimension
to 2, the block output is the same as when you select Each row.
When you set Dimension to 3, the block outputs an M-by-N
matrix containing the minimum value of each vector over the third
dimension of the input, at each sample time.

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:

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the index of the

1-150
2-D Minimum

minimum value of each vector over the second dimension of the


input. For an input that is an M-by-N matrix, the output at each
sample time is an M-by-1 column vector.
• Each column — The output at each sample time consists of a
1-by-N-by-P array, where each element contains the index of the
minimum value of each vector over the first dimension of the input.
For an input that is an M-by-N matrix, the output at each sample
time is a 1-by-N row vector.
In this mode, the block treats length-M unoriented vector inputs
as M-by-1 column vectors.
• Entire input — The output at each sample time is a 1-by-3 vector
that contains the location of the minimum value in the M-by-N-by-P
input matrix. For an input that is an M-by-N matrix, the output
will be a 1-by-2 vector of one-based [x y] location coordinates for the
minimum value.
• Specified dimension — The output at each sample time depends
on Dimension. If Dimension is set to 1, the output is the same as
when you select Each column. If Dimension is set to 2, the output
is the same as when you select Each row. If Dimension is set to
3, the output at each sample time is an M-by-N matrix containing
the indices of the minimum values of each vector over the third
dimension of the input.

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.

Value and Index Mode


When you set the Mode parameter to Value and Index, the block
outputs both the minima, and the indices.

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.

Resetting the Running Minimum


The block resets the running minimum whenever a reset event is
detected at the optional Rst port. The reset sample time must be a
positive integer multiple of the input sample time.
You specify the reset event by the Reset port parameter:

• None — Disables the Rst port


• Rising edge — Triggers a reset operation when the Rst input does
one of the following:
- Rises from a negative value to a positive value or zero
- Rises from zero to a positive value, where the rise is not a
continuation of a rise from a negative value to zero (see the
following figure)

Rising edge
Rising edge

Not a rising edge because it is


Rising edge a continuation of a rise from
Rising edge a negative value to zero.

• 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

- 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)

Falling edge Falling edge

Not a falling edge because it is


Falling edge a continuation of a fall from
Falling edge a positive value to zero.

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described above)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

Note When running simulations in the Simulink MultiTasking mode,


reset signals have a one-sample latency. Therefore, when the block
detects a reset event, there is a one-sample delay at the reset port rate
before the block applies the reset.

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

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,
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.

Output = Single statistic for all ROIs

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

Output = Individual statistics for each ROI

Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.

Output = Single statistic for all ROIs

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.

Fixed-Point Data Types


The parameters on the Fixed-point pane of the dialog box 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.

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

• Value — Output the minimum value of each input matrix. For


more information, see “Value Mode” on page 1-149
• Index— Output the one-based index location of the minimum
value. For more information, see “Index Mode” on page 1-150
• Running — Track the minimum value of the input sequence
over time. For more information, see “Running Mode” on page
1-152.

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 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.

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.

See Output = Individual statistics for each ROI on page 1-154


for details.
ROI portion to process
Specify whether you want to calculate the statistical value for the
entire ROI or just the ROI perimeter. This parameter applies only
when you set the ROI type parameter to 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
does not apply when you set the ROI type parameter, to Binary
mask.
Output flag indicating if ROI is within image bounds
When you select this check box, the Flag port appears on the
block. This check box applies only when you set the ROI type
parameter to Rectangles or Lines. For a description of the Flag
port output, see the tables in “ROI Processing” on page 1-153.

1-158
2-D Minimum

Output flag indicating if label numbers are valid


When you select this check box, the Flag port appears on the
block. This check box applies only when you set the ROI type
parameter to Label matrix. For a description of the Flag port
output, see the tables in “ROI Processing” on page 1-153.

The Fixed-point pane of the 2-D Minimum dialog box appears as


shown in the following figure.

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)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Product output data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.

1-160
2-D Minimum

Accumulator data type


Specify the accumulator data type. See “Fixed-Point Data Types”
on page 1-155 for illustrations depicting the use of the accumulator
data type in this block. You can set this parameter to:
• A rule that inherits a data type, for example, Inherit: Same
as input
• An expression that evaluates to a valid data type, for example,
fixdt([],16,0)

Click the Show data type assistant button to


display the Data Type Assistant, which helps you set the
Accumulator data type parameter.

See “Specify Data Types Using Data Type Assistant” for more
information.

Examples

The ex_vision_2dminimum example finds the minimum value within


two ROIs. The model outputs the minimum values and their one-based
[x y] coordinate locations.

1-161
2-D Minimum

See Also 2-D Maximum Computer Vision System


Toolbox
2-D Mean Computer Vision System
Toolbox
MinMax Simulink
2D-Histogram Computer Vision System
Toolbox
min MATLAB

1-162
2-D Minimum (To Be Removed)

Purpose Find minimum values in an input or sequence of inputs

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-163
2-D Standard Deviation

Purpose Find standard deviation of each input matrix

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

Port Supported Data Types


Input • Double-precision floating point
• Single-precision floating point
Reset • Double-precision floating point
• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

1-164
2-D Standard Deviation

Port Supported Data Types


ROI Rectangles and lines:

• Double-precision floating point


• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

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:

• Entire input — The output at each sample time is a scalar that


contains the standard deviation of the entire input.

1-165
2-D Standard Deviation

y = std(u(:)) % Equivalent MATLAB code

• Each Row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the standard
deviation of each vector over the second dimension of the input. For
an input that is an M-by-N matrix, the output at each sample time is
an M-by-1 column vector.

y = std(u,0,2) % Equivalent MATLAB code

• Each Column — The output at each sample time consists of a


1-by-N-by-P array, where each element contains the standard
deviation of each vector over the first dimension of the input. For an
input that is an M-by-N matrix, the output at each sample time is a
1-by-N row vector.

y = std(u,0,1) % Equivalent MATLAB code

In this mode, the block treats length-M unoriented vector inputs


as M-by-1 column vectors.
• Specified Dimension — The output at each sample time depends
on Dimension. If Dimension is set to 1, the output is the same as
when you select Each column. If Dimension is set to 2, the output
is the same as when you select Each row. If Dimension is set to
3, the output at each sample time is an M-by-N matrix containing
the standard deviation of each vector over the third dimension of
the input.

y = std(u,0,Dimension) % Equivalent MATLAB code

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.

Resetting the Running Standard Deviation


The block resets the running standard deviation whenever a reset event
is detected at the optional Rst port. The reset sample time must be a
positive integer multiple of the input sample time.
You specify the reset event in the Reset port parameter:

• None disables the Rst port.


• Rising edge — Triggers a reset operation when the Rst input does
one of the following:
- Rises from a negative value to a positive value or zero
- Rises from zero to a positive value, where the rise is not a
continuation of a rise from a negative value to zero (see the
following figure)

1-167
2-D Standard Deviation

Falling edge Falling edge

Not a falling edge because it is


Falling edge a continuation of a fall from
Falling edge a positive value to zero.

• 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

Not a rising edge because it is


Rising edge a continuation of a rise from
Rising edge a negative value to zero.

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described earlier)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

1-168
2-D Standard Deviation

Note When running simulations in the Simulink MultiTasking


mode, reset signals have a one-sample latency. Therefore, when the
block detects a reset event, there is a one-sample delay at the reset
port rate before the block applies the reset.

ROI To calculate the statistical value within a particular region of interest


Processing (ROI) of the input, select the Enable ROI processing check box. This
option is only available when the Find the standard deviation value
over parameter is set to Entire input and the Running standard
deviation check box is not selected. ROI processing is only supported
for 2-D inputs.
Use the ROI type parameter to specify whether the ROI is a rectangle,
line, label matrix, or binary mask. A binary mask is a binary image
that enables you to specify which pixels to highlight, or select. In a label
matrix, pixels equal to 0 represent the background, pixels equal to 1
represent the first object, pixels equal to 2 represent the second object,
and so on. When the ROI type parameter is set to Label matrix, the
Label and Label Numbers ports appear on the block. Use the Label
Numbers port to specify the objects in the label matrix for which the
block calculates statistics. The input to this port must be a vector
of scalar values that correspond to the labeled regions in the label
matrix. For more information about the format of the input to the ROI
port when the ROI is a rectangle or a line, see the Draw Shapes block
reference page.
For rectangular ROIs, use the ROI portion to process parameter to
specify whether to calculate the statistical value for the entire ROI
or just the ROI perimeter.
Use the Output parameter to specify the block output. The block can
output separate statistical values for each ROI or the statistical value
for all specified ROIs. This parameter is not available if, for the ROI
type parameter, you select Binary mask.
If, for the ROI type parameter, you select Rectangles or Lines, the
Output flag indicating if ROI is within image bounds check box

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.

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.

Output = Single statistic for all ROIs

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

Output = Individual statistics for each ROI

Flag Description
Port
Output
0 Label number is not in the label matrix.
1 Label number is in the label matrix.

Output = Single statistic for all ROIs

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

Running standard deviation


Enables running operation when selected.
Reset port
Specify the reset event that causes the block to reset the running
standard deviation. 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 standard
deviation check box. For more information, see “Resetting the
Running Standard Deviation” on page 1-167.
Find the standard deviation value over
Specify whether to find the standard deviation value along
rows, columns, entire input, or the dimension specified in the
Dimension parameter. For more information, see “Basic
Operation” on page 1-165.

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

Output flag indicating if ROI is within image bounds

Output flag indicating if label numbers are valid

When you select either of these check boxes, the Flag port appears
on the block. For a description of the Flag port output, see the
tables in “ROI Processing” on page 1-169.

1-173
2-D Standard Deviation

The Output flag indicating if ROI is within image bounds


check box is only visible when you select Rectangles or Lines
as the ROI type.

The Output flag indicating if label numbers are valid check


box is only visible when you select Label matrix for the ROI
type parameter.

Example
The ex_vision_2dstd calculates the standard deviation value within
two ROIs.

See Also 2-D Mean Computer Vision System Toolbox


2-D Variance Computer Vision System Toolbox
std MATLAB

1-174
2-D Standard Deviation (To Be Removed)

Purpose Find standard deviation of each input matrix

Library Statistics

Description

Note This 2-D Standard Deviation 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 Standard
Deviation block that uses the one-based, [x y] coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-175
2-D Variance

Purpose Compute variance of input or sequence of inputs

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

Port Supported Data Types


Input • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Reset • Double-precision floating point
• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

1-176
2-D Variance

Port Supported Data Types


ROI Rectangles and lines:

• Double-precision floating point


• Single-precision floating point
• Boolean
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers

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

over parameter. For example, consider a 3-dimensional input signal


of size M-by-N-by-P:

• Entire input — The output at each sample time is a scalar that


contains the variance of the entire input.

y = var(u(:)) % Equivalent MATLAB code

• Each row — The output at each sample time consists of an


M-by-1-by-P array, where each element contains the variance of each
vector over the second dimension of the input. For an input that
is an M-by-N matrix, the output at each sample time is an M-by-1
column vector.

y = var(u,0,2) % Equivalent MATLAB code

• Each column — The output at each sample time consists of a


1-by-N-by-P array, where each element contains the variance of each
vector over the first dimension of the input. For an input that is an
M-by-N matrix, the output at each sample time is a 1-by-N row vector.

y = var(u,0,1) % Equivalent MATLAB code

In this mode, the block treats length-M unoriented vector inputs


as M-by-1 column vectors.
• Specified dimension — The output at each sample time depends
on Dimension. If Dimension is set to 1, the output is the same as
that when you select Each column. If Dimension is set to 2, the
output is the same as when you select Each row. If Dimension is set
to 3, the output at each sample time is an M-by-N matrix containing
the variance of each vector over the third dimension of the input.

y = var(u,0,Dimension) % Equivalent MATLAB code

For purely real or purely imaginary inputs, the variance of an M-by-N


matrix is the square of the standard deviation:

1-178
2-D Variance

2
M N

M N
  uij
i1 j 1
  uij
2

i1 j 1
M*N
y  2 
M * N 1

1-179
2-D Variance

For complex inputs, the variance is given by the following equation:

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.

Resetting the Running Variance


The block resets the running variance whenever a reset event is
detected at the optional Rst port. The reset sample time must be a
positive integer multiple of the input sample time.
You specify the reset event in the Reset port parameter:

• None disables the Rst port.


• Rising edge — Triggers a reset operation when the Rst input does
one of the following:
- Rises from a negative value to a positive value or zero
- Rises from zero to a positive value, where the rise is not a
continuation of a rise from a negative value to zero (see the
following figure)

Falling edge Falling edge

Not a falling edge because it is


Falling edge a continuation of a fall from
Falling edge a positive value to zero.

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

Not a rising edge because it is


Rising edge a continuation of a rise from
Rising edge a negative value to zero.

• Either edge — Triggers a reset operation when the Rst input is a


Rising edge or Falling edge (as described earlier)
• Non-zero sample — Triggers a reset operation at each sample time
that the Rst input is not zero

Note When running simulations in the Simulink MultiTasking


mode, reset signals have a one-sample latency. Therefore, when the
block detects a reset event, there is a one-sample delay at the reset
port rate before the block applies the reset.

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

parameter is set to Entire input and the Running variance check


box is not selected. ROI processing is only supported for 2-D inputs.
Use the ROI type parameter to specify whether the ROI is a binary
mask, label matrix, rectangle, or line. ROI processing is only supported
for 2-D inputs.

• A binary mask is a binary image that enables you to specify which


pixels to highlight, or select.
• In a label matrix, pixels equal to 0 represent the background, pixels
equal to 1 represent the first object, pixels equal to 2 represent the
second object, and so on. When the ROI type parameter is set to
Label matrix, the Label and Label Numbers ports appear on the
block. Use the Label Numbers port to specify the objects in the label
matrix for which the block calculates statistics. The input to this
port must be a vector of scalar values that correspond to the labeled
regions in the label matrix.
• For more information about the format of the input to the ROI port
when the ROI is a rectangle or a line, see the Draw Shapes reference
page.

Note For rectangular ROIs, use the ROI portion to process


parameter to specify whether to calculate the statistical value for the
entire ROI or just the ROI perimeter.

Use the Output parameter to specify the block output. The block can
output separate statistical values for each ROI or the statistical value
for all specified ROIs. This parameter is not available if, for the ROI
type parameter, you select Binary mask.
If, for the ROI type parameter, you select Rectangles or Lines, the
Output flag indicating if ROI is within image bounds check box
appears in the dialog box. If you select this check box, the Flag port
appears on the block. The following tables describe the Flag port output
based on the block parameters.

1-182
2-D Variance

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.

Output = Single Statistic for All ROIs

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.

Output = Individual Statistics for Each ROI

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

Output = Single Statistic for All ROIs

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.

Fixed-Point Data Types


The parameters on the Data Types pane of the block dialog are only
used for fixed-point inputs. For purely real or purely imaginary inputs,
the variance of the input is the square of its standard deviation. For
complex inputs, the output is the sum of the variance of the real and
imaginary parts of the input.
The following diagram shows the data types used within the Variance
block for fixed-point signals.

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

The results of the magnitude-squared calculations in the figure are in


the product output data type. You can set the accumulator, product
output, and output data types in the block dialog as discussed in “Dialog
Box” on page 1-185.

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.

Note Full ROI processing is available only if you have a


Computer Vision System Toolbox license. If you do not have a
Computer Vision System Toolbox license, you can still use ROI
processing, but are limited to the ROI type Rectangles.

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

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

Output flag indicating if ROI is within image bounds

Output flag indicating if label numbers are valid

When you select either of these check boxes, the Flag port appears
on the block. For a description of the Flag port output, see the
tables in “ROI Processing” on page 1-181.

The Output flag indicating if ROI is within image bounds


check box is only visible when you select Rectangles or Lines
as the ROI type.

The Output flag indicating if label numbers are valid check


box is only visible when you select Label matrix for the ROI
type parameter.

The Data Types pane of the 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

Note See “Fixed-Point Data Types” on page 1-184 for more


information on how the product output, accumulator, and output
data types are used in this block.

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

• When you select Same as input-squared product, these


characteristics match those of the input-squared product.
• 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. This
block requires power-of-two slope and a bias of zero.
Output
Choose how you specify the 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-squared product, these
characteristics match those of the input-squared product.
• 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 zero.
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.

1-191
2-D Variance

Example
The ex_vision_2dvar calculates the variance value within two ROIs.

See Also 2-D Mean Computer Vision System Toolbox


2-D Standard Deviation Computer Vision System Toolbox
var MATLAB

1-192
2-D Variance (To Be Removed)

Purpose Compute variance of each input matrix

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-193
Apply Geometric Transformation

Purpose Apply projective or affine transformation to an image

Library Geometric Transformations


visiongeotforms

Description Use the Apply Geometric Transformation block to apply projective or


affine transform to an image. You can use this block to transform the
entire image or portions of the image with either polygon or rectangle
Regions of Interest (ROIs).
Port Descriptions

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:

• 3-by-2 matrix (affine transform) or a Q-by-6 matrix (multiple affine


transforms).
• 3-by-3 matrix (projective transform) or a Q-by-9 matrix (multiple projective
transforms).

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

• R-by-4 matrix for multiple rectangle ROIs.


• R-by-2L matrix for multiple polygon ROIs.

R: Number of Region of Interests (ROIs).


L(L ≥ 3): Number of vertices in a polygon ROI.

Transformations
The size of the transformation matrix will dictate the transformation
type.
Affine Transformation

For affine transformation, the value of the pixel located at  xˆ , yˆ  in the

output image, is determined by the value of the pixel located at  x, y


in the input image. The relationship between the input and the output
point locations is defined by the following equations:

⎧ 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

format of H   h1 h2 h3 h4 h5 h6  , and Q is the number of


transformations as in:

 h11 h12 ... h16 


h h22 ... h26 
H
21
   ...  
 
 hQ1 hQ2 ... hQ6 
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.
Projective Transformation
For projective transformation, the relationship between the input and
the output points is defined by the following equations:

⎧ ˆ 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 

or in a 1-by-9 vector as in, H   h1 h2 h3 h4 h5 h6 h7 h8 h9  .


If you use more than one transformation, the transformation coefficients
must be arranged as a Q-by-9 matrix, where each row has the format

1-196
Apply Geometric Transformation

of H   h1 h2 h3 h4 h5 h6 h7 h8 h9  , and Q is the number


of transformations. For example,

 h11 h12 ... h19 


h h22 ... h29 
H
21
   ...  
 
 hQ1 hQ2 ... hQ9 

Dialog Box
The Main pane of the Apply Geometric Transformation dialog box
appears as shown in the following figure.

1-197
Apply Geometric Transformation

Transformation matrix source


Specify input matrix source, either Specified via dialog, or
Input port. If you select Specify via dialog, you can enter the
transformation matrix parameters in the parameter that appear with
this selection.
Transformation matrix
Specify a 3-by-2, 3-by-3, Q-by-6,or aQ-by-9 matrix. This option appears
when you set the Transformation matrix source parameter to
Specified via dialog.
Interpolation method for calculating pixel value(s)
Specify interpolation method, either Nearest neighbor, Bilinear, or
Bicubic interpolation to calculate output pixel values. See Geometric

1-198
Apply Geometric Transformation

Transformation Interpolation Methods for an overview of these


methods.
Background fill value
Specify the value of the pixels that are outside of the input image. Use
either a scalar value of P-element vector.
Output image size and position
Specify the output image size to be either Same as input image, or
Specify via dialog. If you select to Specify via dialog, you can
specify the bounding box in the size and location parameters that
appear with this selection.
Size [height width]
Specify the height and width for the output image size as[height
width]. You can specify this parameter, along with the Location of
the upper left corner [x y] parameter when you set the Output
image size and position parameter to Specify via dialog.
Location of the upper left corner [x y]
Specify the [x y] location for the upper left corner of the output image.
You can specify this parameter, along with the Size [height width]
parameter, when you set the Output image size and position
parameter to Specify via dialog.
Process pixels in
Specify the region in which to process pixels. Specify Whole input
image, Rectangle ROI, or Polygon ROI. If you select Rectangle ROI,
or Polygon ROI the ROI source parameter becomes available.
The transformations will be applied on the whole image, or on specified
multiple ROIs. The table below outlines how transformation matrices
are handled with an entire image and with single and multiple ROIs.

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

Specify the polygon by its vertices in clockwise or counter-clockwise


order, with at least three or more vertices. If you specify one
ROI of L vertices, it must be a 2L-element vector of format
 x1 y1 x2 y2 ... xL yL  . If you specify more than one ROI, it
must be an R-by-2L matrix, where L is the maximum number of vertices
in the ROIs. For ROI with vertices fewer than L, its last vertex can be
repeated to form a vector.
Output flag indicating if any part of ROI is outside input image
Select the Output flag indicating if any part of ROI is outside
input image check box to enable this output port on the Apply
Geometric Transformation block.
For projective transformation, use quadratic approximation to
calculate pixel locations
Specify whether to use an exact computation or an approximation for
the projective transformation. If you select this option, you can enter an
error tolerance in the Error tolerance (in pixels) parameter.
Error tolerance (in pixels)
Specify the maximum error tolerance in pixels. This appears when
you select the For projective transformation, use quadratic
approximation to calculate pixel locations check box.
Output flag indicating if any transformed pixels were clipped
Enable output port for flag, which indicates clipping. Clipping occurs
when any of the transformed pixels fall outside of the output image.

Examples Apply a Projective Transformation to an Image


The Simple projective transformation model ex_visionApplyGeo_proj,
uses the Apply Geometric Transformation block, two Constant
blocks and twoVideo Viewer blocks to illustrate a basic model. The
transformation matrix determines a projective transformation and is
applied to the entire input image. The input image is a checker board.
The steps taken to run this model were:

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.

Create an Image of a Cube using Three Regions of Interest


This example shows how to apply affine transformation on multiple
ROIs of an image. It also sets the background color of the output image
to a solid color purple. The input image, transformation matrix, and
ROI vertices are provided to the Apply Geometric Transformation
block via constant blocks. Video viewers are used to view the original
image and the output image created. Open this model by typing
ex_visionApplyGeo_roi at the MATLAB command prompt. The steps
taken to run this model was:

1 Change the Process pixels in parameter to Polygon ROI.

2 Change the Background fill value to [0.5 0.5 0.75]

3 Add three Constant blocks for the input image, transformation


matrix, and ROI vertices. Set the Constant value parameters for
the three blocks as follows:
• For the input image, checker_board(20,10).
• For the transformation matrix,[1 0 30 0 1 -30; 1.0204
-0.4082 70 0 0.4082 30; 0.4082 0 89.1836 -0.4082 1
10.8164].
• For the polygon ROI, [1 101 99 101 99 199 1 199; 1 1 99 1
99 99 1 99; 101 101 199 101 199 199 101 199].

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

Port Supported Data Types


Image • Double-precision floating point
• Single-precision floating point
TForm • Double-precision floating point
• Single-precision floating point
ROI • Double-precision floating point
• Single-precision floating point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned integers
Output Same as input
Err_roi Boolean
Err_clip Boolean

1-203
Apply Geometric Transformation

See Also imtransform Image Processing Toolbox


Estimate Geometric Computer Vision System Toolbox
Transformation
Trace Boundary Computer Vision System Toolbox

Blob Analysis Computer Vision System Toolbox

Video and Image Computer Vision System Toolbox


Processing Demos

1-204
Apply Geometric Transformation (To Be Removed)

Purpose Apply projective or affine transformation to an image

Library Geometric Transformations

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-205
Autothreshold

Purpose Convert intensity image to binary image

Library Conversions
visionconversions

Description The Autothreshold block converts an intensity image to a binary image


using a threshold value computed using Otsu’s method.
This block computes this threshold value by splitting the histogram of
the input image such that the variance of each pixel group is minimized.

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

Use the Thresholding operator parameter to specify the condition


the block places on the input values. If you select > and the input value
is greater than the threshold value, the block outputs 1 at the BW port;
otherwise, it outputs 0. If you select <= and the input value is less

1-206
Autothreshold

than or equal to the threshold value, the block outputs 1; otherwise,


it outputs 0.
Select the Output threshold check box to output the calculated
threshold values at the Th port.
Select the Output effectiveness metric check box to output values
that represent the effectiveness of the thresholding at the EMetric
port. This metric ranges from 0 to 1. If every pixel has the same value,
the effectiveness metric is 0. If the image has two pixel values or the
histogram of the image pixels is symmetric, the effectiveness metric is 1.
If you clear the Specify data range check box, the block assumes that
floating-point input values range from 0 to 1. To specify a different
data range, select this check box. The Minimum value of input and
Maximum value of input parameters appear in the dialog box. Use
these parameters to enter the minimum and maximum values of your
input signal.
Use the When data range is exceeded parameter to specify the
block’s behavior when the input values are outside the expected range.
The following options are available:

• Ignore — Proceed with the computation and do not issue a warning


message. If you choose this option, the block performs the most
efficient computation. However, if the input values exceed the
expected range, the block produces incorrect results.
• Saturate — Change any input values outside the range to the
minimum or maximum value of the range and proceed with the
computation.
• Warn and saturate — Display a warning message in the MATLAB
Command Window, saturate values, and proceed with the
computation.
• Error — Display an error dialog box and terminate the simulation.

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.

Fixed-Point Data Types


The following diagram shows the data types used in the Autothreshold
block for fixed-point signals. You can use the default fixed-point
parameters if your input has a word length less than or equal to 16.

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

whether the input matrix values are above, below, or equal to


the threshold value.
Output threshold
Select this check box to output the calculated threshold values
at the Th port.
Output effectiveness metric
Select this check box to output values that represent the
effectiveness of the thresholding at the EMetric port.
Specify data range
If you clear this check box, the block assumes that floating-point
input values range from 0 to 1. To specify a different data range,
select this check box.
Minimum value of input
Enter the minimum value of your input data. This parameter is
visible if you select the Specify data range check box.
Maximum value of input
Enter the maximum value of your input data. This parameter is
visible if you select the Specify data range check box.
When data range is exceeded
Specify the block’s behavior when the input values are outside the
expected range. Your options are Ignore, Saturate, Warn and
saturate, or Error. This parameter is visible if you select the
Specify data range check box.
Scale threshold
Select this check box to scale the threshold value computed by
Otsu’s method.
Threshold scaling factor
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. This parameter is visible if you
select the Scale threshold check box.

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

“Fixed-Point Data Types” on page 1-208. For this step, Rounding


mode is always set to Nearest.
Overflow mode
Select the overflow mode for fixed-point operations.
Product 1, 2, 3, 4

As shown previously, the output of the multiplier is placed into


the product output data type and scaling. Use this parameter to
specify how to designate the product output word and fraction
lengths.
• When you select Specify word length, you can enter the word
length of the product values in bits. The block sets the fraction
length to give you the best precision.
• When you select Same as input, the characteristics match
those of the input to the block. This choice is only available
for the Product 4 parameter.
• 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.

1-212
Autothreshold

Accumulator 1, 2, 3, 4

As shown previously, inputs to the accumulator are cast to the


accumulator data type. The output of the adder remains in the
accumulator data type as each element of the input is added to it.
Use this parameter to specify how to designate the accumulator
word and fraction lengths.
• When you select Same as Product, these characteristics match
those of the product output.
• When you select Specify word length, you can enter the
word length of the accumulator values in bits. The block sets
the fraction length to give you the best precision. This choice is
not available for the Accumulator 4 parameter because it is
dependent on the input data type.
• 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.

The Accumulator 3 parameter is only visible if, on the Main


pane, you select the Output effectiveness metric check box.

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

Example Thresholding Intensity Images Using the Autothreshold Block


Convert an intensity image into a binary image. Use the Autothreshold
block when lighting conditions vary and the threshold needs to change
for each video frame.
You can open the example model by typing

ex_vision_autothreshold

on the MATLAB command line.

See Also Compare To Constant Simulink


Relational Operator Simulink
graythresh Image Processing Toolbox

1-215
Blob Analysis

Purpose Compute statistics for labeled regions

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

Port Input/Output Supported Data Types


BW Vector or matrix that Boolean
represents a binary image
Area Vector that represents the 32-bit signed integer
number of pixels in labeled
regions
Centroid M-by-2 matrix of centroid • Double-precision floating point
coordinates, where M
• Single-precision floating point
represents the number of
blobs • Fixed point

BBox M-by-4 matrix of [x y 32-bit signed integer


width height] bounding
box coordinates, where M
represents the number of
blobs and [x y] represents
the upper left corner of the
bounding box.

1-216
Blob Analysis

Port Input/Output Supported Data Types


MajorAxis Vector that represents the • Double-precision floating point
lengths of major axes of
• Single-precision floating point
ellipses
MinorAxis Vector that represents the Same as MajorAxis port
lengths of minor axes of
ellipses
Orientation Vector that represents the Same as MajorAxis port
angles between the major axes
of the ellipses and the x-axis.
Eccentricity Vector that represents the Same as MajorAxis port
eccentricities of the ellipses
Diameter ^2 Vector that represents the Same as Centroid port
equivalent diameters squared
Extent Vector that represents the Same as Centroid port
results of dividing the areas of
the blobs by the area of their
bounding boxes
Perimeter Vector containing an estimate Same as Centroid port
of the perimeter length, in
pixels, for each blob
Label Label matrix 8-, 16-, or 32-bit unsigned integer
Count Scalar value that represents Same as Label port
the actual number of labeled
regions in each image

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

Minor axis length


Select this check box to output a vector with the following
characteristics:
• Represents the lengths of the minor axes of ellipses
• Has the same normalized second central moments as the
labeled regions
Orientation
Select this check box to output a vector that represents the angles
between the major axes of the ellipses and the x-axis. The angle
values are in radians and range between:

π π
− 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 Connectivity parameter also affects how the block calculates


the perimeter of a blob. For example:

The following figure illustrates how the block calculates the


perimeter when you set the Connectivity parameter to 4.

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

Maximum number of blobs


Specify the maximum number of labeled regions in each input
image. The block uses this value to preallocate vectors and
matrices to ensure that they are long enough to hold the statistical
values. The maximum number of blobs the block outputs depends

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.

Accumulator data type


Product output data type
MULTIPLIER
4/pi data type

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

signals in the Computer Vision System Toolbox software have


a bias of 0.

Inputs to the Accumulator get cast to the accumulator data


type. Each element of the input gets added 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.
Centroid output
Choose how to specify the Word length and Fraction length of
the output at the Centroid port:
• When you select Same as accumulator, these characteristics
match the characteristics of the accumulator.
• When you select Binary point scaling, you can enter the
Word length and 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. All signals
in the Computer Vision System Toolbox software have a bias
of 0.
Equiv Diam^2 output
Choose how to specify the Word length and Fraction length of
the output at the Diameter ^2 port:

1-228
Blob Analysis

• When you select Same as accumulator, these characteristics


match the characteristics of the Accumulator.
• 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 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. All signals
in the Computer Vision System Toolbox software have a bias
of 0.
Extent output
Choose how to specify the Word length and Fraction length of
the output at the Extent port:
• When you select Same as accumulator, these characteristics
match the characteristics of the accumulator.
• When you select Binary point scaling, you can enter the
Word length and 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. All signals
in the Computer Vision System Toolbox software have a bias
of 0.
Fill in empty spaces outputs
Select this check box to fill empty spaces in the statistical vectors
with the value you specify in the Fill values parameter.

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

• When you select Same as accumulator, these characteristics


match the characteristics of the accumulator.

When you select Binary point scaling, you can enter the
Word length and 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. All signals in
the Computer Vision System Toolbox software have a bias of 0.
Lock scaling against changes by the autoscaling tool
Select this parameter to prevent the autoscaling tool in the
Fixed-Point Tool overriding any fixed-point scaling you specify in
this block mask. For more information, see fxptdlg, a reference
page on the Fixed-Point Tool in the Simulink documentation.

See Also Label Computer Vision System Toolbox


regionprops Image Processing Toolbox

1-230
Blob Analysis (To Be Removed)

Purpose Compute statistics for labeled regions

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-231
Block Matching

Purpose Estimate motion between images or video frames

Library Analysis & Enhancement


visionanalysis

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

Input image = frame k STEP 1: Subdivide the image in frame k.

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.

Previous block location


Search region Search region
New block location

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

Use the Estimate motion between parameter to specify whether


to estimate the motion between two images or two video frames. If
you select Current frame and N-th frame back, the N parameter
appears in the dialog box. Enter a scalar value that represents the
number of frames between the reference frame and the current frame.
Use the Search method parameter to specify how the block locates
the block of pixels in frame k+1 that best matches the block of pixels
in frame k.

• 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

approximately equal to half the maximum search range. In each


step, the block compares the central point of the search region to
eight search points located on the boundaries of the region and moves
the central point to the search point whose values is the closest to
that of the central point. The block then reduces the step size by half,
and begins the process again. This option is less computationally
expensive, though it might not find the optimal solution.

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

In the previous equation, B is an N1 × N 2 block of pixels, and


s(x,y,k) denotes a pixel location at (x,y) in frame k. If you select Mean
absolute difference (MAD), the Block Matching block estimates the
displacement of the center pixel of the block as the (d1 , d2 ) values that
minimize the following MAD equation:

1
MAD(d1 , d2 ) = ∑ ∑| s(n1 , n2 , k) − s(n1 + d1 , n2 + d2 , k + 1)|
N1 × N 2 (n ,n ), ∈B
1 2

Use the Block size [height width] and Overlap [r c] parameters


to specify how the block subdivides the input image. For a graphical
description of these parameters, see the first figure in this reference
page. If the Overlap [r c] parameter is not [0 0], the blocks would
overlap each other by the number of pixels you specify.
Use the Maximum displacement [r c] parameter to specify the
maximum number of pixels any center pixel in a block of pixels might

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

MSE 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

ADDER CAST MULTIPLIER CAST


CAST
Input Accumulator Product Product
Accumulator data type data type
data type data type data type

MAD Block Matching

The result of each addition remains


in the 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.

Estimate motion between


Select Two images to estimate the motion between two images.
Select Current frame and N-th frame back to estimate the
motion between two video frames that are N frames apart.
N
Enter a scalar value that represents the number of frames
between the reference frame and the current frame. This
parameter is only visible if, for the Estimate motion between
parameter, you select Current frame and N-th frame back.
Search method
Specify how the block searches for the block of pixels in the next
image or frame. Your choices are Exhaustive or Three-step.

1-238
Block Matching

Block matching criteria


Specify how the block measures the similarity of the block of
pixels in frame k to the block of pixels in frame k+1. Your choices
are Mean square error (MSE) or Mean absolute difference
(MAD).
Block size [height width]
Specify the size of the block of pixels.
Overlap [r c]
Specify the overlap (in pixels) of two subdivisions of the input
image.
Maximum displacement [r c]
Specify the maximum number of pixels any center pixel in a block
of pixels might move from image to image or frame to frame. The
block uses this value to determine the size of the search region.
Velocity output
If you select Magnitude-squared, the block outputs the optical
2 2
flow matrix where each element is of the form u + v . 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 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

As shown previously, the output of the multiplier is placed into


the product output data type and scaling. Use this parameter to
specify how to designate the product output word and fraction
lengths.

1-240
Block Matching

• 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

As depicted previously, inputs to the accumulator are cast to the


accumulator data type. The output of the adder remains in the
accumulator data type as each element of the input is added to it.
Use this parameter to specify how to designate this accumulator
word and fraction lengths.
• 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-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.

See Also Optical Flow Computer Vision System Toolbox software

1-242
Block Processing

Purpose Repeat user-specified operation on submatrices of input matrix

Library Utilities
visionutilities

Description The Block Processing block extracts submatrices of a user-specified


size from each input matrix. It sends each submatrix to a subsystem
for processing, and then reassembles each subsystem output into the
output matrix.

Subsystem

Note Because you modify the Block Processing block’s subsystem,


the link between this block and the block library is broken when you
click-and-drag a Block Processing block into your model. As a result,
this block will not be automatically updated if you upgrade to a newer
version of the Computer Vision System Toolbox software. If you
right-click on the block and select Mask>Look Under Mask, you can
delete blocks from this subsystem without triggering a warning. Lastly,
if you search for library blocks in a model, this block will not be part of
the results.

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

Use the Number of inputs and Number of outputs parameters to


specify the number of input and output ports on the Block Processing
block.
Use the Block size parameter to specify the size of each submatrix
in cell array format. Each vector in the cell array corresponds to one
input; the block uses the vectors in the order you enter them. If you
have one input port, enter one vector. If you have more than one input
port, you can enter one vector that is used for all inputs or you can
specify a different vector for each input. For example, if you want each
submatrix to be 2-by-3, enter {[2 3]}.
Use the Overlap parameter to specify the overlap of each submatrix
in cell array format. Each vector in the cell array corresponds to the
overlap of one input; the block uses the vectors in the order they are
specified. If you enter one vector, each overlap is the same size. For
example, if you want each 3-by-3 submatrix to overlap by 1 row and 2
columns, enter {[1 2]}.
The Traverse order parameter 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.
Click the Open Subsystem 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. The input to this
subsystem are the submatrices whose size is determined by the Block
size parameter.

Note When you place an Assignment block inside a Block Processing


block’s subsystem, the Assignment block behaves as though it is inside
a For Iterator block. For a description of this behavior, see the “Iterated
Assignment” section of the Assignment block reference page.

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.

See Also For Iterator Simulink


blockproc Image Processing Toolbox

1-246
Bottom-hat

Purpose Perform bottom-hat filtering on intensity or binary images

Library Morphological Operations


visionmorphops

Description Use the Bottom-hat block to perform bottom-hat filtering on an intensity


or binary image using a predefined neighborhood or structuring
element. Bottom-hat filtering is the equivalent of subtracting the input
image from the result of performing a morphological closing operation
on the input image. This block uses flat structuring elements only.

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

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 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.

Dialog The Bottom-hat dialog box appears as shown in the following figure.
Box

1-248
Bottom-hat

Input image type


If your input image is a binary image, select Binary. If your input
image is an intensity image, select Intensity.
Neighborhood or structuring element source
Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or
structuring element source parameter, you select Specify
via dialog.

See Also Closing Computer Vision System Toolbox software


Dilation Computer Vision System Toolbox software
Erosion Video and Image Processing Blockset software
Label Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
imbothat Image Processing Toolbox software
strel Image Processing Toolbox software

1-249
Chroma Resampling

Purpose Downsample or upsample chrominance components of images

Library Conversions
visionconversions

Description The Chroma Resampling block downsamples or upsamples chrominance


components of pixels to reduce the bandwidth required for transmission
or storage of a signal.

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.

Chroma Resampling Formats


The Chroma Resampling block supports the formats shown in the
following diagram.

1-250
Chroma Resampling

4:4:4 4:2:2 4:1:1

Y pixel

Cb and Cr pixel

4:2:0 MPEG1 4:2:0 MPEG2

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

User-defined, the Horizontal filter coefficients parameter appears


on the dialog box. Enter the filter coefficients to apply to your input.
If, for the Resampling parameter, you select 4:4:4 to 4:2:0 (MPEG1),
4:4:4 to 4:2:0 (MPEG2), 4:2:2 to 4:2:0 (MPEG1), or
4:2:2 to 4:2:0 (MPEG2) and, for the Antialiasing filter parameter,
you select User-defined. Vertical filter coefficients parameters
appear on the dialog box. Enter an even number of filter coefficients to
apply to your input signal.
If, for the Antialiasing filter parameter, you select None, the block
does not filter the input signal.

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.

Row-Major Data Format


The MATLAB environment and the Computer Vision System Toolbox
software use column-major data organization. However, the Chroma
Resampling block gives you the option to process data that is stored in
row-major format. When you select the Input image is transposed
(data order is row major) check box, the block assumes that the input
buffer contains contiguous data elements from the first row first, then
data elements from the second row second, and so on through the last
row. Use this functionality only when you meet all the following criteria:

1-252
Chroma Resampling

• You are developing algorithms to run on an embedded target that


uses the row-major format.
• You want to limit the additional processing required to take
the transpose of signals at the interfaces of the row-major and
column-major systems.

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.

Use the following two-step workflow to develop algorithms in row-major


format to run on an embedded target.

1-253
Chroma Resampling

Step 1:
Create block diagram Algorithm
blocks

Video Transpose Transpose Video


source block block sink
block block

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

select 4:4:4 to 4:2:0 (MPEG1), 4:4:4 to 4:2:0 (MPEG2),


4:2:2 to 4:2:0 (MPEG1), or 4:2:2 to 4:2:0 (MPEG2) and, for
the Antialiasing filter parameter, you select User-defined.
Interpolation
Specify the interpolation method that the block uses to
approximate the missing chrominance values. If you select
Linear, the block uses linear interpolation to calculate the
missing values. If you select Pixel replication, the block
replicates the chrominance values of the neighboring pixels
to create the upsampled image. This parameter is visible
when you are upsampling the chrominance values. This
parameter is visible if the Resampling parameter is set to
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 , or
4:2:0 (MPEG2) to 4:2:2 .
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
elements from the second row second, and so on through the last
row.

References [1] Haskell, Barry G., Atul Puri, and Arun N. Netravali. Digital Video:
An Introduction to MPEG-2. New York: Chapman & Hall, 1996.

[2] Recommendation ITU-R BT.601-5, Studio Encoding Parameters of


Digital Television for Standard 4:3 and Wide Screen 16:9 Aspect Ratios.

[3] Wang, Yao, Jorn Ostermann, Ya-Qin Zhang. Video Processing and
Communications. Upper Saddle River, NJ: Prentice Hall, 2002.

1-256
Chroma Resampling

See Also Autothreshold Computer Vision System Toolbox software


Color Space Computer Vision System Toolbox software
Conversion
Image Complement Computer Vision System Toolbox software

1-257
Closing

Purpose Perform morphological closing on binary or intensity images

Library Morphological Operations


visionmorphops

Description The Closing block performs a dilation operation followed by an erosion


operation using a predefined neighborhood or structuring element. This
block uses flat structuring elements only.

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

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 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.

Dialog The Closing dialog box appears as shown in the following figure.
Box

1-259
Closing

Neighborhood or structuring element source


Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or
structuring element source parameter, you select Specify
via dialog.

References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.

See Also Bottom-hat Computer Vision System Toolbox software


Dilation Computer Vision System Toolbox software
Erosion Computer Vision System Toolbox software
Label Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
imclose Image Processing Toolbox software
strel Image Processing Toolbox software

1-260
Color Space Conversion

Purpose Convert color information between color spaces

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.

Conversion Between R’G’B’ and Y’CbCr Color Spaces


The R’G’B’ to Y’CbCr conversion and the Y’CbCr to R’G’B’ conversion
are defined by the following equations:

⎡ 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

Matrix Use conversion Use conversion specified by = Rec. 709 (HDTV)


specified by = Rec.
Scanning standard = Scanning standard =
601 (SDTV)
1125/60/2:1 1250/50/2:1
A ⎡0.25678824 0.50412941 0.09790588 ⎤ ⎡ 0.18258588 0.61423059 0.06200706 ⎤ ⎡0.25678824 0.50412941 0.09790588 ⎤
⎢ −0.1482229 −0.29099279 0.43921569 ⎥ ⎢ -0.10064373 -0.3385
57195 0.43921569 ⎥⎥ ⎢ −0.1482229 −0.29099279 0.43921569 ⎥
⎢ ⎥ ⎢ ⎢ ⎥
⎢⎣0.43921569 −0.36778831 −0.07142737⎥⎦ ⎢⎣ 0.43921569 -0.39894216 -0.04027352 ⎥⎦ ⎢⎣0.43921569 −0.36778831 −0.07142737⎥⎦

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′ ⎥⎦

Conversion Between R’G’B’ and HSV Color Spaces


The R’G’B’ to HSV conversion is defined by the following equations. In
these equations, MAX and MIN represent the maximum and minimum
values of each R’G’B’ triplet, respectively. H, S, and V vary from 0 to 1,
where 1 represents the greatest saturation and value.

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

The HSV to R’G’B’ conversion is defined by the following equations:

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

Conversion Between sR’G’B’ and XYZ Color Spaces


The sR’G’B’ to XYZ conversion is a two-step process. First, the block
converts the gamma-corrected sR’G’B’ values to linear sRGB values
using the following equations:

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:

⎡ X ⎤ ⎡0.41239079926596 0.35758433938388 0.18048078840183 ⎤ ⎡ RsRG GB ⎤


⎢ Y ⎥ = ⎢0.21263900587151 0.71516867876776 0.07219231536073 ⎥ × ⎢ G ⎥
⎢ ⎥ ⎢ ⎥ ⎢ sRGB ⎥
⎢⎣ Z ⎥⎦ ⎢⎣0.01933081871559 0.11919477979463 0.95053215224966 ⎥⎦ ⎢⎣ BsRGB ⎥⎦

The XYZ to sR’G’B’ conversion is also a two-step process. First, the


block converts the XYZ values to linear sRGB 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:

If RsRGB , GsRGB , BsRGB ≤ 0.00304



RsRGB = 12.92 RsRGB

GsRGB = 12.92GsRGB

BsRGB = 12.92 BsRGB
otherwise, if RsRGB , GsRGB , BsRGB > 0.00304

RsRGB = 1.055 RsRGB(1.0 / 2.4) − 0.055

GsRGB = 1.055GsRGB(1.0 / 2.4) − 0.055

BsRGB = 1.055 BsRGB(1.0 / 2.4) − 0.055

Note Computer Vision System Toolbox software uses a D65 white


point, which is specified in Recommendation ITU-R BT.709, for this
conversion. In contrast, the Image Processing Toolbox conversion is
based on ICC profiles, and it uses a D65 to D50 Bradford adaptation
transformation to the D50 white point. If you are using these two
products and comparing results, you must account for this difference.

Conversion Between sR’G’B’ and L*a*b* Color Spaces


The Color Space Conversion block converts sR’G’B’ values to L*a*b*
values in two steps. First it converts sR’G’B’ to XYZ values using
the equations described in “Conversion Between sR’G’B’ and XYZ
Color Spaces” on page 1-266. Then it uses the following equations to
transform the XYZ values to L*a*b* values. Here, X n , Yn , and Zn are
the tristimulus values of the reference white point you specify using the
White point parameter:

1-267
Color Space Conversion

L* = 116(Y / Yn )1 3 − 16, for Y Yn > 0.008856


L* = 903.3 Y Yn , otherwise

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

The block converts L*a*b* values to sR’G’B’ values in two steps as


well. The block transforms the L*a*b* values to XYZ values using
these equations:

For Y Yn > 0.008856

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

if, for the Conversion parameter, you select R'G'B' to Y'CbCr


or Y'CbCr to R'G'B'.
Scanning standard
Specify the scanning standard to use to convert your values
between the R’G’B’ and Y’CbCr color spaces. Your choices are
1125/60/2:1 or 1250/50/2:1. This parameter is only available
if, for the Use conversion specified by parameter, you select
Rec. 709 (HDTV).
White point
Specify the reference white point. This parameter is visible if,
for the Conversion parameter, you select sR'G'B' to L*a*b*
or L*a*b* to sR'G'B'.
Image signal
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.

References [1] Poynton, Charles A. A Technical Introduction to Digital Video. New


York: John Wiley & Sons, 1996.

[2] Recommendation ITU-R BT.601-5, Studio Encoding Parameters of


Digital Television for Standard 4:3 and Wide Screen 16:9 Aspect Ratios.

[3] Recommendation ITU-R BT.709-5. Parameter values for the HDTV


standards for production and international programme exchange.

[4] Stokes, Michael, Matthew Anderson, Srinivasan Chandrasekar,


and Ricardo Motta, “A Standard Default Color Space for the Internet -
sRGB.” November 5, 1996.

[5] Berns, Roy S. Principles of Color Technology, 3rd ed. New York:
John Wiley & Sons, 2000.

1-270
Color Space Conversion

See Also Chroma Resampling Computer Vision System Toolbox software


rgb2hsv MATLAB software
hsv2rgb MATLAB software
rgb2ycbcr Image Processing Toolbox software
ycbcr2rgb Image Processing Toolbox software
rgb2gray Image Processing Toolbox software
makecform Image Processing Toolbox software
applycform Image Processing Toolbox software

1-271
Compositing

Purpose Combine pixel values of two images, overlay one image over another,
or highlight selected pixels

Library Text & Graphics


visiontextngfix

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:

O(i, j) = (1 − X ) * I1(i, j) + X * I 2(i, j)

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.

Note This block supports intensity and color images.

1-272
Compositing

Fixed-Point Data Types


The following diagram shows the data types used in the Compositing
block for fixed-point signals. These data types applies when the
Operation parameter is set to Blend.

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

can enter 0 or 1 to use for all pixels in the image, or a matrix of


0s and 1s that defines the factor for each pixel.
• If you choose Input port, the Factor port appears on the
block. The input to this port must be a 0 or 1 whose data type is
Boolean. Or, a matrix of 0s or 1s whose data type is Boolean, as
described for the Mask parameter.

Highlight selected pixels


If, for the Operation parameter, you choose Highlight selected
pixels, the block uses the binary image input at the Mask
port to determine which pixels are set to the maximum value
supported by their data type. For example, for every pixel value
set to 1 in the binary image, the block sets the corresponding
pixel in the input image to the maximum value supported by its
data type. For every 0 in the binary image, the block leaves the
corresponding pixel value alone.
Opacity factor(s) source
Indicate where to specify any opacity factors. Your choices are
Specify via dialog and Input port. This parameter is visible
if, for the Operation parameter, you choose Blend.
Opacity factor(s)
Define the amount by which the block scales each pixel value
before combining them. You can enter a scalar value used for all
pixels or a matrix of values that defines the factor for each pixel.
This parameter is visible if, for the Opacity factor(s) source
parameter, you choose Specify via dialog. Tunable.
Mask source
Indicate where to specify any masking factors. Your choices are
Specify via dialog and Input port. This parameter is visible
if, for the Operation parameter, you choose Binary mask.
Mask
Define which pixels are overwritten. You can enter 0 or 1, which
is used for all pixels, or a matrix of 0s and 1s that defines the

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

As the previous figure shows, the block takes inputs to the


accumulator and casts them to the accumulator data type. The
output of the adder remains in the accumulator data type as each
element of the input is added to it.
• When you select Same as product output, these
characteristics match those of the product output.
• 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 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
software is 0.

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

• 8-, 16-, and 32-bit unsigned


integer
Image 2 M-by-N matrix of intensity Same as Image 1 port No
values or an M-by-N-by-P color
video signal where P is the
number of color planes
Factor Scalar or matrix of opacity or • Double-precision floating No
masking factor point
• Single-precision floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit signed
integer
• 8-, 16-, and 32-bit unsigned
integer
Mask Binary image that specifies Same as Factor port No
which pixels to highlight
When the Operation parameter
is set to Highlight selected
pixel, the input to the Mask
port must be a Boolean data
type.

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

See Also Insert Text Computer Vision System Toolbox


Draw Markers Computer Vision System Toolbox
Draw Shapes Computer Vision System Toolbox

1-283
Compositing (To Be Removed)

Purpose Combine pixel values of two images, overlay one image over another,
or highlight selected pixels

Library Text & Graphics


viptextngfix

Description

Note This Compositing 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 Compositing block that
uses the one-based, [x y] coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-284
Contrast Adjustment

Purpose Adjust image contrast by linearly scaling pixel values

Library Analysis & Enhancement


visionanalysis

Description The Contrast Adjustment block adjusts the contrast of an image by


linearly scaling the pixel values between upper and lower limits. Pixel
values that are above or below this range are saturated to the upper
or lower limit value, respectively.

Number of pixels

3000 Lower Input Limit Upper Input Limit

1500
These values are
scaled to lower
output limit.

Pixel value
50 100 150 200 250
Number of pixels

2000 Values within the upper and


lower input limits are linearly
scaled within the upper and
lower output limits.

1000

Pixel value
25 50 75 100 125

Lower Output Limit Upper Output Limit

1-285
Contrast Adjustment

Mathematically, the contrast adjustment operation is described by the


following equation, where the input limits are [low_in high_in] and the
output limits are [low_out high_out]:

⎧ low _ out , Input ≤ low _ in ⎫


⎪ ⎪
⎪ high _ out − low _ out ⎪
Output = ⎨low _ out + ( Input − low _ in) , low _ in < Input < high _ in ⎬
⎪ high _ in − low _ in ⎪
⎪⎩ high _ out , Input ≥ high _ in ⎪⎭

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

Specifying upper and lower limits


Use the Adjust pixel values from and Adjust pixel values to
parameters to specify the upper and lower input and output limits.
All options are described below.
Input limits
Use the Adjust pixel values from parameter to specify the upper and
lower input limits.

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:

1 Find the minimum and maximum input values, [min_in max_in].

2 Scale the pixel values from [min_in max_in] to [0 num_bins-1],


where num_bins is the scalar value you specify in the Number of
histogram bins parameter. This parameter always displays the
value used by the block. Then the block calculates the histogram of
the scaled input. For additional information about histograms, see
the 2D-Histogram block reference page.

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 you select User-defined range, the Range [low high] parameter


appears on the block. Enter a two-element vector of scalar values,
where the first element corresponds to the lower output limit and the
second element corresponds to the upper output limit.
For INF, -INF and NAN Input Values
If any input pixel value is either INF or -INF, the Contrast Adjustment
block will change the pixel value according to how the parameters are
set. The following table shows how the block handles these pixel values.

If Adjust pixel values Contrast Adjustment block will:


from parameter is set
to...
Full data range Set the entire output image to the lower
[min,max] limit of the Adjust pixel values to
parameter setting.
Range determined by
saturating outlier pixels
User defined range Lower and higher limits of the Adjust
pixel values to parameter set to -INF
and INF, respectively.

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.

Fixed-Point Data Types


The following diagram shows the data types used in the Contrast
Adjustment block for fixed-point signals:

1-288
Contrast Adjustment

Dialog The Contrast Adjustment dialog box appears as shown in the following
Box figure.

1-289
Contrast Adjustment

Adjust pixel values from


Specify how to enter the upper and lower input limits. Your
choices are Full input data range [min max], User-defined,
and Range determined by saturating outlier pixels.
Range [low high]
Enter a two-element vector of scalar values. The first element
corresponds to the lower input limit, and the second element
corresponds to the upper input limit. This parameter is visible
if, for the Adjust pixel values from parameter, you select
User-defined.
Percentage of pixels to saturate [low high] (in %)
Enter a two-element vector. The block calculates 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. It
calculates the upper input limit similarly. This parameter is
visible if, for the Adjust pixel values from parameter, you select
Range determined by saturating outlier pixels.
Specify number of histogram bins (used to calculate the range
when outliers are eliminated)
Select this check box to change the number of histogram bins.
This parameter is editable if, for the Adjust pixel values
from parameter, you select Range determined by saturating
outlier pixels.
Number of histogram bins
Enter the number of histogram bins to use to calculate the scaled
input values. This parameter is available if you select the Specify
number of histogram bins (used to calculate the range
when outliers are eliminated) check box.
Adjust pixel values 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 output limit. If you select User-defined
range, the Range [low high] parameter appears on the block.

1-290
Contrast Adjustment

Range [low high]


Enter a two-element vector of scalar values. The first element
corresponds to the lower output limit and the second element
corresponds to the upper output limit. This parameter is
visible if, for the Adjust pixel values to parameter, you select
User-defined range

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

As shown 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 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

As shown 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:

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.

See Also 2D-Histogram Computer Vision System Toolbox software


Histogram Computer Vision System Toolbox software
Equalization

1-293
Corner Detection

Purpose Calculate corner metric matrix and find corners in images

Library Analysis & Enhancement


visionanalysis

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

Port Description Supported Data Types


I Matrix of intensity values • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Loc M-by-2 matrix of [x y] 32-bit unsigned integer
coordinates, that represents

1-294
Corner Detection

Port Description Supported Data Types

the locations of the corners.


M represents the number of
corners and is less than or
equal to the Maximum
number of corners
parameter
Count Scalar value that represents 32-bit unsigned integer
the number of detected corners
Metric Matrix of corner metric values Same as I port
that is the same size as the
input image

Minimum Eigenvalue Method


This method is more computationally expensive than the Harris corner
detection algorithm because it directly calculates the eigenvalues of the
sum of the squared difference matrix, M.
The sum of the squared difference matrix, M, is defined as follows:

⎡ A C⎤
M=⎢ ⎥
⎣ C B⎦

The previous equation is based on the following values:

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

Use the Coefficients for separable smoothing filter parameter to


define a vector of filter coefficients. The block multiplies this vector of
coefficients by its transpose to create a matrix of filter coefficients, w.
The block calculates the smaller eigenvalue of the sum of the squared
difference matrix. This minimum eigenvalue corresponds to the corner
metric matrix.

Harris Corner Detection Method


The Harris corner detection method avoids the explicit computation of
the eigenvalues of the sum of squared differences matrix by solving for
the following corner metric matrix, R:

R = AB − C 2 − k( A + B)2

A, B, C are defined in the previous section, “Minimum Eigenvalue


Method” on page 1-295.
The variable k corresponds to the sensitivity factor. You can specify
its value using the Sensitivity factor (0<k<0.25) parameter. The
smaller the value of k, the more likely it is that the algorithm can detect
sharp corners.
Use the Coefficients for separable smoothing filter parameter to
define a vector of filter coefficients. The block multiplies this vector of
coefficients by its transpose to create a matrix of filter coefficients, w.

Local Intensity Comparison


This method determines that a pixel is a possible corner if it has
either, N contiguous valid bright surrounding pixels, or N contiguous
dark surrounding pixels. Specifying the value of N is discussed later
in this section. The next section explains how the block finds these
surrounding pixels.
Suppose that p is the pixel under consideration and j is one of the
pixels surrounding p. The locations of the other surrounding pixels are
denoted by the shaded areas in the following figure.

1-296
Corner Detection

Surrounding
pixel j

Pixel under
consideration

Angle

I p and I j are the intensities of pixels p and j, respectively. Pixel j is a


valid bright surrounding pixel if I j − I p ≥ T . Similarly, pixel j is a valid
dark surrounding pixel if I p − I j ≥ T . In these equations, T is the value
you specified for the Intensity comparison threshold parameter.
The block repeats this process to determine whether the block has N
contiguous valid surrounding pixels. The value of N is related to the
value you specify for the Maximum angle to be considered a corner
(in degrees), as shown in the following table.

1-297
Corner Detection

Number of Valid Angle (degrees)


Surrounding Pixels, N
15 22.5
14 45
13 67.5
12 90
11 112.5
10 135
9 157.5

After the block determines that a pixel is a possible corner, it computes


its corner metric using the following equation:

⎛ ⎞
R = max ⎜ ∑ I p − I j − T, ∑ I p − I j − T, ⎟
⎜ ⎟
⎝ j: I j ≥ I p + T j: I j ≤ I p − T ⎠

Fixed-Point Data Types


The following diagram shows the data types used in the Corner
Detection block for fixed-point signals. These diagrams apply to the
Harris corner detection and minimum eigenvalue methods only.

1-298
Corner Detection

1-299
Corner Detection

The following table summarizes the variables used in the previous


diagrams.

Variable Name Definition


IN_DT Input data type
MEM_DT Memory data type
OUT_DT Metric output data type
COEF_DT Coefficients data type

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

When you set the this parameter to Corner location or Corner


location and metric matrix, the Maximum number of
corners, Minimum metric value that indicates a corner,
and Neighborhood size (suppress region around detected
corners) parameters appear on the block.

To determine the final corner values, the block follows this


process:
1 Find the pixel with the largest corner metric value.

2 Verify that the metric value is greater than or equal to the


value you specified for the Minimum metric value that
indicates a corner parameter.
3 Suppress the region around the corner value by the size
defined in the Neighborhood size (suppress region around
detected corners) parameter.

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.

The corner metric values computed by the Minimum eigenvalue


and Local intensity comparison methods are always
non-negative. The corner metric values computed by the Harris
corner detection method can be negative.
Maximum number of corners
Enter the maximum number of corners you want the block to
find. This parameter is visible if you set the Output parameter to
Corner location or Corner location and metric matrix.
Minimum metric value that indicates a corner
Specify the minimum corner metric value. This parameter is
visible if you set the Output parameter to Corner location
or Corner location and metric matrix. This parameter is
tunable.

1-304
Corner Detection

Neighborhood size (suppress region around detected corners)


Specify the size of the neighborhood around the corner metric
value over which the block zeros out the values. Enter a
two-element vector of positive odd integers, [r c]. Here, r is
the number of rows in the neighborhood and c is the number
of columns. This parameter is visible if you set the Output
parameter to Corner location or Corner location and metric
matrix.

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.

Input data type


Product output data type
MULTIPLIER
Coefficient data type

Use this parameter to specify how to designate the product output


word and fraction lengths.

1-307
Corner Detection

• 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
As shown in the following figure, inputs to the accumulator
are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the
input is added to it.

The result of each addition remains


in the accumulator data type.

ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type

Use this parameter to specify how to designate this accumulator


word and fraction lengths:
• When you select Same as input, these characteristics match
those of the input.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the accumulator, in bits.

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

References [1] C. Harris and M. Stephens. “A Combined Corner and Edge


Detector.” Proceedings of the 4th Alvey Vision Conference. August 1988,
pp. 147-151.

[2] J. Shi and C. Tomasi. “Good Features to Track.” Proceedings of the


IEEE Conference on Computer Vision and Pattern Recognition. June
1994, pp. 593–600.

[3] E. Rosten 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.

See Also Find Local Maxima Computer Vision System Toolbox software
Estimate Geometric Computer Vision System Toolbox software
Transformation

matchFeatures Computer Vision System Toolbox software

extractFeatures Computer Vision System Toolbox software

detectSURFFeatures Computer Vision System Toolbox software

1-310
Corner Detection (To Be Removed)

Purpose Calculate corner metric matrix and find corners in images

Library Analysis & Enhancement


vipanalysis

Description

Note This Corner Detection 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 Corner
Detection block that uses the one-based, [x y] coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-311
Deinterlacing

Purpose Remove motion artifacts by deinterlacing input video signal

Library Analysis & Enhancement


visionanalysis

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

Use the Deinterlacing method parameter to specify how the block


deinterlaces the video.
The following figure illustrates the block’s behavior if you select Line
repetition.

1-312
Deinterlacing

Line Repetition

Original Interlaced Video

Top Field Bottom Field

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

Block Input Block Output - Deinterlaced Video

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

Original Interlaced Video

Top Field Bottom Field

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

Block Input Block Output - Deinterlaced Video

Row 1 A B C Row 1 A B C

Row 2 D E F Row 2 (A+G)/2 (B+H)/2 (C+I)/2

Row 3 G H I Row 3 G H I

Row 4 J K L Row 4 (G+M)/2 (H+N)/2 (I+O)/2

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


Vertical temporal median filtering.

1-314
Deinterlacing

Vertical Temporal Median Filtering

Original Interlaced Video

Top Field Bottom Field

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

Block Input Block Output - Deinterlaced Video

Row 1 A B C Row 1 A B C

Row 2 D E F Row 2 median([A,D,G]) median([B,E,H]) median([C,F,I])

Row 3 G H I Row 3 G H I

Row 4 J K L Row 4 median([G,J,M]) median([H,K,N]) median([I,L,O])

Row 5 M N O Row 5 M N O

Row 6 P Q R Row 6 M N O

Row-Major Data Format


The MATLAB enviroment and the Computer Vision System Toolbox
software use column-major data organization. However, the
Deinterlacing block gives you the option to process data that is stored in

1-315
Deinterlacing

row-major format. When you select the Input image is transposed


(data order is row major) check box, the block assumes that the input
buffer contains contiguous data elements from the first row first, then
data elements from the second row second, and so on through the last
row. Use this functionality only when you meet all the following criteria:

• You are developing algorithms to run on an embedded target that


uses the row-major format.
• You want to limit the additional processing required to take
the transpose of signals at the interfaces of the row-major and
column-major systems.

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.

Use the following two-step workflow to develop algorithms in row-major


format to run on an embedded target.

1-316
Deinterlacing

Step 1:
Create block diagram Algorithm
blocks

Video Transpose Transpose Video


source block block sink
block block

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.

1 Open the example model by typing

ex_deinterlace

at the MATLAB command prompt.

2 Double-click the Deinterlacing block. The model uses this block


to remove the motion artifacts from the input image. The
Deinterlacing method parameter is set to Vertical temporal
median filtering.

1-317
Deinterlacing

3 Run the model.

The original image that contains the motion artifacts appears in the
Input Image window.

1-318
Deinterlacing

The clearer output image appears in the Output Image window.

1-319
Deinterlacing

Fixed-Point Data Types


The following diagram shows the data types used in the Deinterlacing
block for fixed-point signals.

1-320
Deinterlacing

The result of each addition remains


in the accumulator data type.

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

The result of each addition remains


in the accumulator data type.

ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type

As depicted in the previous figure, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate this
accumulator word and fraction lengths:
• 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.
• 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 blocks is 0.
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.

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

Purpose Demosaic Bayer’s format images

Library Conversions
visionconversions

Description

The following figure illustrates a 4-by-4 image in Bayer’s format with


each pixel labeled R, G, or B.

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.

Use the Interpolation algorithm parameter to specify the algorithm


the block uses to calculate the missing color information. If you select
Bilinear, the block spatially averages neighboring pixels to calculate
the color information. If you select Gradient-corrected linear, the
block uses a Weiner approach to minimize the mean-squared error in

1-326
Demosaic

the interpolation. This method performs well on the edges of objects in


the image. For more information, see [1].
Use the Sensor alignment parameter to specify the alignment of the
input image. 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. For example, for the
image at the beginning of this reference page, you would select BGGR.
Both methods use symmetric padding at the image boundaries. For
more information, see the Image Pad block reference page.
Use the Output image signal parameter to 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 appear on the block. Each port outputs one M-by-N
plane of an RGB video stream.

Fixed-Point Data Types


The following diagram shows the data types used in the Demosaic block
for fixed-point signals.

The result of each addition remains


in the accumulator data type.

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

appear on the block. Each port outputs one M-by-N plane of an


RGB video stream.

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 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 blocks is 0.
Accumulator

The result of each addition remains


in the accumulator data type.

ADDER
CAST
Input to adder - Accumulator Accumulator
input data type data type data type

As depicted in the previous figure, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input

1-330
Demosaic

is added to it. Use this parameter to specify how to designate this


accumulator word and fraction lengths:
• 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.
• 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 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] 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

[2] Gunturk, Bahadir K., John Glotzbach, Yucel Altunbasak, Ronald W.


Schafer, and Russel M. Mersereau, “Demosaicking: Color Filter Array
Interpolation,” IEEE Signal Processing Magazine, Vol. 22, Number 1,
January 2005.

1-331
Dilation

Purpose Find local maxima in binary or intensity image

Library Morphological Operations


visionmorphops

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.

If the neighborhood or structuring element does not have an exact


center, the block has a bias toward the lower-right corner, as a result
of the rotation. The block places the maxima there, as illustrated in
the following figure.

This block uses flat structuring elements only.

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

use of a more efficient algorithm. If you enter an array of STREL


objects, the block applies each object to the entire matrix in turn.

Dialog The Dilation dialog box appears as shown in the following figure.
Box

Neighborhood or structuring element source


Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or
structuring element source parameter, you select Specify
via dialog.

1-334
Dilation

References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.

See Also Bottom-hat Computer Vision System Toolbox software


Closing Computer Vision System Toolbox software
Erosion Computer Vision System Toolbox software
Label Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
imdilate Image Processing Toolbox software
strel Image Processing Toolbox software

1-335
Draw Markers

Purpose Draw markers by embedding predefined shapes on output image

Library Text & Graphics


visiontextngfix

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.

Enter a scalar value, M, that defines a (2M+1)-by-(2M+1) pixel


square into which the marker fits. M must be greater than or
equal to 1.
Filled
Select this check box to fill the marker with an intensity value
or a color. This parameter is visible if, for the Marker shape
parameter, you choose Circle or Square.

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.

Block Color Value(s) for Color Value(s) for


Input Drawing One Marker Drawing Multiple
or Multiple Markers Markers with Unique
with the Same Color Color
Intensity Scalar intensity value R-element vector where
image R is the number of
markers
Color P-element vector where P-by-R matrix where P
image P is the number of color is the number of color
planes planes and R is the
number of markers

For each value in the parameter, enter a number between the


minimum and maximum values that can be represented by the
data type of the input image. If you enter a value outside this
range, the block produces an error message.

1-341
Draw Markers

Opacity factor (between 0 and 1)


Specify the opacity of the shading inside the marker, where 0
indicates transparent and 1 indicates opaque. This parameter
appears when you select the Filled check box. This parameter
is tunable.

The following table describes what to enter for the Opacity


factor(s) (between 0 and 1) parameter based on the block input
and the number of markers you are drawing.

Opacity Factor value for Oopacity Factor value for


Drawing One Marker or Drawing Multiple Marker
Multiple Markers with the with Unique Color
Same Color
Scalar intensity value R-element vector where R is
the number of 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

See Also Draw Shapes Computer Vision System Toolbox


software
Insert Text Computer Vision System Toolbox
software

1-343
Draw Markers (To Be Removed)

Purpose Draw markers by embedding predefined shapes on output image

Library Text & Graphics

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-344
Draw Shapes

Purpose Draw rectangles, lines, polygons, or circles on images

Library Text & Graphics


visiontextngfix

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

Image M-by-N matrix of intensity • Double-precision No


values or an M-by-N-by-P floating point
color values where P is the
• Single-precision
number of color planes
floating point
• Fixed point
• Boolean
• 8-, 16-, and 32-bit
signed integer

1-345
Draw Shapes

Complex
Supported Data
Port Input/Output Values
Types
Supported

• 8-, 16-, and 32-bit


unsigned integer
R, G, Scalar, vector, or matrix Same as Image port No
B that is one plane of the
input RGB video stream.
Inputs to the R, G, and B
ports must have the same
dimensions and data type.

Pts Use integer values to • Double-precision No


define one-based shape floating point (only
coordinates. If you enter supported if the
noninteger values, the input to the I or R,
block rounds them to the G, and B ports is
nearest integer. floating point)
• Single-precision
floating point (only
supported if the
input to the I or R,
G, and B ports is
floating point)
• 8-, 16-, and 32-bit
signed integer
• 8-, 16-, and 32-bit
unsigned integer

1-346
Draw Shapes

Complex
Supported Data
Port Input/Output Values
Types
Supported

ROI 4-element vector of • Double-precision No


integers [x y width height], floating point
that define a rectangular
• Single-precision
area in which to draw
floating point
the shapes. The first two
elements represent the • 8-, 16-, and 32-bit
one-based coordinates of signed integer
the upper-left corner of
• 8-, 16-, and 32-bit
the area. The second two
unsigned integer
elements represent the
width and height of the
area.
Clr This port can be used to Same as Image port No
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.
Output Scalar, vector, or matrix of Same as Image port No
pixel values that contain
the shape(s)

1-347
Draw Shapes

Drawing Shapes and Lines


Use the Shape parameter and Pts port to draw the following shapes
or lines:

• Drawing Rectangles on page 348


• Drawing Lines and Polylines on page 350
• Drawing Polygons on page 352
• Drawing Circles on page 354

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

Shape Input to the Pts Port Drawn Shape


Single Rectangle Four-element row vector
[x y width height] where

• x and y are the one-based


coordinates of the upper-left corner
of the rectangle.
• width and height are the width, in
pixels, and height, in pixels, of the
rectangle. The values of width and
height must be greater than 0.

M Rectangles M-by-4 matrix

 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

For an example of how to use the Draw Shapes block to draw a


rectangle, see “Track an Object Using Correlation”.
Drawing Lines and Polylines
The Draw Shapes block lets you draw either a single line, or one or
more polylines. You can draw a polyline with a series of connected line
segments. Set the Shape parameter to Lines, and then follow the
instructions in the table to specify the input to the Pts port to obtain the
desired shape.

Shape Input to the Pts Port Drawn Shape


Single Line Four-element row vector [x1 y1 x2 y2]
where

• x1 and y1 are the coordinates of the


beginning of the line.
• x2 and y2 are the coordinates of the
end of the line.

M Lines M-by-4 matrix

 x11 y11 x12 y12 


x y21 x22 y22 
 21 
     
 
 xM1 yM 1 xM 2 yM 2 
where each row of the matrix
corresponds to a different line and is of
the same form as the vector for a single
line.

1-350
Draw Shapes

Shape Input to the Pts Port Drawn Shape


Single Polyline Vector of size 2L, where L is the
with (L-1) number of vertices, with format, [x1,
Segments y1, x2, y2, ..., xL, yL].

• x1 and y1 are the coordinates of the


beginning of the first line segment.
• x2 and y2 are the coordinates of the
end of the first line segment and
the beginning of the second line
segment.
• xL and yL are the coordinates of the
end of the (L-1)th line segment.

The polyline always contains (L-1)


number of segments because the first
and last vertex points do not connect.
The block produces an error message
when the number of rows is less than
two or not a multiple of two.
M Polylines with M-by-2L matrix
(L-1) Segments
 x11 y11 x12 y12  x1 L y1 L 
x y21 x22 y22  x2 L y2 L 
 21
        
 
 xM1 yM 1 xM 2 yM 2  xML yML 
where each row of the matrix
corresponds to a different polyline and
is of the same form as the vector for
a single polyline. When you require
one polyline to contain less than (L–1)
number of segments, fill the matrix by
repeating the coordinates of the last
vertex.
The block produces an error message if
the number of rows is less than two or
not a multiple of two.

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.

Shape Input to the Pts Port Drawn Shape


Single Polygon Row vector of size 2L, where L is the
with L line number of vertices, with format, [x1 y1
segments x2 y2 ... xL yL] where

• x1 and y1 are the coordinates of the


beginning of the first line segment.
• x2 and y2 are the coordinates of
the end of the first line segment
and the beginning of the second line
segment.
• xL and yL are the coordinates of the
end of the (L-1)th line segment and
the beginning of the Lth line segment.

The block connects [x1 y1] to [xL yL]


to complete the polygon. The block

1-352
Draw Shapes

Shape Input to the Pts Port Drawn Shape

produces an error if the number of rows


is negative or not a multiple of two.
M Polygons M-by-2L matrix
with the largest
number of line  x11 y11 x12 y12  x1 L y1 L
segments in any x y21 x22 y22  x2 L y2 L
line being L  21 
        
 
 xM1 yM 1 xM 2 yM 2  xML yML 
where each row of the matrix
corresponds to a different polygon and
is of the same form as the vector for a
single polygon. If some polygons are
shorter than others, repeat the ending
coordinates to fill the polygon matrix.
The block produces an error message if
the number of rows is less than two or
is not a multiple of two.

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

Shape Input to the Pts Port Drawn Shape


Single Circle Three-element row vector
[x y radius] where

• x and y are coordinates for the


center of the circle.
• radius is the radius of the circle,
which must be greater than 0.

M Circles M-by-3 matrix

 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.

The block performs a smoothing algorithm when you select the


Use antialiasing check box with either Lines, Polygons, or
Circles. The block uses an algorithm similar to the poly2mask
function to determine which subpixels to draw.
Fill shapes
Fill the shape with an intensity value or a color.

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

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 appears when you select
the Fill shapes 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. You can specify
either Black, White, or User-specified value. If you select
User-specified value, the Color value(s) parameter appears
in the dialog box. This parameter appears when you clear the
Fill shapes check box.
Color value(s)
Specify an intensity or color value for the shape’s border or fill.
This parameter applies when you set the Border color or Fill
color parameter to User-specified value. This parameter is
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.

Block Input Color Value(s) Color Value(s) for


for Drawing One Drawing Multiple
Shape or Multiple Shapes with
Shapes with the Unique Color
Same Color
Intensity image Scalar intensity R-element vector
value where R is the
number of shapes
Color image P-element vector R-by-P matrix
where P is the where P is the
number of color number of color
planes planes and R is the
number of shapes

1-358
Draw Shapes

For each value in the Color Value(s) parameter, enter a


number between the minimum and maximum values that can be
represented by the data type of the input image. If you enter a
value outside this range, the block produces an error message.
Opacity factor (between 0 and 1)
Specify the opacity of the shading inside the shape, where 0 is
transparent and 1 is opaque. This parameter is visible if you
select the Fill shapes check box.

The following table describes what to enter for this parameter


based on the block input and the number of shapes you are
drawing. This parameter applies when you select the Filled
check box.

Opacity Factor value for Oopacity Factor value for


Drawing One Shape or Drawing Multiple Shapes
Multiple Shapes with the with Unique Color
Same Color
Scalar intensity value R-element vector where R is
the number of 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.

See Also Draw Markers Computer Vision System Toolbox


software
Insert Text Computer Vision System Toolbox
software

1-360
Draw Shapes (To Be Removed)

Purpose Draw rectangles, lines, polygons, or circles on images

Library Text & Graphics

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-361
Edge Detection

Purpose Find edges of objects in images using Sobel, Prewitt, Roberts, or Canny
method

Library Analysis & Enhancement


visionanalysis

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

• 8-, 16-, 32-bit unsigned integer (not


supported for the Canny method)
Th Matrix of intensity Same as I port No
values
Edge Matrix that represents Boolean No
a binary image
Gv Matrix of gradient Same as I port No
values in the vertical
direction
Gh Matrix of gradient Same as I port No
values in the horizontal
direction
G45 Matrix of gradient Same as I port No
values
G135 Matrix of gradient Same as I port No
values

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

select Sobel or Prewitt, the block outputs the gradient components


that correspond to the horizontal and vertical edge responses at the Gh
and Gv ports, respectively. If you select Gradient components and,
for the Method parameter, you select Roberts, the block outputs the
gradient components that correspond to the 45 and 135 degree edge
responses at the G45 and G135 ports, respectively. If you select Binary
image and gradient components, the block outputs both the binary
image and the gradient components of the image.
Select the User-defined threshold check box to define a threshold
values or values. If you clear this check box, the block computes the
threshold for you.
Use the Threshold source parameter to specify how to enter your
threshold value. If you select Specify via dialog, the Threshold
parameter appears in the dialog box. Enter a threshold value that is
within the range of your input data. If you choose Input port, use
input port Th to specify a threshold value. This value must have the
same data type as the input data. Gradient magnitudes above the
threshold value correspond to edges.
The Edge Detection block computes the automatic threshold using the
mean of the gradient magnitude squared image. However, you can
adjust this threshold using the Threshold scale factor (used to
automatically calculate threshold value) parameter. The block
multiplies the value you enter with the automatic threshold value to
determine a new threshold value.
Select the Edge thinning check box to reduce the thickness of the
edges in your output image. This option requires additional processing
time and memory resources.

Note This block is most efficient in terms of memory usage and


processing time when you clear the Edge thinning check box and use
the Threshold parameter to specify a threshold value.

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.

Fixed-Point Data Types


The following diagram shows the data types used in the Edge Detection
block for fixed-point signals.

1-365
Edge Detection

The result of each addition remains


in the accumulator data type.

MULTIPLIER CAST ADDER CAST


Product output Accumulator Accumulator Output
Input data type data type data type
data type data type

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

and vertical edge responses. If you select Gradient components


and, for the Method parameter, you select Roberts, the block
outputs the gradient components that correspond to the 45 and
135 degree edge responses. If you select Binary image and
gradient components, the block outputs both the binary image
and the gradient components of the image. This parameter is
visible if, for the Method parameter, you select Sobel, Prewitt,
or Roberts.
User-defined threshold
If you select this check box, you can enter a desired threshold
value. If you clear this check box, the block computes the
threshold for you. This parameter is visible if, for the Method
parameter, you select Sobel, Prewitt, or Roberts, and, for the
Output type parameter, you select Binary image or Binary
image and gradient components. This parameter is also visible
if, for the Method parameter, you select Canny.
Threshold source
If you select Specify via dialog, enter your threshold value in
the dialog box. If you choose Input port, use the Th input port to
specify a threshold value that is the same data type as the input
data. This parameter is visible if you select the User-defined
threshold check box.
Threshold
Enter a threshold value that is within the range of your input
data. This parameter is visible if, for the Method parameter, you
select Sobel, Prewitt, or Roberts, you select the User-defined
threshold check box, and, for Threshold source parameter, you
select Specify via dialog. .
Threshold [low high]
Enter the low and high threshold values that define the weak
and strong edges. This parameter is visible if, for the Method
parameter, you select Canny. Then you select the User-defined
threshold check box, and, for Threshold source parameter, you
select Specify via dialog. Tunable.

1-368
Edge Detection

Threshold scale factor (used to automatically calculate


threshold value)
Enter a multiplier that is used to adjust the calculation of the
automatic threshold. This parameter is visible if, for the Method
parameter, you select Sobel, Prewitt, or Roberts, and you clear
the User-defined threshold check box. Tunable.
Edge thinning
Select this check box if you want the block to perform edge
thinning. This option requires additional processing time and
memory resources. This parameter is visible if, for the Method
parameter, you select Sobel, Prewitt, or Roberts, and for the
Output type parameter, you select Binary image or Binary
image and gradient components.
Approximate percentage of weak edge and nonedge pixels (used
to automatically calculate threshold values)
Enter the approximate percentage of weak edge and nonedge
image pixels. The block computes the automatic threshold values
using this approximation. This parameter is visible if, for the
Method parameter, you select Canny. Tunable.
Standard deviation of Gaussian filter
Enter the standard deviation of the Gaussian filter whose
derivative is convolved with the input image. This parameter is
visible if, for the Method parameter, you select Canny.

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

As depicted in the previous figure, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate this
accumulator word and fraction lengths.
• When you select Same as product output, these
characteristics match those of the product output.
• 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 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 blocks is 0.
Gradients
Choose how to specify the word length and fraction length of the
outputs of the Gv and Gh ports. This parameter is visible if, for
the Output type parameter, you choose Gradient components
or Binary image and gradient components:
• When you select Same as accumulator, these characteristics
match those of the accumulator.

1-372
Edge Detection

• When you select Same as product output, these


characteristics match those of the product output.
• 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 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] Gonzales, Rafael C. and Richard E. Woods. Digital Image


Processing. 2nd ed. Englewood Cliffs, NJ: Prentice-Hall, 2002.

[2] Pratt, William K. Digital Image Processing, 2nd ed. New York: John
Wiley & Sons, 1991.

See Also edge Image Processing Toolbox

1-373
Erosion

Purpose Find local minima in binary or intensity images

Library Morphological Operations


visionmorphops

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.

If the neighborhood or structuring element does not have an exact


center, the block has a bias toward the upper-left corner and places the
minima there, as illustrated in the following figure.

This block uses flat structuring elements only.

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

use of a more efficient algorithm. If you enter an array of STREL


objects, the block applies each object to the entire matrix in turn.

Dialog The Erosion dialog box appears as shown in the following figure.
Box

Neighborhood or structuring element source


Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or
structuring element source parameter, you select Specify
via dialog.

1-376
Erosion

References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.

See Also Bottom-hat Computer Vision System Toolbox software


Closing Computer Vision System Toolbox software
Dilation Computer Vision System Toolbox software
Label Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
imerode Image Processing Toolbox software
strel Image Processing Toolbox software

1-377
Estimate Geometric Transformation

Purpose Estimate geometric transformation from matching point pairs

Library Geometric Transformations


visiongeotforms

Description

Use the Estimate Geometric Transformation block to find the


transformation matrix which maps the greatest number of point pairs
between two images. A point pair refers to a point in the input image
and its related point on the image created using the transformation
matrix. You can select to use the RANdom SAmple Consensus
(RANSAC) or the Least Median Squares algorithm to exclude outliers
and to calculate the transformation matrix. You can also use all input
points to calculate the transformation matrix.

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.

RANSAC and Least Median Squares Algorithms


The RANSAC algorithm relies on a distance threshold. A pair of

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:

d = median( D( p1b , ψ( p1a : H )), D( p2b , ψ( p2a : H )),..., D( pbNum , ψ( pN


a
: H )))

For both equations:

pia is a point in image a (Pts1)

pib is a point in image b (Pts2)

ψ( pia : H ) is the projection of a point on image a based on transformation


matrix H

D( pib , pbj ) is the distance between two point pairs on image b


t is the threshold
Num is the number of points
The smaller the distance metric, the better the transformation matrix
and therefore the more accurate the projection image.

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 

The projection of a point  x y by H is:  xˆ yˆ    x y 1 H


affine transformation supports nonisotropic scaling in addition to
all transformations that the nonreflective similarity transformation
supports. It has six degrees of freedom that can be determined from
three pairs of noncollinear points.

 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

The projection of a point  x y by H is represented by homogeneous

coordinates as: uˆ vˆ w


ˆ   x y 1 H

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:

• K number of random samplings is performed

1-382
Estimate Geometric Transformation

• The RANSAC algorithm, when enough number of inlier point pairs


can be mapped, (dynamically updating K)

The Estimate Geometric Transformation algorithm follows these steps:

A transformation matrix H is initialized to zeros

Set count = 0 (Randomly sampling).

While count < K , where K is total number of random samplings to


perform, perform the following;
a

Increment the count; count = count + 1.


b

Randomly select pair of points from images a and b, (2 pairs for


Nonreflective similarity, 3 pairs for affine, or 4 pairs for projective).
c

Calculate a transformation matrix H , from the selected points.


d

If H has a distance metric less than that of H , then replace H


with H .
(Optional for RANSAC algorithm only)
i.
Update K dynamically.
ii.

1-383
Estimate Geometric Transformation

Exit out of sampling loop if enough number of point pairs can be


mapped by H .

Use all point pairs in images a and b that can be mapped by H to


calculate a refined transformation matrix H

Iterative Refinement, (Optional for RANSAC and LMS algorithms)


a

Denote all point pairs that can be mapped by H as inliers.


b

Use inlier point pairs to calculate a transformation matrix H .


c

If H has a distance metric less than that of H , then replace H


with H , otherwise exit the loop.
Number of Random Samplings
The number of random samplings can be specified by the user for the
RANSAC and Least Median Squares algorithms. You can use an
additional option with the RANSAC algorithm, which calculates this
number based on an accuracy requirement. The Desired Confidence
level drives the accuracy.
The calculated number of random samplings, K used with the RANSAC
algorithm, is as follows:

log(1 p)
K
log(1 qs )

where

• p is the probability of independent point pairs belonging to the


largest group that can be mapped by the same transformation. The

1-384
Estimate Geometric Transformation

probability is dynamically calculated based on the number of inliers


found versus the total number of points. As the probability increases,
the number of samplings, K , decreases.
• q is the probability of finding the largest group that can be mapped
by the same transformation.
• s is equal to the value 2, 3, or 4 for Nonreflective similarity, affine,
and projective transformation, respectively.

Iterative Refinement of Transformation Matrix


The transformation matrix calculated from all inliers can be used to
calculate a refined transformation matrix. The refined transformation
matrix is then used to find a new set of inliers. This procedure can be
repeated until the transformation matrix cannot be further improved.
This iterative refinement is optional.

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

Determine number of random samplings using


Select Specified value to enter a positive integer value for
number of random samplings, or select Desired confidence
to set the number of random samplings as a percentage and a
maximum number. This parameter appears when you select Find
and exclude outliers parameter, and you set the value of the
Method parameter to Random Sample Consensus (RANSAC).
Number of random samplings
Specify the number of random samplings for the algorithm to
perform. This parameter appears when you set the value of the
Determine number of random samplings using parameter to
Specified value.
Desired confidence (in %)
Specify a percent by entering a number between 0 and 100. The
Desired confidence value represents the probability of the
algorithm to find the largest group of points that can be mapped
by a transformation matix. This parameter appears when you
set the Determine number of random samplings using
parameter to Desired confidence.
Maximum number of random samplings
Specify an integer number for the maximum number of random
samplings. This parameter appears when you set the Method
parameter to Random Sample Consensus (RANSAC) and you set
the value of the Determine number of random samplings
using parameter to Desired confidence.
Stop sampling earlier when a specified percentage of point
pairs are determined to be inlier
Specify to stop random sampling when a percentage of input
points have been found as inliers. This parameter appears when
you set the Method parameter to Random Sample Consensus
(RANSAC).

1-388
Estimate Geometric Transformation

Perform additional iterative refinement of the transformation


matrix
Specify whether to perform refinement on the transformation
matrix. This parameter appears when you select Find and
exclude outliers check box.
Output Boolean signal indicating which point pairs are inliers
Select this option to output the inlier point pairs that were used
to calculate the transformation matrix. This parameter appears
when you select Find and exclude outliers check box. The
block will not use this parameter with signed or double, data type
points.
When Pts1 and Pts2 are built-in integers, set transformation
matrix date type to
Specify transformation matrix data type as Single or Double
when the input points are built-in integers. The block will not use
this parameter with signed or double, data type points.

Examples Calculate transformation matrix from largest group of point


pairs
Examples of input data and application of the Estimate Geometric
Transformation block appear in the following figures. Figures (a) and
(b) show the point pairs. The points are denoted by stars or circles, and
the numbers following them show how they are paired. Some point
pairs can be mapped by the same transformation matrix. Other point
pairs require a different transformation matrix. One matrix exists
that maps the largest number of point pairs, the block calculates and
returns this matrix. The block finds the point pairs in the largest group
and uses them to calculate the transformation matrix. The point pairs
connected by the magenta lines are the largest group.
The transformation matrix can then be used to stitch the images as
shown in Figure (e).

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.

TroubleshootingThe success of estimating the correct geometric transformation depends


heavily on the quality of the input point pairs. If you chose the RANSAC
or LMS algorithm, the block will randomly select point pairs to compute
the transformation matrix and will use the transformation that best fits
the input points. There is a chance that all of the randomly selected
point pairs may contain outliers despite repeated samplings. In this
case, the output transformation matrix, TForm, is invalid, indicated
by a matrix of zeros.
To improve your results, try the following:

Increase the percentage of inliers in the input points.


Increase the number for random samplings.
For the RANSAC method, increase the desired confidence.
For the LMS method, make sure the input points have 50% or more
inliers.
Use features appropriate for the image contents
Be aware that repeated patterns, for example, windows in office
building, will cause false matches when you match the features. This
increases the number of outliers.
Do not use this function if the images have significant parallax. You
can use the estimateFundamentalMatrix function instead.
Choose the minimum transformation for your problem.
If a projective transformation produces the error message, “A portion
of the input image was transformed to the location at infinity. Only
transformation matrices that do not transform any part of the image
to infinity are supported.”, it is usually caused by a transformation
matrix and an image that would result in an output distortion that
does not fit physical reality. If the matrix was an output of the
Estimate Geometric Transformation block, then most likely it could
not find enough inliers.

1-391
Estimate Geometric Transformation

References R. Hartley and A. Ziserman, “Multiple View Geometry in Computer


Vision,” Second edition, Cambridge University Press, 2003

See Also cp2tform Image Processing Toolbox

vipmosaicking Computer Vision System Toolbox

1-392
Estimate Geometric Transformation (To Be Removed)

Purpose Estimate geometric transformation from matching point pairs

Library Geometric Transformations

Description

Note This Estimate 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
Estimate Geometric Transformation block that uses the one-based, [x y]
coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-393
Find Local Maxima

Purpose Find local maxima in matrices

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

Maximum number of local maxima


Specify the maximum number of maxima you want the block to
find.
Neighborhood size
Specify the size of the neighborhood around the maxima over
which the block zeros out the values. Enter a two-element vector
of positive odd integers, [rc]. Here, r represents the number
of rows in the neighborhood, and c represents the number of
columns.
Source of threshold value
Specify how to enter the threshold value. If you select Input
port, the Th port appears on the block. If you select Specify
via dialog, the Threshold parameter appears in the dialog
box. Enter a scalar value that represents the value all maxima
should meet or exceed.
Threshold
Enter a scalar value that represents the value all maxima should
meet or exceed. This parameter is visible if, for the Source of
threshold value parameter, you choose Specify via dialog.
Input is Hough matrix spanning full theta range
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.
Index output data type
Specify the data type of the Idx port output. Your choices are
double, single, uint8, uint16, or uint32.
Output variable size signal
Specify output data type. When you uncheck the Output
variable size signal, the Count output data type parameter
appears in the dialog box.
Count output data types
Specify the data type of the Count port output. Your choices
are double, single, uint8, uint16, or uint32. This parameter

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

See Also Hough Lines Computer Vision System Toolbox

Hough Transform Computer Vision System Toolbox


Corner Detection Computer Vision System Toolbox
houghpeaks Image Processing Toolbox
vision.CornerDetector Computer Vision System Toolbox
vision.HoughLines Computer Vision System Toolbox
vision.HoughTransform Computer Vision System Toolbox

1-398
Find Local Maxima (To Be Removed)

Purpose Find local maxima in matrices

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-399
Frame Rate Display

Purpose Calculate average update rate of input signal

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.

Calculate and display rate every


Use this parameter to control how often the block updates the
display.

See Also To Multimedia File Computer Vision System Toolbox software


To Video Display Computer Vision System Toolbox software
Video To Workspace Computer Vision System Toolbox software
Video Viewer Computer Vision System Toolbox software

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.

Supported Platforms and File Types


The supported file formats available to you depend on the codecs
installed on your system.

Platform Supported File Name Extensions


All Platforms AVI (.avi)
Windows® Image:
.jpg,.bmp

Video:
MPEG (.mpeg)
MPEG-2 (.mp2)
MPEG-1.mpg

MPEG-4, including H.264 encoded video (.mp4, .m4v)


Motion JPEG 2000 (.mj2)
Windows Media Video (.wmv,.asf, .asx, .asx)
and any format supported by Microsoft DirectShow®
9.0 or higher.
Audio:
WAVE (.wav)
Windows Media Audio File (.wma)
Audio Interchange File Format (.aif, .aiff)
Compressed Audio Interchange File Format(.aifc),
MP3 (.mp3)
Sun Audio (.au)
Apple (.snd)

1-403
From Multimedia File

Platform Supported File Name Extensions


Macintosh Video:
.avi
Motion JPEG 2000 (.mj2)
MPEG-4, including H.264 encoded video (.mp4, .m4v)
Apple QuickTime Movie (.mov)
and any format supported by QuickTime as listed on
http://support.apple.com/kb/HT3775.
Audio:
Uncompressed .avi
Linux® Motion JPEG 2000 (.mj2)
Any format supported by your installed plug-ins
for GStreamer 0.10 or above, as listed on
http://gstreamer.freedesktop.org/documentation/plugins.html,
including Ogg Theora (.ogg).

Windows XP and Windows 7 x64 platform ships with a limited set of


64-bit video and audio codecs. If a compressed multimedia file fails to
play, try one of the two alternatives:

• Run the 32-bit version of MATLAB on your Windows XP x64


platform. Windows XP x64 ships with many 32-bit codecs.
• Save the multimedia file to a supported file format listed in the table
above.

If you use Windows, use Windows Media player Version 11 or later.

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

Output color format


Specify whether you want the block to output RGB, Intensity, or
YCbCr 4:2:2 video frames. This parameter becomes available
only for a signal that contains video. If you select RGB, use the
Image signal parameter to specify how to output a color signal.
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
appear on the block. Each port outputs one M-by-N plane of an
RGB video stream. This parameter becomes available only if
you set the Image color space parameter to RGB and the signal
contains video.
Audio output sampling mode
Select Sample based or Frame based output. This parameter
appears when you specify a file containing audio for the File
name parameter.

The Data Types pane of the To Multimedia File block dialog box
appears as follows.

1-409
From Multimedia File

Audio output data type


Set the data type of the audio samples output at the Audio port.
This parameter becomes available only if the multimedia file
contains audio. You can choose double, single, int16, or uint8
types.

1-410
From Multimedia File

Video output data type


Set the data type of the video frames output at the R, G, B,
or Image ports. This parameter becomes available only if the
multimedia file contains video. You can choose double, single,
int8, uint8, int16, uint16, int32, uint32, or Inherit from
file types.

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.

Port Supported Data Types Supports


Complex
Values?
Image • Double-precision floating point No
• Single-precision floating point
• 8-, 16-, and 32-bit signed integers
• 8-, 16-, and 32-bit unsigned
integers
R, G, B Same as the Image port No
Audio • Double-precision floating point No
• Single-precision floating point
• 16-bit signed integers
• 8-bit unsigned integers
Y, Cb,Cr Same as the Image port No

1-411
From Multimedia File

See Also To Multimedia File Computer Vision System Toolbox


“Specify Sample Simulink
Time”

1-412
Gamma Correction

Purpose Apply or remove gamma correction from images or video streams

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

For normalized input signals, the block removes gamma correction,


which linearizes the input video stream, as defined by the following
equation:

 I 
 , I   SLS B p 
SLS
 
I  
 I   CO  
 F  , I   SLS B p 
 S  

Typical gamma values range from 1 to 3. Most monitor gamma values


range from 1.8 to 2.2. Check with the manufacturer of your hardware to
obtain the exact gamma value. Gamma function parameters for some
common standards are shown in the following table:

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

Use the Operation parameter to specify the block’s operation. If


you want to perform gamma correction, select Gamma. If you want to
linearize the input signal, select De-gamma.
If, for the Operation parameter, you select Gamma, use the Gamma
parameter to 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, use the Gamma parameter to enter
the gamma value of the input video stream.
Select the Linear segment check box if you want the gamma curve to
have a linear portion near black. If you select this check box, the Break
point parameter appears on the dialog box. Enter a scalar value that
indicates the I-axis value of the end of the linear segment. The break
point is shown in the first diagram of this block reference page.

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.

See Also Color Space Conversion Computer Vision System Toolbox


software
imadjust Image Processing Toolbox software

1-417
Gaussian Pyramid

Purpose Perform Gaussian pyramid decomposition

Library Transforms
visiontransforms

Description The Gaussian Pyramid block computes Gaussian pyramid reduction or


expansion to resize an image. The image reduction process involves
lowpass filtering and downsampling the image pixels. The image
expansion process involves upsampling the image pixels and lowpass
filtering. You can also use this block to build a Laplacian pyramid. For
more information, see “Examples” on page 1-420.

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

represents one level of a


Gaussian pyramid.
In Expand mode, the
output can be a matrix
that represents one level
of a Gaussian pyramid.

Use the Operation parameter to specify whether to reduce or expand


the input image. If you select Reduce, the block applies a lowpass filter
and then downsamples the input image. If you select Expand, the block
upsamples and then applies a lowpass filter to the input image.
Use the Pyramid level parameter to specify the number of times the
block upsamples or downsamples each dimension of the image by a
factor of 2. For example, suppose you have a 4-by-4 input image. You
set the Operation parameter to Reduce and the Pyramid level to
1. The block filters and downsamples the image and outputs a 2-by-2
pixel output image. If you have an M-by-N input image and you set the
Operation parameter to Reduce, you can calculate the dimensions of
the output image using the following equation:

⎛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

Use the Coefficient source parameter to specify the coefficients of the


lowpass filter. If you select Default separable filter [1/4-a/2
1/4 a 1/4 1/4-a/2], use the a parameter to define the coefficients in
the vector of separable filter coefficients. If you select Specify via
dialog, use the Coefficient for separable filter parameter to enter a
vector of separable filter coefficients.

Examples
The following example model shows how to construct a Laplacian
pyramid:

1 Open this model by typing

ex_laplacian

at the MATLAB command prompt.

2 Run the model to see the following results.

1-420
Gaussian Pyramid

1-421
Gaussian Pyramid

1-422
Gaussian Pyramid

You can construct a Laplacian pyramid if the dimensions of the input

image, R-by-C, satisfy R = M R 2 N + 1 and C = Mc 2 N + 1 , where MR,


MC, and N are integers. In this example, you have an input matrix
that is 256-by-256. If you set MR and MC equal to 63 and N equal
to 2, you find that the input image needs to be 253-by-253. So you
use a Submatrix block to crop the dimensions of the input image to
253-by-253.

Fixed-Point Data Types


The following diagram shows the data types used in the Gaussian
Pyramid block for fixed-point signals:

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

Input data type


Product output data type
MULTIPLIER
Coefficient data type
As shown 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 the product output word
and fraction lengths.
• When you select Same as input, these characteristics match
those of the input to the block.

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

As shown in the previous figure, inputs to the accumulator are


cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate the
accumulator word and fraction lengths.
• 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 blocks is 0.

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.

See Also Resize Computer Vision System Toolbox software

1-430
Histogram Equalization

Purpose Enhance contrast of images using histogram equalization

Library Analysis & Enhancement


visionanalysis

Description The Histogram Equalization block enhances the contrast of images by


transforming the values in an intensity image so that the histogram of
the output image approximately matches a specified histogram.

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

Use the Target histogram parameter to 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. Use the Number
of bins parameter to enter the number of equally spaced bins you want
the uniform histogram to have.
If you select User-defined, the Histogram source and Histogram
parameters appear on the dialog box. Use the Histogram source
parameter to select how to specify your histogram. If, for the
Histogram source parameter, you select Specify via dialog, you
can use the Histogram parameter to enter the desired histogram of
the output image. The histogram should be a vector of integer values
that represents the desired intensity values in each bin. The block
transforms the input image so that the histogram of the output image is
approximately the specified histogram.
If, for the Histogram source parameter, you select Input port, the
Hist port appears on the block. Use this port to specify your desired
histogram.

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

Dialog The Histogram Equalization dialog box appears as shown in the


Box following figure.

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

See Also imadjust Image Processing Toolbox


histeq Image Processing Toolbox

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

Sine value computation method


If you select Trigonometric function, the block computes sine
and cosine values to calculate the intersections of the lines during
the simulation. If you select Table lookup, the block computes
and stores the trigonometric values to calculate the intersections
of the lines before the simulation starts. In this case, the block
requires extra memory.

For floating-point inputs, set the Sine value computation


method parameter to Trigonometric function. For fixed-point
inputs, set the parameter to Table lookup.
Theta resolution (radians)
Use this parameter to specify the spacing of the theta-axis. This
parameter appears in the dialog box only if, for the Sine value
computation method parameter, you select Table lookup.
parameter appears in the dialog box.

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 Same as first input, the characteristics match


the characteristics 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. All
signals in the Computer Vision System Toolbox blocks have a
bias of 0.

See “Multiplication Data Types” for illustrations depicting the


use of the product output.
Accumulator
Use this parameter to specify how you would like to designate the
accumulator word and fraction lengths.

When you select Same as product output the characteristics


match the characteristics of the product output.

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.

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.

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

See “Detect Lines in Images” and “Measure Angle Between Lines” in


the Computer Vision System Toolbox User Guide.

See Also Find Local Maxima Computer Vision System Toolbox


Hough Transform Computer Vision System Toolbox

1-443
Hough Lines (To Be Removed)

Purpose Find Cartesian coordinates of lines described by rho and theta pairs

Library Transforms

Description

Note This Hough Lines 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 Hough Lines block that
uses the one-based, [x y] coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-444
Hough Transform

Purpose Find lines in images

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.

Theta resolution (radians)


Specify the spacing of the Hough transform bins along the
theta-axis.
Rho resolution (pixels)
Specify the spacing of the Hough transform bins along the
rho-axis.
Output theta and rho values
If you select this check box, the Theta and Rho ports appear on
the block. The block outputs theta and rho-axis vector values
at these ports.
Output data type
Specify the data type of your output signal.

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.

See “Multiplication Data Types” for illustrations depicting the


use of the product output.

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.

Algorithm The Hough Transform block implements the Standard Hough


Transform (SHT). The SHT uses the parametric representation of a line:

rho = x * cos(theta) + y * sin(theta)

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.

See Also Find Local Maxima Computer Vision System Toolbox


Hough Lines Computer Vision System Toolbox
hough Image Processing Toolbox
houghlines Image Processing Toolbox
houghpeaks Image Processing Toolbox

1-451
Image Complement

Purpose Compute complement of pixel values in binary or intensity images

Library Conversions
visionconversions

Description The Image Complement block computes the complement of a binary or


intensity image. For binary images, the block replaces pixel values
equal to 0 with 1 and pixel values equal to 1 with 0. For an intensity
image, the block subtracts each pixel value from the maximum value
that can be represented by the input data type and outputs the
difference.
For example, suppose the input pixel values are given by x(i) and the
output pixel values are given by y(i). If the data type of the input is
double or single precision floating-point, the block outputs y(i) = 1.0-x(i).
If the input is an 8-bit unsigned integer, the block outputs y(i) = 255-x(i).

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.

See Also Autothreshold Computer Vision System Toolbox software


Chroma Resampling Computer Vision System Toolbox software
Color Space Conversion Computer Vision System Toolbox software
imcomplement Image Processing Toolbox software

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

• 8-, 16-bit unsigned integer


Output M-by-N matrix of intensity Same as Input port No
values or an M-by-N-by-P
color video signal where P is
the number of color planes

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.

Output data type


Use this parameter to specify the data type of your output signal.

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.

See Also Autothreshold Computer Vision System Toolbox software

1-456
Image From File

Purpose Import image from image 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

Output port labels


Enter the labels for your output ports using the spacer character,
|, as the delimiter. This parameter is visible if you set the Image
signal parameter to Separate color signals.

The Data Types pane of the Image From File dialog box appears as
shown in the following figure.

Output data type


Specify the data type of your output signal.
Signed
Select to output a signed fixed-point signal. Otherwise, the signal
will be unsigned. This parameter is only visible if, from the
Output data type list, you select Fixed-point.

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.

See Also From Multimedia Computer Vision System Toolbox software


File
Image From Computer Vision System Toolbox software
Workspace

1-461
Image From File

To Video Display Video and Image Processing Blockset software


Video From Computer Vision System Toolbox software
Workspace
Video Viewer Computer Vision System Toolbox software
im2double Image Processing Toolbox software
im2uint8 Image Processing Toolbox software
imread MATLAB

1-462
Image From Workspace

Purpose Import image from MATLAB 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

Output port labels


Enter the labels for your output ports using the spacer character,
|, as the delimiter. This parameter is visible if you set the Image
signal parameter to Separate color signals.

The Data Types pane of the Image From Workspace dialog box appears
as shown in the following figure.

Output data type


Specify the data type of your output signal.
Signed
Select to output a signed fixed-point signal. Otherwise, the signal
is unsigned. This parameter is only visible if, from the Output
data type list, you select Fixed-point.

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.

See Also From Multimedia File Computer Vision System Toolbox


software
To Video Display Computer Vision System Toolbox
software

1-467
Image From Workspace

Video From Workspace Computer Vision System Toolbox


software
Video Viewer Computer Vision System Toolbox
software
im2double Image Processing Toolbox software
im2uint8 Image Processing Toolbox software

1-468
Image Pad

Purpose Pad signal along its rows, columns, or both

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

Examples Pad with a Constant Value


Suppose you want to pad the rows of your input signal with three initial
values equal to 0 and your input signal is defined as follows:

Set the Image Pad block parameters as follows:

• 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

The Image Pad block outputs the following signal:

1-470
Image Pad

Pad by Repeating Border Values


Suppose you want to pad your input signal with its border values, and
your input signal is defined as follows:

Set the Image Pad block parameters as follows:

• 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]

The Image Pad block outputs the following signal:

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.

Pad with Mirror Image


Suppose you want to pad your input signal using its mirror image, and
your input signal is defined as follows:

Set the Image Pad block parameters as follows:

• Method = Symmetric
• Specify = Pad size
• Add columns to = Both left and right

1-472
Image Pad

• Number of added columns = [5 6]


• Add rows to = Both top and bottom
• Number of added rows = 2

The Image Pad block outputs the following signal:

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

Set the Image Pad block parameters as follows:

• 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 Image Pad block outputs the following signal:

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

If you set the Method parameter to Constant, the Pad value


source parameter appears on the dialog box.
• Input port — The PVal port appears on the block. Use this
port to specify the constant value with which to pad your signal
• Specify via dialog — The Pad value parameter appears in
the dialog box. Enter the constant value with which to pad
your signal.
Pad value source
If you select Input port, the PVal port appears on the block.
Use this port to specify the constant value with which to pad
your signal. If you select Specify via dialog, the Pad value
parameter becomes available. This parameter is visible if, for the
Method parameter, you select Constant.
Pad value
Enter the constant value with which to pad your signal. This
parameter is visible if, for the Pad value source parameter, you
select Specify via dialog. This parameter is tunable.
Specify
If you select Pad size, you can enter the size of the padding in
the horizontal and vertical directions.

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.

Use the Add columns to and Number of added columns


parameters to specify the size of the padding in the horizontal
direction. Enter a scalar value, and the block adds this number of
columns to the left, right, or both sides of your input signal. If you
set the Add columns to parameter to Both left and right,
you can enter a two element vector. The left element controls the
number of columns the block adds to the left side of the signal;
the right element controls the number of columns the block adds
to the right side of the signal.
Output row mode
Use the Output row mode parameter to describe how to pad
the input signal.
• User-specified — Use the Number of output rows
parameter to specify the total number of rows.
• Next power of two — The block pads the input signal along
the rows until the length of the rows is equal to a power of two.
When the length of the input signal’s rows is equal to a power
of two, the block does not pad the input signal’s rows.

1-477
Image Pad

Number of added columns


This parameter controls how many columns are added to the
right and/or left side of your input signal. Enter a scalar value,
and the block adds this number of columns to the left, right, or
both sides of your signal. If, for the Add columns to parameter
you select Both left and right, enter a two-element vector.
The left element controls the number of columns the block adds
to the left side of the signal and the right element controls how
many columns the block adds to the right side of the signal. This
parameter is visible if, for the Specify parameter, you select
Pad size.
Add rows to
The Add rows to parameter controls the padding at the top and
bottom of the input signal.
• Top — The block adds additional rows to the top.
• Bottom — The block adds additional rows to the bottom.
• Both top and bottom — The block adds additional rows to
the top and bottom.
• No padding — The block does not change the number of rows.

Use the Add rows to and Number of added rows parameters


to specify the size of the padding in the vertical direction. Enter a
scalar value, and the block adds this number of rows to the top,
bottom, or both of your input signal. If you set the Add rows
to parameter to Both top and bottom, you can enter a two
element vector. The left element controls the number of rows the
block adds to the top of the signal; the right element controls the
number of rows the block adds to the bottom of the signal.
Output column mode
Describe how to pad the input signal. If you select
User-specified, the Row size parameter appears on the block
dialog box. If you select Next power of two, the block pads the
input signal along the rows until the length of the rows is equal

1-478
Image Pad

to a power of two. This parameter is visible if, for the Specify


parameter, you select Output size.

Use the Output column mode parameter to describe how to


pad the input signal.
• User-specified — Use the Number of column rows
parameter to specify the total number of columns.
• Next power of two — The block pads the input signal along
the columns until the length of the columns is equal to a power
of two. When the length of the input signal’s columns is equal
to a power of two, the block does not pad the input signal’s
columns.
Number of added rows
This parameter controls how many rows are added to the top,
bottom, or both of your input signal. Enter a scalar value and the
block adds this number of columns to the top, bottom, or both of
your signal. If, for the Add rows to parameter you select Both
top and bottom, enter a two-element vector. The left element
controls the number of rows the block adds to the top of the signal
and the right element controls how many rows the block adds to
the bottom of the signal. This parameter is visible if you set the
Specify parameter to Pad size.
Action when truncation occurs
The following options are available for the Action when
truncation occurs parameter:
• None — Select this option when you do not want to be notified
that the input signal is truncated.
• Warning — Select this option when you want to receive a
warning in the MATLAB Command Window when the input
signal is truncated.
• Error — Select this option when you want an error dialog box
displayed and the simulation terminated when the input signal
is truncated.

1-479
Image Pad

See Also Selector | Submatrix | imcrop

1-480
Insert Text

Purpose Draw text on image or video stream.

Library Text & Graphics


visiontextngfix

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:

• A single instance of one text string


• Multiple instances of one text string
• Multiple instances of text, with a different text string at each location
Port Description

Port Description Supported Data Types


ImageM-by-N matrix of • Double-precision floating point
intensity values or an
• Single-precision floating point
M-by-N-by-P color video
signal where P represents • Fixed point(signed, word length
the number of color less than or equal to 32.)
planes.
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
R, Matrix that represents Same as Input port
G, one plane of the RGB
B video stream. Outputs
from the R, G, or B ports

1-481
Insert Text

Port Description Supported Data Types

have the same dimensions


and data type.
Select One-based index value • Double-precision floating point.
that indicates which text (This data type is only supported
string to display. if the input to the I or R, G, and
B ports is a floating-point data
type.)
• Single-precision floating point.
(This data type is only supported
if the input to the I or R, G, and
B ports is a floating-point data
type.)
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Variables
Vector or matrix whose The data types supported by this
values are used to replace port depend on the conversion
ANSI C printf-style specification you are using in the
format specifications. Text parameter.
%d, %i, and %u:

• 8-, 16-, 32-bit signed integer


• 8-, 16-, 32-bit unsigned integer

%c and %s:

• 8-bit unsigned integer

%f:

• Double-precision floating point

1-482
Insert Text

Port Description Supported Data Types

• Single-precision floating point

%o, %x, %X, %e, %E, %g, and %G:

• Double-precision floating point


• Single-precision floating point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Color Intensity input — Scalar Same as Input port (The input to
value used for all strings this port must be the same data
or a vector of intensity type as the input to the Input port.)
values whose length is
equal to the number of
strings.
Color input —
Three-element vector
that specifies one color
for all strings or a M-by-3
matrix of color values,
where M represents the
number of strings.

1-483
Insert Text

Port Description Supported Data Types


Location
M-by-2 matrix of • Double-precision floating point.
one-based [x y] (This data type is only supported
coordinates, where M if the input to the I or R, G, and
represents the number B ports is a floating-point data
of text strings to insert. type.)
Location specifies the
• Single-precision floating point.
top-left corner of the text
(This data type is only supported
string bounding box.
if the input to the I or R, G, and
B ports is a floating-point data
type.)
• Boolean
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Opacity
Scalar value that is used • Double-precision floating point.
for all strings or vector (This data type is only supported
of opacity values whose if the input to the Input or R, G,
length is equal to the and B ports is a double-precision
number of strings. floating-point data type.)
• Single-precision floating point.
(This data type is only supported
if the input to the I or R, G,
and B ports is a single-precision
floating-point data type.)
• ufix8_En7 (This data type is
only supported if the input to
the I or R, G, and B ports is a
fixed-point data type.)

Row-Major Data Format


MATLAB and the Computer Vision System Toolbox blocks use
column-major data organization. However, the Insert Text block gives

1-484
Insert Text

you the option to process data that is stored in row-major format.


When you select the Input image is transposed (data order is row
major) check box, the block assumes that the input buffer contains
contiguous data elements from the first row first, then data elements
from the second row second, and so on through the last row. Use this
functionality only when you meet all the following criteria:

• You are developing algorithms to run on an embedded target that


uses the row-major format.
• You want to limit the additional processing required to take
the transpose of signals at the interfaces of the row-major and
column-major systems.

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.

Use the following two-step workflow to develop algorithms in row-major


format to run on an embedded target.

1-485
Insert Text

Step 1:
Create block diagram Algorithm
blocks

Video Transpose Transpose Video


source block block sink
block block

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.

When you enter ANSI C printf-style format specifications, such


as %d, %f, or %s, the Variables port appears on the block. The
block replaces the format specifications in the Text parameter
with each element of the input vector . Use the %s option to
specify a set of text strings for the block to display simultaneously
at different locations. For example, using a Constant block,
enter [uint8('Text1') 0 uint8('Text2')] for the Constant
value parameter. The following table summarizes the supported
conversion specifications.

1-488
Insert Text

Text Parameter Supported Conversion Specifications

Supported Support for Support


specifications multiple for mixed
instances of specifications
the same
specification
%d, %i, %u, %c, %f, Yes No
%o, %x, %X, %e,
%E, %g, and %G
%s No No

Color value source


Select where to specify the text color. Your choices are:
• Specify via dialog — the Color value parameter appears
on the dialog box.
• Input port — the Color port appears on the block.
Color value
Specify the intensity or color of the text. This parameter is visible
if, for the Color source parameter, you select Specify via
dialog. Tunable.

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

Text String Color Values

Block Input One Text String Multiple Text


Strings
Intensity image Color value Color value
parameter or the parameter or the
input to the Color input to the Color
port specified as port specified as a
a scalar intensity vector of intensity
value values whose length
is equal to the
number of strings
Color image Color value Color value
parameter or the parameter or the
input to the Color input to the Color
port specified as an port specified as an
RGB triplet that M-by-3 matrix of
defines the color of color values, where
the text M represents the
number of strings

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.

The following table describes how to format the location of the


text strings depending on the number of strings you specify to

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.

Location Parameter Text String Insertion

Parameter One Instance of Multiple Instances Multiple Instances


One Text String of the Same Text of Unique Text
String Strings
Location [x y] Two-element vector M-by-2 matrix, M-by-2 matrix,
parameter setting of the form [x y] that where M represents where M represents
or the input to the indicates the top-left the number of the number of text
Location port corner of the text locations at which strings. Each
bounding box. to display the row contains the
text string. Each coordinates of the
row contains the top-left corner of the
coordinates of the text bounding box for
top-left corner of the the string, e.g., [x1
text bounding box for y1; x2 y2].
the string, e.g., [x1
y1 ; x 2 y2 ]

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.

Text String Opacity Values

Parameter One Text String Multiple Text


Strings
Opacity parameter Scalar value Vector whose
setting or the input between 0 and length is equal
to the Opacity port 1, where 0 is to the number of
translucent and strings
1 is opaque

Use the Image signal parameter to specify how to input and


output a color video signal:
• 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.
Image signal
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.
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
elements from the second row second, and so on through the last
row.

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.

Examples • “Annotate Video Files with Frame Numbers”

See Also Draw Shapes Computer Vision System Toolbox


Draw Markers Computer Vision System Toolbox

1-495
Insert Text (To Be Removed)

Purpose Draw text on image or video stream.

Library Text & Graphics

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-496
Label

Purpose Label connected components in binary images

Library Morphological Operations


visionmorphops

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

Use the Connectivity parameter to define which pixels are connected


to each other. If you want a pixel to be connected to the other pixels
located on the top, bottom, left, and right, select 4. If you want a pixel
to be connected to the other pixels on the top, bottom, left, right, and
diagonally, select 8.
Consider the following 3-by-3 image. If, for the Connectivity
parameter, you select 4, the block considers the white pixels marked
by black circles to be connected.

1-497
Label

If, for the Connectivity parameter, you select 8, the block considers
the white pixels marked by black circles to be connected.

Use the Output parameter to determine the block’s output. If you


select Label matrix and number of labels, ports Label and Count
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
Label matrix, the Label port appears on the block. If you select Number
of labels, the Count port appears on the block.
Use the Output data type parameter to set the data type of the
outputs at the Label and Count ports. If you select Automatic, the
block calculates the maximum number of objects that can fit inside the
image based on the image size and the connectivity you specified. Based
on this calculation, it determines the minimum output data type size
that guarantees unique region labels and sets the output data type
appropriately. If you select uint32, uint16, or uint8, the data type of
the output is 32-, 16-, or 8-bit unsigned integers, respectively. If you
select uint16, or uint8, the If label exceeds data type size, mark
remaining regions using parameter appears in the dialog box. If the
number of found objects exceeds the maximum number that can be
represented by the output data type, use this parameter to specify the

1-498
Label

block’s behavior. 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.

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.

See Also Bottom-hat Computer Vision System Toolbox software


Closing Computer Vision System Toolbox software
Dilation Computer Vision System Toolbox software
Erosion Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
bwlabel Image Processing Toolbox software
bwlabeln Image Processing Toolbox software

1-500
Median Filter

Purpose Perform 2-D median filtering

Library Filtering and Analysis & Enhancement


visionanalysis
visionfilter

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.

Fixed-Point Data Types


The information in this section is applicable only when the dimensions
of the neighborhood are even.
For fixed-point inputs, you can specify accumulator and output data
types as discussed in “Dialog Box” on page 1-504. Not all these
fixed-point parameters apply to all types of fixed-point inputs. The
following table shows the output and accumulator data type used for
each fixed-point input.

Fixed-Point Input Output Data Type Accumulator Data Type


Even M X X
Odd M X

1-502
Median Filter

Fixed-Point Input Output Data Type Accumulator Data Type


Odd M and complex X X
Even M and complex X X

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

• Enter a scalar value that represents the number of rows and


columns in a square matrix.
• Enter a vector that represents the number of rows and columns
in a rectangular matrix.
Output size
This parameter controls the size of the output matrix.
• If you choose Same as input port I, the output has the same
dimensions as the input to port I. The Padding options
parameter appears in the dialog box. Use the Padding
options parameter to specify how to pad the boundary of your
input matrix.
• If you select Valid, the block only computes the median where
the neighborhood fits entirely within the input image, with
no need for padding. The dimensions of the output image are,
output rows = input rows - neighborhood rows + 1,
and
output columns = input columns - neighborhood
columns + 1.
Padding options
Specify how to pad the boundary of your input matrix.
• Select Constant to pad your matrix with a constant value. The
Pad value source parameter appears in the dialog box
• Select Replicate to pad your input matrix by repeating its
border values.
• Select Symmetric to 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, for the
Output size parameter, you select Same as input port I.
For more information on padding, see the Image Pad block
reference page.

1-505
Median Filter

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. The Pad value parameter appears
in the dialog box.
• Select Input port to specify your constant value using the
Val port. This parameter appears if, for the Padding options
parameter, you select Constant.

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

information, see fxptdlg, a reference page on the Fixed-Point


Tool in the Simulink documentation.

References [1] Gonzales, Rafael C. and Richard E. Woods. Digital Image


Processing. 2nd ed. Englewood Cliffs, NJ: Prentice-Hall, 2002.

See Also 2-D Convolution Computer Vision System Toolbox


2-D FIR Filter Computer Vision System Toolbox
medfilt2 Image Processing Toolbox

1-509
Opening

Purpose Perform morphological opening on binary or intensity images

Library Morphological Operations


visionmorphops

Description The Opening block performs an erosion operation followed by a dilation


operation using a predefined neighborhood or structuring element. This
block uses flat structuring elements only.

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

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 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.

Dialog The Opening dialog box appears as shown in the following figure.
Box

1-511
Opening

Neighborhood or structuring element source


Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or
structuring element source parameter, you select Specify
via dialog.

References [1] Soille, Pierre. Morphological Image Analysis. 2nd ed. New York:
Springer, 2003.

See Also Bottom-hat Computer Vision System Toolbox software


Closing Computer Vision System Toolbox software
Dilation Computer Vision System Toolbox software
Erosion Computer Vision System Toolbox software
Label Computer Vision System Toolbox software
Top-hat Computer Vision System Toolbox software
imopen Image Processing Toolbox software
strel Image Processing Toolbox software

1-512
Optical Flow

Purpose Estimate object velocities

Library Analysis & Enhancement


visionanalysis

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

In this equation, the following values are represented:

• I x , I y and It are the spatiotemporal image brightness derivatives


• u is the horizontal optical flow
• v is the vertical optical flow

Because this equation is underconstrained, there are several methods


to solve for u and v:

• Horn-Schunck Method
• Lucas-Kanade Method

See the following two sections for descriptions of these methods

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 v]T , that minimizes this equation:

⎧⎪⎛ ∂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:

1 Compute I x and I y using the Sobel convolution kernel:

[ −1 −2 −1; 0 0 0; 1 2 1] , and its transposed form for each


pixel in the first image.

2 Compute It between images 1 and 2 using the [ −1 1] kernel.

3 Assume the previous velocity to be 0, and compute the average

velocity for each pixel using [0 1 0; 1 0 1; 0 1 0] as a


convolution kernel.

4 Iteratively solve for u and v.

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

a constant model for [u v]


T
in each section, Ω , by minimizing the
following equation:

1-515
Optical Flow

∑ W 2[ I xu + I yv + It ]2
x∈Ω

Here, W is a window function that emphasizes the constraints at the


center of each section. The solution to the minimization problem is
given by the following equation:

⎡ ∑ 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 ⎥⎦

When you choose the Lucas-Kanade method, It is computed using a


difference filter or a derivative of a Gaussian filter.

The two following sections explain how I x , I y , It , and then u and v


are computed.
Difference Filter
When you set the Temporal gradient filter to Difference filter
[-1 1], u and v are solved as follows:

1 Compute I x and I y using the kernel [ −1 8 0 −8 1] / 12 and its


transposed form.

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 Compute It between images 1 and 2 using the [ −1 1] kernel.

3 Smooth the gradient components, I x , I y , and It , using a separable


and isotropic 5-by-5 element kernel whose effective 1-D coefficients
are [1 4 6 4 1] / 16 . If you are working with fixed-point data
types, the kernel values are unsigned fixed-point values with word
length equal to 8 and fraction length equal to 7.

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

a+c 4b2 + (a − c)2


In the fixed-point diagrams, P = ,Q =
2 2
• The eigenvalues are compared to the threshold, τ , that
corresponds to the value you enter for the threshold for noise
reduction. The results fall into one of the following cases:

Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, the system of equations are solved using
Cramer’s rule.

Case 2: λ1 ≥ τ and λ 2 < τ


A is singular (noninvertible), the gradient flow is normalized to
calculate u and v.

Case 3: λ1 < τ and λ 2 < τ


The optical flow, u and v, is 0.

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 Compute I x and I y using the following steps:

1-517
Optical Flow

a Use a Gaussian filter to perform temporal filtering. Specify the


temporal filter characteristics such as the standard deviation and
number of filter coefficients using the Number of frames to
buffer for temporal smoothing parameter.
b Use a Gaussian filter and the derivative of a Gaussian filter to
smooth the image using spatial filtering. Specify the standard
deviation and length of the image smoothing filter using the
Standard deviation for image smoothing filter parameter.

2 Compute It between images 1 and 2 using the following steps:

a Use the derivative of a Gaussian filter to perform temporal


filtering. Specify the temporal filter characteristics such as
the standard deviation and number of filter coefficients using
the Number of frames to buffer for temporal smoothing
parameter.
b Use the filter described in step 1b to perform spatial filtering on
the output of the temporal filter.

3 Smooth the gradient components, I x , I y , and It , using a gradient


smoothing filter. Use the Standard deviation for gradient
smoothing filter parameter to specify the standard deviation and
the number of filter coefficients for the gradient smoothing filter.

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

Threshold for noise reduction parameter. The results fall into


one of the following cases:

Case 1: λ1 ≥ τ and λ 2 ≥ τ
A is nonsingular, so the block solves the system of equations using
Cramer’s rule.

Case 2: λ1 ≥ τ and λ 2 < τ


A is singular (noninvertible), so the block normalizes the gradient
flow to calculate u and v.

Case 3: λ1 < τ and λ 2 < τ


The optical flow, u and v, is 0.

tFilt = Coefficients of Gaussian Filter


tGradFilt = Coefficients of the Derivative of a Gaussian Filter
sFilt = Coefficients of Gaussian Filter
sGradFilt = Coefficients of the Derivative of a Gaussian Filter

1-519
Optical Flow

Fixed-Point Data Type Diagram


The following diagrams shows the data types used in the Optical Flow
block for fixed-point signals. The block supports fixed-point data types
only when the Method parameter is set to Lucas-Kanade.

Data type diagram for Optical Flow block’s overall algorithm

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

Data type diagram for convolution algorithm

The result of each addition remains


in the accumulator data type. The result of each addition remains
Product in the accumulator data type.
Image Accumulator
data type output
data type data type
CAST ADDER /
SUBTRACTOR MULTIPLIER CAST ADDER CAST
Accumulator Kernel
data type Accumulator Accumulator Gradient
data type data type data type
data type

Data type diagram for smoothing algorithm

The result of each addition remains


in the accumulator data type. The result of each addition remains
Product in the accumulator data type.
Gradient Accumulator output
data type data type data type
CAST ADDER /
SUBTRACTOR MULTIPLIER CAST ADDER
Accumulator Kernel
data type Accumulator Accumulator
data type data type
data type

1-520
Optical Flow

Data type diagram for product algorithm

Gradient Accumulator Product


data type data type output Gradient
CAST data type data type
MULTIPLIER CAST
CAST
Gradient
data type

1-521
Optical Flow

Solving linear equations to compute eigenvalues


(see Step 4 in the Lucas-Kanade Method section for the eigenvalue equations)

Data type diagram for P

The result of each addition remains


in the accumulator data type.

ADDER RIGHT SHIFT


Accumulator Accumulator
Accumulator data type
data type data type

Data type diagram for 4b^2


Accumulator
data type
Int32
MULTIPLIER CAST MULTIPLIER CAST
Accumulator Accumulator
Product output Product data type
data type data type Accumulator output
data type data type
Data type diagram for (a-c)^2

The result of each addition remains


in the accumulator data type. Product
output
Accumulator data type Accumulator
data type data type
ADDER MULTIPLIER CAST
Accumulator
data type Accumulator
data type
Data type diagram for Q
The result of each addition remains
in the accumulator data type.

ADDER SQUARE ROOT RIGHT SHIFT


Accumulator Accumulator Accumulator Accumulator
data type data type data type data type

Data type diagram for eigenvalues

The result of each addition remains


in the accumulator data type.
Accumulator
data type
1-522
ADDER / CAST
Accumulator SUBTRACTOR Threshold
data type data type
Optical Flow

Data type diagram for finding the motion vectors algorithm


The result of each addition remains
Product in the accumulator data type.
Accumulator output Accumulator
data type data type data type
MULTIPLIER CAST ADDER DIVIDER
MULTIPLIER
Accumulator Accumulator Accumulator
data type data type data type Product
Accumulator output
data type data type

CAST ADDER CAST


Output
Accumulator Accumulator data type
data type data type

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

This parameter is visible if you set the Method parameter to


Horn-Schunck or you set the Method parameter to Lucas-Kanade
and the Temporal gradient filter to Difference filter [-1
1].
N
Enter a scalar value that represents the number of frames
between the reference frame and the current frame. This
parameter becomes available if you set the Compute optical
flow between parameter, you select Current frame and N-th
frame back.
Smoothness factor
If the relative motion between the two images or video frames is
large, enter a large positive scalar value. If the relative motion is
small, enter a small positive scalar value. This parameter becomes
available if you set the Method parameter to Horn-Schunck.
Stop iterative solution
Use this parameter to control when the block’s iterative solution
process stops. If you want it to stop when the velocity difference
is below a certain threshold value, select When velocity
difference falls below threshold. If you want it to stop after
a certain number of iterations, choose When maximum number of
iterations is reached. You can also select Whichever comes
first. This parameter becomes available if you set the Method
parameter to Horn-Schunck.
Maximum number of iterations
Enter a scalar value that represents the maximum number of
iterations you want the block to perform. This parameter is
only visible if, for the Stop iterative solution parameter, you
select When maximum number of iterations is reached or
Whichever comes first. This parameter becomes available if
you set the Method parameter to Horn-Schunck.
Velocity difference threshold
Enter a scalar threshold value. This parameter is only visible
if, for the Stop iterative solution parameter, you select When

1-525
Optical Flow

velocity difference falls below threshold or Whichever


comes first. This parameter becomes available if you set the
Method parameter to Horn-Schunck.
Velocity output
If you select Magnitude-squared, the block outputs the optical
2 2
flow matrix where each element is of the form u + v . 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 .
Temporal gradient filter
Specify whether the block solves for u and v using a difference
filter or a derivative of a Gaussian filter. This parameter becomes
available if you set the Method parameter to Lucas-Kanade.
Number of frames to buffer for temporal smoothing
Use this parameter to specify the temporal filter characteristics
such as the standard deviation and number of filter coefficients.
This parameter becomes available if you set the Temporal
gradient filter parameter to Derivative of Gaussian.
Standard deviation for image smoothing filter
Specify the standard deviation for the image smoothing filter.
This parameter becomes available if you set the Temporal
gradient filter parameter to Derivative of Gaussian.
Standard deviation for gradient smoothing filter
Specify the standard deviation for the gradient smoothing filter.
This parameter becomes available if you set the Temporal
gradient filter parameter to Derivative of Gaussian.
Discard normal flow estimates when constraint equation is
ill-conditioned
Select this check box if you want the block to set the motion vector
to zero when the optical flow constraint equation is ill-conditioned.
This parameter becomes available if you set the Temporal
gradient filter parameter to Derivative of Gaussian.

1-526
Optical Flow

Output image corresponding to motion vectors (accounts for


block delay)
Select this check box if you want the block to output the image
that corresponds to the motion vector being output by the block.
This parameter becomes available if you set the Temporal
gradient filter parameter to Derivative of Gaussian.
Threshold for noise reduction
Enter a scalar value that determines the motion threshold
between each image or video frame. The higher the number, the
less small movements impact the optical flow calculation. This
parameter becomes available if you set the Method parameter
to Lucas-Kanade.

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.

The result of each addition remains


in the accumulator data type.

CAST ADDER
Input to adder - Accumulator
Image, gradient, Accumulator
data type data type
or product output
data type

• When you select Same as product output, these


characteristics match those 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. The bias of
all signals in the Computer Vision System Toolbox blocks is 0.
Gradients
Choose how to specify the word length and fraction length of the
gradients data type:
• When you select Same as accumulator, these characteristics
match those of the accumulator.

1-529
Optical Flow

• When you select Same as product output, these


characteristics match those of the product output.
• 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 blocks is 0.
Threshold
Choose how to specify the word length and fraction length of the
threshold data type:
• When you select Same word length as first input, the
threshold word length matches that of the first input.
• When you select Specify word length, enter the word length
of the threshold data type.
• When you select Binary point scaling, you can enter the
word length and the fraction length of the threshold, in bits.
• When you select Slope and bias scaling, you can enter the
word length in bits and the slope of the threshold. 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 data type:
• 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

1-530
Optical Flow

information, see fxptdlg, a reference page on the Fixed-Point


Tool in the Simulink documentation.

References [1] Barron, J.L., D.J. Fleet, S.S. Beauchemin, and T.A. Burkitt.
Performance of optical flow techniques. CVPR, 1992.

See Also Block Matching Computer Vision System Toolbox software


Gaussian Pyramid Computer Vision System Toolbox software

1-531
Projective Transformation (To Be Removed)

Purpose Transform quadrilateral into another quadrilateral

Library Geometric Transformations


vipgeotforms

Description

Note This block will be removed in a future release. It is recommended


that you replace this block with the Apply Geometric Transformation
and Estimate Geometric Transformation block. The replacement will
require that you modify your model.

1-532
PSNR

Purpose Compute peak signal-to-noise ratio (PSNR) between images

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:

∑ [ I1 (m, n) − I2 (m, n)]2


M, N
MSE =
M*N

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 ⎟
⎝ ⎠

In the previous equation, R is the maximum fluctuation in the input


image data type. For example, if the input image has a double-precision
floating-point data type, then R is 1. If it has an 8-bit unsigned integer
data type, R is 255, etc.

1-533
PSNR

Recommendation for Computing PSNR for Color Images


Different approaches exist for computing the PSNR of a color image.
Because the human eye is most sensitive to luma information, compute
the PSNR for color images by converting the image to a color space that
separates the intensity (luma) channel, such as YCbCr. The Y (luma),
in YCbCr represents a weighted average of R, G, and B. G is given the
most weight, again because the human eye perceives it most easily.
With this consideration, compute the PSNR only on the luma channel.

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)

Purpose Read uncompressed video frames from AVI file

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

Purpose Read binary video data from files

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

Four Character Code Video Formats


Four Character Codes (FOURCC) identify video formats. For more
information about these codes, see http://www.fourcc.org.
Use the Four character code parameter to identify the binary file
format. Then, use the Rows and Cols parameters to define the size
of the output matrix. These dimensions should match the matrix
dimensions of the data inside the file.

1-537
Read Binary File

Custom Video Formats


If your binary file contains data that is not in FOURCC format, you can
configure the Read Binary File block to understand a custom format:

• 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

Frame size: Rows, Cols


Define the size of the output matrix. These dimensions should
match the matrix dimensions of the data inside the file.
Line ordering
Specify how the block fills the output matrix.If you select Top
line first, the block first fills the first row of the output matrix
with the contents of the binary file. It then fills the other rows
in increasing order. If you select Bottom line first, the block
first fills the last row of the output matrix. It then fills the other
rows in decreasing order.
Number of times to play file
Specify the number of times to play the file. The number you
enter must be a positive integer or inf, to play the file until you
stop the simulation.
Output end-of-file indicator
Specifies the output is the last video frame in the binary file.
When you select this check box, a Boolean output port labeled
EOF appears on the block. The output from the EOF port is 1
when the last video frame in the binary file is output from the
block. Otherwise, the output from the EOF port is 0.
Sample time
Specify the sample period of the output signal.

1-540
Read Binary File

Bit stream format


Specify whether your data is planar or packed.
Frame size: Rows, Cols
Define the size of the output matrix. This parameter appears
when you select a Bit stream format parameter of Packed.
Number of output components
Specify the number of components in the binary file.
Component, Bits, Rows, Cols
Specify the component name, bit size, and size of the output
matrices, respectively.

1-541
Read Binary File

Component order in binary file


Specify the order in which the components appear in the binary
file.
Interlaced video
Select this check box if the binary file contains interlaced video
data.
Input file has signed data
Select this check box if the binary file contains signed integers.
Byte order in binary file
Use this parameter to indicate whether your binary file has little
endian or big endian byte ordering.

See Also From Multimedia Computer Vision System Toolbox


File
Write Binary File Computer Vision System Toolbox

1-542
Resize

Purpose Enlarge or shrink image sizes

Library Geometric Transformations


visiongeotforms

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

• 8-, 16-, 32-bit signed integer


• 8-, 16-, 32-bit unsigned integer
Output Resized image Same as Input port No
Flag Boolean value that indicates Boolean No
whether the ROI is within the
image bounds

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.

• Specify = Number of output rows and columns


• Interpolation method = Nearest neighbor, Bilinear, or Bicubic
• Clear the Perform antialiasing when resize factor is between 0
and 100 check box.

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

Flag Port Output Description


0 ROI is completely inside the input
image.
1 ROI is completely or partially
outside the input image.

Fixed-Point Data Types


The following diagram shows the data types used in the Resize block for
fixed-point signals.

You can set the interpolation weights table, product output,


accumulator, and output data types in the block mask.

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.

When you select Output size as a percentage of input


size, the Resize factor in % parameter appears in the dialog
box. Enter a scalar percentage value that is applied to both rows
and columns.

When you select Number of output columns and preserve


aspect ratio, the Number of output columns parameter
appears in the dialog box. Enter a scalar value that represents
the number of columns you want the output image to have. The
block calculates the number of output rows so that the output
image has the same aspect ratio as the input image.

When you select Number of output rows and preserve aspect


ratio, the Number of output rows parameter appears in the
dialog box. Enter a scalar value that represents the number of
rows you want the output image to have. The block calculates the
number of output columns so that the output image has the same
aspect ratio as the input image.

When you select Number of output rows and columns, the


Number of output rows and columns parameter appears
in the dialog box. Enter a two-element vector, where the first
element is the number of rows in the output image and the second
element is the number of columns. In this case, the aspect ratio of
the image can change.
Resize factor in %
Enter a scalar percentage value that is applied to both rows and
columns or a two-element vector, where the first element is the
percentage by which to resize the rows and the second element is

1-547
Resize

the percentage by which to resize the columns. This parameter is


visible if, for the Specify parameter, you select Output size as
a percentage of input size.

You must enter a scalar value that is greater than zero. The table
below describes the affect of the resize factor value:

Resize factor Resizing of image


in %
0 < resize The block shrinks the image.
factor < 100
resize factor = Image unchanged.
100
resize factor > The block enlarges the image.
100
The dimensions of the output matrix depend on the Resize factor
in % parameter and are given by the following equations:

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

Number of output rows and columns


Enter a two-element vector, where the first element is the
number of rows in the output image and the second element is the
number of columns. This parameter is visible if, for the Specify
parameter, you select Number of output rows and columns.
Interpolation method
Specify which interpolation method to resize the image.

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

Output flag indicating if any part of ROI is outside image


bounds
If you select this check box, the Flag port appears on the block.
The block outputs 1 at this port if the ROI is completely or
partially outside the input image. Otherwise, it outputs 0.

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

As depicted in the preceding diagram, 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 input, these characteristics match
those of the input to the block.

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

As depicted in the preceding diagram, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate this
accumulator word and fraction lengths.
• 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 blocks is 0.

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.

[2] Wolberg, George. Digital Image Warping. Washington: IEEE


Computer Society Press, 1990.

See Also Rotate Computer Vision System Toolbox software


Shear Computer Vision System Toolbox software
Translate Computer Vision System Toolbox software
imresize Image Processing Toolbox software

1-554
Resize (To Be Removed)

Purpose Enlarge or shrink image sizes

Library Geometric Transformations


vipgeotforms

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-555
Rotate

Purpose Rotate image by specified angle

Library Geometric Transformations


visiongeotforms

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.

Fixed-Point Data Types


The following diagram shows the data types used in the Rotate block
for bilinear interpolation of fixed-point signals.

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

Note If overflow occurs, the rotated image might appear distorted.

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

Rotation angle source


Specify how to enter your rotation angle. If you select Specify
via dialog, the Angle (radians) parameter appears in the
dialog box.

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.

This parameter is visible if you set the Output size parameter,


to Expanded to fit rotated input image, and the Rotation
angle source parameter toInput port.
Display rotated image in
Specify how the image is rotated. If you select Center, the image
is rotated about its center point. If you select Top-left corner,
the block rotates the image so that two corners of the rotated

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 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.

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

mode, the fraction length of the angle 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
angle values.
• When you select Specify word length, you can enter the word
length of the angle 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 angle values, in bits.
• When you select Slope and bias scaling, you can enter the
word length, in bits, and the slope of the angle values. The bias
of all signals in the Computer Vision System Toolbox blocks is 0.

This parameter is only visible if, for the Rotation angle source
parameter, you select Specify via dialog.
Product output

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 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.

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

As depicted in the previous figure, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate this
accumulator word and fraction lengths.
• When you select Same as product output, these
characteristics match those of the product output.
• 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 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 blocks is 0.
Output
Choose how to specify the word length and fraction length of the
output of the block:

1-564
Rotate

• 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 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.

Supported
Data
Types

Port Supported Data Types


Image • Double-precision floating point
• Single-precision floating point
• Fixed point
• 8-, 16-, 32-bit signed integer
• 8-, 16-, 32-bit unsigned integer
Angle Same as Image port
Output Same as Image port

If the data type of the input signal is floating point, the output signal is
the same data type as the input signal.

References [1] Wolberg, George. Digital Image Warping. Washington: IEEE


Computer Society Press, 1990.

1-565
Rotate

See Also Resize Computer Vision System Toolbox software


Translate Computer Vision System Toolbox software
Shear Computer Vision System Toolbox software
imrotate Image Processing Toolbox software

1-566
SAD (To Be Removed)

Purpose Perform 2-D sum of absolute differences (SAD)

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

Purpose Shift rows or columns of image by linearly varying offset

Library Geometric Transformations


visiongeotforms

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

has an offset equal to the first element of the Row/column shear


values [first last] vector. The following rows have an offset that
linearly increases up to the value you enter for the last element of
the Row/column shear values [first last] vector. If you select
Vertical, the first column has an offset equal to the first element of the
Row/column shear values [first last] vector. The following columns
have an offset that linearly increases up to the value you enter for the
last element of the Row/column shear values [first last] vector.
Use the Output size after shear parameter to specify the size of the
sheared image. If you select Full, the block outputs a matrix that
contains the entire sheared image. If you select Same as input image,
the block outputs a matrix that is the same size as the input image and
contains the top-left portion of the sheared image. Use the Background
fill value parameter to specify the pixel values outside the image.
Use the Shear values source parameter to specify how to enter your
shear parameters. If you select Specify via dialog, the Row/column
shear values [first last] parameter appears in the dialog box. Use
this parameter to enter a two-element vector that represents the
number of pixels by which you want to shift your first and last rows
or columns. For example, if for the Shear direction parameter you
select Horizontal and, for the Row/column shear values [first last]
parameter, you enter [50 150], the block moves the top-left corner
50 pixels to the right and the bottom left corner of the input image
150 pixels to the right. If you want to move either corner to the left,
enter negative values. If for the Shear direction parameter you
select Vertical and, for the Row/column shear values [first last]
parameter, you enter [-10 50], the block moves the top-left corner 10
pixels up and the top right corner 50 pixels down. If you want to move
either corner down, enter positive values.
Use the Interpolation method parameter to specify which
interpolation method the block uses to shear the image. If you select
Nearest neighbor, the block uses the value of the nearest pixel for
the new pixel value. If you select Bilinear, the new pixel value is the
weighted average of the two nearest pixel values. If you select Bicubic,

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.

Fixed-Point Data Types


The following diagram shows the data types used in the Shear block for
bilinear interpolation of fixed-point signals.

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

Output size after shear


Specify the size of the sheared image. If you select Full, the
block outputs a matrix that contains the sheared image values.
If you select Same as input image, the block outputs a matrix
that is the same size as the input image and contains a portion of
the sheared image.
Shear values source
Specify how to enter your shear parameters. If you select
Specify via dialog, the Row/column shear values [first
last] parameter appears in the dialog box. If you select Input
port, port S appears on the block. The block uses the input to this
port at each time step as your shear value.
Row/column shear values [first last]
Enter a two-element vector that represents the number of pixels
by which to shift your first and last rows or columns. This
parameter is visible if, for the Shear values source parameter,
you select Specify via dialog.
Maximum shear value
Enter a real, scalar value that represents the maximum number of
pixels by which to shear your image. This parameter is visible if,
for the Shear values source parameter, you select Input port.
Background fill value
Specify a value for the pixels that are outside the image. This
parameter is tunable.
Interpolation method
Specify which interpolation method the block uses to shear 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 two nearest
pixel values. If you select Bicubic, the new pixel value is the
weighted average of the four nearest pixel values.

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.

This parameter is visible if, for the Shear values source


parameter, you select Specify via dialog.
Product output

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 at the I port.

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

As depicted in the previous figure, inputs to the accumulator


are cast to the accumulator data type. The output of the adder
remains in the accumulator data type as each element of the input
is added to it. Use this parameter to specify how to designate this
accumulator word and fraction lengths.
• When you select Same as product output, these
characteristics match those of the product output.
• 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 accumulator, in bits.

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.

References [1] Wolberg, George. Digital Image Warping. Washington: IEEE


Computer Society Press, 1990.

See Also Resize Computer Vision System Toolbox software


Rotate Computer Vision System Toolbox software
Translate Computer Vision System Toolbox software

1-577
Template Matching

Purpose Locate a template in an image

Library Analysis & Enhancement


visionanalysis

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

Port Supported Data Types


I (Input Image) • Double-precision floating point
• Single-precision floating point
• Fixed point (signed, unsigned or both)
• Boolean
• 8-, 16-, and 32-bit signed integers

1-578
Template Matching

Port Supported Data Types

• 8-, 16-, and 32-bit unsigned integers

T (Template) • Double-precision floating point


• Single-precision floating point
• Fixed point (signed, unsigned or both)
• Boolean
• 8-bit unsigned integers
ROI (Region of • Double-precision floating point
Interest, [x y
• Single-precision floating point
width height])
• Fixed point (signed, unsigned or both)
• Boolean
• 8-bit unsigned integers

1-579
Template Matching

Port Supported Data Types


Metric (Match • Double-precision floating point
Metric Values)
• Single-precision floating point
• Fixed point (signed, unsigned or both)
• Boolean
• 32-bit unsigned integers

Loc (Best • 32-bit unsigned integers


match location
[x y])
NMetric • Double-precision floating point
(Metric
• Single-precision floating point
values in
Neighborhood • Fixed point (signed, unsigned or both)
of best match)
• Boolean
• 8-bit unsigned integers
NValid • Boolean
(Neighborhood
valid)
ROIValid (ROI • Boolean
valid)

1-580
Template Matching

Using the Template Matching Block

Choosing an Output Option


The block outputs either a matrix of match metric values or the
zero-based location of the best template match. The block outputs the
matrix to the Metric port or the location to the Loc port. Optionally,
the block can output an NxN matrix of neighborhood match metric
values to the NMetric port.

Input and Output Signal Sizes


The Template Matching block does not pad the input data. Therefore, it
can only compute values for the match metrics between the input image
and the template, where the template is positioned such that it falls
entirely on the input image. A set of all such positions of the template
is termed as the valid region of the input image. The size of the valid
region is the difference between the sizes of the input and template
images plus one.

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.

Defining the Region of Interest (ROI)


To perform template matching on a subregion of the input image, select
the Enable ROI processing check box. This check box adds the ROI
input port to the Template Matching block. The ROI processing option
is only available for the Best match index mode.

1-581
Template Matching

The ROI port requires a four-element vector that defines a rectangular


area. The first two elements represent [x y] coordinates for the
upper-left corner of the region. The second two elements represent the
width and height of the ROI. The block outputs the best match location
index relative to the top left corner of the input image.

Choosing a Match Metric


The block computes the match metric at each step of the iteration.
Choose the match metric that best suits your application. The block
calculates the global optimum for the best metric value. It uses the
valid subregion of the input image intersected by the ROI, if provided.

Returning the Matrix of Match Metric Values


The matrix of the match metrics always implements single-step
exhaustive window iteration. Therefore, the block computes the metric
values at every pixel.

Returning the Best Match Location


When in the ROI processing mode, the block treats the image around
the ROI as an extension of the ROI subregion. Therefore, it computes
the best match locations true to the actual boundaries of the ROI. The
block outputs the best match coordinates, relative to the top-left corner
of the image. The one-based [x y] coordinates of the location correspond
to the center of the template. The following table shows how the block
outputs the center coordinates for odd and even templates:

1-582
Template Matching

Odd number of pixels in Even number of pixels in


template template

Returning the Neighborhood Match Metric around the Best


Match
When you select Best match location to return the matrix of metrics
in a neighborhood around the best match, an exhaustive loop computes
all the metric values for the N-by-N neighborhood. This output is
particularly useful for performing template matching with subpixel
accuracy.

Choosing a Search Method


When you select Best match location as the output option, you can
choose to use either Exhaustive or Three-step search methods.
The Exhaustive search method is computationally intensive because
it searches at every pixel location of the image. However, this method
provides a more precise result.

1-583
Template Matching

The Three-step search method is a fast search that uses a neighborhood


approach, which does not inspect every pixel. The search starts with a
step size equal to or slightly greater than half of the maximum search
range and then employs the following steps:

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

Using the ROIValid and NValid flags for Diagnostics


The ROIValid and NValid ports represent boolean flags, which track
the valid Region of Interest (ROI) and neighborhood. You can use these
flags to communicate with the downstream blocks and operations.
Valid Region of Interest
If you select the Output flag indicating if ROI is valid check box,
the block adds the ROIValid port. If the ROI lies partially outside the
valid image, the block only processes the intersection of the ROI and the
valid image. The block sets the ROI flag output to this port as follows:

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:

• True, set to 1 indicating that the neighborhood containing the best


match is completely inside the region of interest.
• False, set to 0 indicating that the neighborhood containing the best
match is completely or partially outside of the region of interest.

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.

• Sum of Absolute Differences (SAD)


This metric is also known as the Taxicab or Manhattan Distance
metric. It sums the absolute values of the differences between pixels
in the original image and the corresponding pixels in the template
image. This metric is the l1 norm of the difference image. The lowest
SAD score estimates the best position of template within the search
image. The general SAD distance metric becomes:

n
d1 ( I j , T ) = ∑ Ii, j − Ti
i=1

1-586
Template Matching

• Sum of Squared Differences (SSD)


This metric is also known as the Euclidean Distance metric. It sums
the square of the absolute differences between pixels in the original
image and the corresponding pixels in the template image. This
metric is the square of the l2 norm of the difference image. The
general SSD distance metric becomes:

n
2
d2 ( I j , T ) = ∑ Ii, j − Ti
i=1

• Maximum Absolute Difference (MaxAD)


This metric is also known as the Uniform Distance metric. It sums
the maximum of absolute values of the differences between pixels
in the original image and the corresponding pixels in the template
image. This distance metric provides the l∞ norm of the difference
image. The general MaxAD distance metric becomes:

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:

• Sum of absolute differences (SAD)


• Sum of squared differences (SSD)
• Maximum absolute difference (MaxAD)

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

Output NxN matrix of metric values around best match


This option appears when you select Best match location for the
Output parameter. Select the check box to output a matrix of metric
values centered around the best match. When you do so, the block adds
the NMetric and NValid output ports.

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

• Use this parameter to specify how to designate the product output


word and fraction lengths. Refer to “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. This
block requires power-of-two slope and a bias of zero.

Accumulator
Use this parameter to specify how you would like to designate the
accumulator word and fraction lengths.

• When you select Same as product output the characteristics match


the characteristics of the product output. See “Multiplication Data
Types” for illustrations depicting the use of the accumulator data
type in this block:
When you select Binary point scaling, you can enter the Word
length and the Fraction length of the accumulator, in bits.

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:

• When you select Same as first input, these characteristics match


the characteristics of the accumulator.
• When you select Binary point scaling, you can enter the Word
length and 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. All signals in the
Computer Vision System Toolbox software have a bias of 0.

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.

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.

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

[2] Zakai M., “General distance criteria” IEEE Transaction on


Information Theory, pp. 94–95, January 1964.

[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 .

See Also Block Matching Image Processing Toolbox


Video Stabilization Computer Vision System Toolbox

1-594
Template Matching (To Be Removed)

Purpose Locate a template in an image

Library Analysis & Enhancement

Description

Note This Template Matching 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 Template
Matching block that uses the one-based, [x y] coordinate system.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-595
To Multimedia File

Purpose Write video frames and audio samples 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.

You can compress the video frames or audio samples by selecting a


compression algorithm. You can connect as many of the input ports as
you want. Therefore, you can control the type of video and/or audio the
multimedia file receives.

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.

This block performs best on platforms with Version 11 or later


of Windows Media® Player software. This block supports only
uncompressed RGB24 AVI files on Linux and Mac platforms.

Windows 7 UAC (User Account Control), may require administrative


privileges to encode .mwv and .mwa files.

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.

Note The other items available in this parameter list are


the audio compression algorithms installed on your system.
For information about a specific audio compressor, see the
documentation for that compressor.

Audio data type


Select the audio data type. You can use the Audio data type
parameter only for uncompressed wave files.
Video compressor
Select the type of compression algorithm to use to compress the
video data. This compression reduces the size of the multimedia
file. Choose None (uncompressed) to save uncompressed video
data to the multimedia file.

Note The other items available in this parameter list are


the video compression algorithms installed on your system.
For information about a specific video compressor, see the
documentation for that compressor.

1-599
To Multimedia File

File color format


Select the color format of the data stored in the file. You can select
either RGB or YCbCr 4:2:2.
Image signal
Specify how the block accepts 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.

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

See Also From Multimedia File Computer Vision System Toolbox

1-601
To Video Display

Purpose Display video data

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.

Note This block supports code generation and is only available on


Windows platforms with available file I/O. This excludes Real-Time
Windows Target (RTWin). This block performs best on platforms with
DirectX Version 9.0 or later and Windows Media Version 9.0 or later.

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

Select Full-screen mode to display your video stream in a full


screen window. To exit or return to other applications from
full-screen, select the display and use the Esc key.

1-603
To Video Display

Select True Size (1:1) mode to display a one-to-one pixel ratio


of input image at simulation start time. The block displays the
same information per pixel and does not change size from the
input size. You can change the display size after the model
starts.
Select Normal mode to modify display size at simulation start
time.
Open at Start of Simulation
Select Open at Start of Simulation from the View menu for
the display window to appear while running the model. If not
selected, you can double click the block to display the window.
Settings menu

Input Color Format


Select the color format of the data stored in the input image.
Select RGB for the block to accept a matrix that represents one
plane of the RGB video stream. Inputs to the R, G, or B ports
must have the same dimension and data type.
Select YCbCr 4:2:2 for the block to accept a matrix that
represents one frame of the YCbCr video stream. The Y port
accepts an M-by-N matrix. The Cb and Cr ports accepts an

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

Preferences window. To access the preferences, select Settings


> Preferences . Then select Computer Vision from the
preferences list.

Help menu

Help

Select To Video Display for reference documentation for the


block.
Select Computer Vision System Toolbox to navigate to the
Computer Vision System Toolbox product page.
Select About Computer Vision System Toolbox for version
information.

Supported
Data
Types

Port Supported Data Types


Image • Double-precision floating point
• Single-precision floating point
• Boolean
• 8-, 16, and 32-bit signed integer
• 8-, 16, and 32-bit unsigned integer
R, G, B Same as Image port
YCbCr 4:2:2 Same as Image ports

1-605
To Video Display

See Also Frame Rate Display Computer Vision System Toolbox


software
From Multimedia File Computer Vision System Toolbox
software
To Multimedia File Computer Vision System Toolbox
software
Video To Workspace Computer Vision System Toolbox
software
Video Viewer Computer Vision System Toolbox
software

1-606
Top-hat

Purpose Perform top-hat filtering on intensity or binary images

Library Morphological Operations


visionmorphops

Description The Top-hat block performs top-hat filtering on an intensity or binary


image using a predefined neighborhood or structuring element. Top-hat
filtering is the equivalent of subtracting the result of performing a
morphological opening operation on the input image from the input
image itself. This block uses flat structuring elements only.

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

Input image type


If your input image is a binary image, select Binary. If your input
image is an intensity image, select Intensity.
Neighborhood or structuring element source
Specify how to enter your neighborhood or structuring element
values. Select Specify via dialog to enter the values in the
dialog box. Select Input port to use the Nhood port to specify the
neighborhood values. You can only specify a structuring element
using the dialog box.
Neighborhood or structuring element
If you are specifying a neighborhood, this parameter must be a
matrix or vector of 1s and 0s. If you are specifying a structuring
element, use the strel function from the Image Processing
Toolbox. This parameter is visible if, for the Neighborhood or

1-609
Top-hat

structuring element source parameter, you select Specify


via dialog.

See Also Bottom-hat Computer Vision System Toolbox software


Closing Computer Vision System Toolbox software
Dilation Computer Vision System Toolbox software
Erosion Computer Vision System Toolbox software
Label Computer Vision System Toolbox software
Opening Computer Vision System Toolbox software
imtophat Image Processing Toolbox software
strel Image Processing Toolbox software

1-610
Trace Boundaries (To Be Removed)

Purpose Trace object boundaries in binary images

Library Analysis & Enhancement

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.

Refer to “Conventions Changed for Indexing, Spatial Coordinates, and


Representation of Geometric Transforms” in the R2011b Release Notes
for details related to these changes.

1-611
Trace Boundary

Purpose Trace object boundaries in binary images

Library Analysis & Enhancement


visionanalysis

Description

The Trace Boundary block traces object boundaries in binary images,


where nonzero pixels represent objects and 0 pixels represent the
background.
Port Descriptions

Port Input/Output Supported Data Types


BW Vector or matrix that Boolean
represents a binary image
Start Pt One-based [x y] coordinates • Double-precision floating point
of the boundary starting
• Single-precision floating point
point.
• 8-, 16-, and 32-bit signed integer
• 8-, 16-, and 32-bit unsigned integer
Pts M-by-2 matrix of [x Same as Start Pts port
y] coordinates of the
boundary points, where M
represents the number of
traced boundary pixels. M
must be less than or equal
to the value specified by
the Maximum number

1-612
Trace Boundary

Port Input/Output Supported Data Types

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.

If, for the Connectivity parameter, you select 4, the following


figure illustrates the four possible initial search directions:

North

West East

South

If, for the Connectivity parameter, you select 8, the following


figure illustrates the eight possible initial search directions:

North
Northwest Northeast

West East

Southwest South Southeast

Trace direction
Specify the direction in which to trace the boundary. Your choices
are Clockwise or Counterclockwise.

1-615
Trace Boundary

Maximum number of boundary pixels


Specify the maximum number of boundary pixels for each starting
point. The block uses this value to preallocate the number of rows
of the Pts port output matrix so that it can hold all the boundary
pixel location values.

Use the Maximum number of boundary pixels parameter to


specify the maximum number of boundary pixels f