Mathworks VIDEO AND IMAGE PROCESSING BLOCKSET 3 Reference

Video and Image Pro
Reference
cessing Blockset™ 3
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes
info@mathwo
com
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, 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.
Video and Image Processing Blockset™ Reference
© COPYRIGHT 2004 –2010 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 MathW orks, 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 docume ntation 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 theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand 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 Docu mentation, 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
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2007 Online only New for Version 2.3 (Release 2007a) September 2007 Online only Revised for Version 2.4 (Release 2007b) March 2008 Online only Revised for Version 2.5 (Release 2008a) October 2008 Online only Revised for Version 2.6 (Release 2008b) March 2009 Online only Revised for Version 2.7 (Release 2009a) September 2009 Online only Revised for Version 2.8 (Release 2009b) March 2010 Online only Revised for Version 3.0 (Release 2010a)
Block Reference
1
Analysis & Enhancement ........................... 1-2
Contents
Conversions
Filtering
Geometric Transformations
Morphological Operations
Sinks
Sources
Statistics
Text & Graphics
Transforms
Utilities
............................................. 1-4
....................................... 1-2
.......................................... 1-3
........................................... 1-5
.......................................... 1-5
................................... 1-7
....................................... 1-7
........................................... 1-8
........................ 1-3
.......................... 1-4
v
Blocks — Alphabetical List
2
System Object Reference
3
Analysis & Enhancement ........................... 3-2
Conversions
Filtering
Geometric Transformations
Morphological Operations
Sinks
Sources
Statistics
Text & Graphics
Transforms
Utilities
............................................. 3-4
....................................... 3-2
.......................................... 3-3
........................................... 3-5
.......................................... 3-5
................................... 3-6
....................................... 3-6
........................................... 3-7
........................ 3-3
.......................... 3-4
vi Contents
Alphabetical List
4
Function Reference
5
VideoandImageProcessingFunctions .............. 5-2
vii
viii Contents

Block Reference

Analysis & Enhancement (p. 1-2) Analyze or enhance images or video
Conversions (p. 1-2) Perform conversion operations such
1
as color space conversion
Filtering (p. 1-3)
Geometric Transformations (p. 1-3)
Morphological Operations (p. 1-4) Perform morphological operations
Sinks (p. 1-4)
Sources (p. 1-5) Import imagesorvideointoSimulink
Statistics (p. 1-5) Perform statistical operations on
Text & Graphics (p. 1-7) Annotate images or video
Transforms (p. 1-7) Perform transform operations such
Utilities (p. 1-8) Perform processing operations
Filter images or video
Manipulate size, shape, and orientation of images or video
such as erosion and dilation
Export or display images or video
images or video
as 2-D FFT and 2-D DCT
such as image padding and block processing
1 Block Reference

Analysis & Enhancement

Block Matching Estimate motion between images or
Contrast Adjustment Adjust image contrast by linearly
Corner Detection Calculate corner metric matrix and
video frames
scaling pixel values
find corners in images
Con
versions
Deinterlac
Edge Detec
Histogra
Median F
Optical Flow
Templ
Trace Boundaries Trace object boundaries in binary
Autothreshold Convert intensity image to binary
Chroma Resampling
ing
tion
m Equalization
ilter
ate Matching
Remove motion artifacts by deinterlacing input video signal
Find edges of objects in images using Sobel, Prewitt, Roberts, or Canny method
Enhance contrast of images using histogram equalization
Perform 2-D median filtering
Estima
Locat
images
image
Do c
te object velocities
e a template in an image
wnsample or upsample
hrominance components of images
1-2
olor Space Conversion
C
Demosaic
onvert color information between
C color spaces
Demosaic Bayer’s format images

Filtering

Filtering
Gamma Correction Apply or remove gamma correction
from images or video streams
Image Complement Compute comple ment of pixel values
inbinary,intensity,orRGBimages
Image Data Type Conversion Convert and scale input image to
specified output data type
2-D Convolution Compute 2-D discrete convolution of
two input matrices
2-D FIR Filter
Kalman Filter
Median Filter

Geometric Transformations

Apply Geometric Transformation Apply projective or affine
Estimate Geometric Transformation Estimate geometric transformation
Projective Transformation Transform quadrilateral into
Resize Enlarge or shrink image sizes
Rotate
Perform 2-D FIR filtering on input matrix
Predict or estimate states of dynamic systems
Perform 2-D median filtering
transformation to an image
from matching point pairs
another quadrilateral
Rotate im age by specified angle
1-3
1 Block Reference
Shear Shift rows or columns of image by
Translate Translate image in 2-D plane using

Morphological Operations

linearly varying offset
displacement vector

Sinks

Bottom-hat
Closing Perform morphological closing on
Dilation Find local maxima in binary or
Erosion Find local minima in binary or
Label Label connected components in
Opening Perform morphological opening on
Top-hat
Frame Rate Display
Perform bottom-hat filtering on intensity or bina r y images
binary or intensity images
intensity images
intensity images
binary images
binary or intensity images
Perform top-hat filtering on intensity or binary images
Calculate average update rate of input signal
1-4
To Multimedia File
To Video Display Display video data
Write video frames and audio samples to multimedia file

Sources

Sources
VideoToWorkspace
Video Viewer
Write A VI File (Obsolete) Write video frames to uncompressed
Write Binary File
From Multimedia File
Image From File
Image From Workspace
Read Binary File
Video From Workspace
Export video signal to MATLAB workspace
Display binary, intensity, or RGB images or video streams
AVI file
Write binary video data to files
Read video frames and audio samples from compressed multimedia file
Import image from image file
Import image from MATLAB workspace
Read binary video data from files
Import video signal from MATLAB workspace
®

Statistics

2-D Autocorrelation Compute 2-D autocorrelation of
input matrix
2-D Correlation Com pute 2-D cross-correlation of two
input matrices
2-D Histogram (Obsolete) Generate histogram of each input
matrix
2-D Mean (Obsolete) Find mean value of each input
matrix
1-5
1 Block Reference
2-D Median (Obsolete) Find median value of each input
matrix
2-D S ta n d ard Deviation (Obsolete) Find standard deviation of each
input matrix
2-D Variance (Obsolete) Compute variance of each input
matrix
Blob Analysis Compute statistics for labeled
regions
Find Local Maxima Find local maxima in matrices
Histogram
Maximum Find maximum values in input or
Mean
Median
Minimum Find minimum values in input or
PSNR Compute peak signal-to-noise ratio
Standard Deviation Find standard deviation of each
Variance
Generate histogram of each input matrix
sequence of inputs
Find mean value of each input matrix
Find median value of e ach input matrix
sequence of inputs
(PSNR) between images
input matrix
Compute variance of input or sequence of inputs
1-6

Text & Graphics

Compositing Combine pixel values of two images,
Draw Markers Draw markers by embedding
Text & Graphics
overlay one image over another, or highlight selected pixels
predefined shapes on output image
Transfor
ms
Draw Shapes
Insert Text
2-D DCT Compute 2-D discrete cosine
2-D FFT
2-D IDCT Compute 2-D inverse discrete cosine
2-D IFFT
Gaussian Pyramid Perform Gaussian pyramid
gh Lines
Hou
Hough Transform
Draw rectang circles on im
Draw text on image or video stream.
transform (DCT)
Compute 2-D FFT of input
transform (IDCT)
Compute 2-D IFFT of input
decomposition
Find Cartesian coordinates of lines described by rho and theta pairs
nd lines in images
Fi
les, lines, polygon s , or
ages
1-7
1 Block Reference

Utilities

Block Processing
Image Pad Pad signal along its rows, columns,
Variable Selector Specify subset of rows or columns
Repeat user-specified operation on submatrices of input matrix
or both
from input
1-8
2

Blocks — Alphabetical List

2-D Autocorrelation
Purpose Compute 2-D autocorrelation of input matrix
Library Statistics
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
()()
Na
Ma
Ci j Amn conj Am in j
(, ) ( , ) ( ( , ))
=⋅++
m
1
1
n
=
=
0
0
where
021≤< iMa
The output of this block has dimensions
Port
Input
Input/Output Supported Data Types
Vector or matrix of intensity values or a scalar, vector, or matrix that represents one plane oftheRGBvideostream
Output Autocorrelation of the
input matrix
If the data type of the input is floating point, the output of the block has thesamedatatype.
Fixed-Point Data Types
Thefollowingdiagramshowsthedatatypesusedinthe2-D Autocorrelation block for fixed-point s ignals.
021≤< −jNa
and
.
(,)2121Ma Na−−
Double-precision floating point
Single-precision floating point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit unsigned integer
Same as Input port
.
Complex Val u es Supported
Yes
Yes
2-2
2-D Autocorrelation
You can set the product output, accumulator, and output data types in the b lock mask as discussed in “Dialog Box” on page 2-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” in the Signal Processing Blockset™ documentation.
2-3
2-D Autocorrelation
Dialog Box
The Main pane of the 2-D Autocorrelation dialog box appears as shown in the following figure.
2-4
The Data Types pane of the 2-D Autocorrelation dialog box appears asshowninthefollowingfigure.
2-D Autocorrelation
Rounding mode
Select the rounding mode f or 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. Refer to “Fixed-Point Data Types” on page 2-2 and “Multiplication Data Types” in the Signal Pro cessing
2-5
2-D Autocorrelation
Blockset documentation for illustrations depicting the use of the product output data type in this block:
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the product output, in bits.
When you select
word length, in bits, and the slope of the product output. The bias of all signals in the Video and Image Processing Blockset™ 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 2-2 and “Multiplication Data Types” in the Signal Pro cessing Blockset 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
characteristics match those of the product output.
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the accumulator, in bits.
Same as input, these characteristics match
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Same as product output,these
Same as input, these characteristics match
Binary point scaling,youcanenterthe
2-6
When you select
word length, in bits, and the slope of the accumulator. The bias of all signals in the Video and Image Processing Blockset software is 0.
Output
Choose how to specify the output word length and fraction length.
When you select
thoseoftheinputtotheblock.
Slope and bias scaling,youcanenterthe
Same as input, these characteristics match
2-D Autocorrelation
When you select Binary point scaling,youcanenterthe
word length and the fraction length of the output, in bits.
See Also
When you select
word length, in bits, and the slope of the output. The bias of all signals in the Video and Image Processing Blockset 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 Tool in the Simulink
2-D Correlation
Histogram Video and Image Pro cessing
Mean
Median Video and Image Processing
Standard Deviation
Variance Video and Image Processing
Slope and bias scaling,youcanenterthe
fxptdlg, a reference page on the Fixed-Point
®
documentation.
VideoandImageProcessing Blockset software
Blockset software
VideoandImageProcessing Blockset software
Blockset software
VideoandImageProcessing Blockset software
Blockset software
Maximum
Minimum
Signal P rocess ing Blockset software
Signal P rocess ing Blockset software
2-7
2-D Convolution
Purpose Compute 2-D discrete convolution of two input matrices
Library Filtering
vipfilter
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
()()
Na
Ma
Ci j Amn Bi m j n
(, ) ( , )* ( , )
=−
m
1
1
n
=
=
0
0
2-8
Port
I1
I2
where
01≤< + −iMaMb
01≤< + −jNaNb
and
Input/Output Supported Data Types
Matrix of intensity values or a matrix that represents one plane of the R G B video stream
Double-precision floating point
Single-precision floating point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit unsigned integer
Matrix of intensity
Same as I1 port
values or a matrix that
.
Complex Values Supported
Yes
Yes
Port
Input/Output Supported Data Types
represents one plane of the R G B video stream
2-D Convolution
Complex Values Supported
Output Convolution of the input
matrices
If the data type of the input is floating point, the output of the block has thesamedatatype.
The dimensions of the output are dictated by the Output size parameter. Ass um e 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 convolution with dimensions (Ma+Mb-1, Na+Nb-1). If, for the Output size parameter, you choose central part of the convolution with the same dimensions as the input at port I1. If, for the Output size parameter, you choose is only those parts of the convolution that are computed w ithout the zero-padded edges of any input. This output has dimensions (Ma-Mb+1, Na-Nb+1). However, if
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))),whereI1p is the
portion of the I1 matrix that aligns with the I2 matrix. See “Example 2” on page 2-12 for more information.
Note When you select the Output normalized convolution check box, the block input cannot be fixed point.
Same as I1 port
Full, the output is the full two-dimensional
Same as input port I1, the output is the
Valid, the output
all(size(I1)<size(I2)), the block errors out.
Yes
Fixed-Point Data Types
The following diagram shows the data types used in the 2-D Convolution block for fixed-point signals.
2-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 2-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” in the Signal Processing Blockset documentation.
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 determine the number of rows and columns of the output m atrix:
The resulting matrix is
2-10
Full, the block uses the following equations to
2-D Convolution
If, for the Output size parameter, you choose Same as input port
, the output is the central part of
I1
the input at port I1, (4,3). However, since a 4-by-3 matrix cannot be
extracted from the exact center of columns on the top and left side of the
Cfull
with the same dimensions as
, the block leaves more rows and
Cfull
matrix and outputs:
Cfull
If, for the Output size parameter, you choose Valid, the block uses the following e quations to determine the number of rows and columns of the output matrix:
2-11
2-D Convolution
In this case, it Therefore, the
is always possible to extract the exact center of
block outputs
Cfull
.
Example 2
In convolution, the value of an output element is computed as a weighted sum of neighboring elements.
For example, su p p ose the first inp u t 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]
2-12
The second input matrix also represents an image and is defined as
I2=[816
357 492]
The following figure shows how to compute the (1,1) output element (zero-based indexing) using these steps:
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⋅+⋅+⋅+⋅+ ⋅+ ⋅+⋅+ ⋅+⋅=
.
2-13
2-D Convolution
Values of rotated I2 matrix
2
7
6
9
5
1
4
3
8
Alignment of I2 matrix
Alignment of center element of I2
17
23
4
10
24
5
6
12
1
7
13
19
8
14
20
21
15
16
22
3
Image pixel values
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].
2-14
11 9
18
25
2
2-D Convolution
Dialog Box
The Main pane of the 2-D Convolution dialog box appears as shown in the following figure.
2-15
2-D Convolution
Output size
Output normalized convolution
The Data Types pane of the 2-D Convolution dialog box appears as shown in the following figure.
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 Na+Nb-1). If you choose thesamedimensionsastheinputatportI1. Ifyouchoose output has dimensions (Ma-Mb+1, Na-Nb+1).
If you select this check box, the block’s output is normalized.
Full, the output has dimensions (Ma+Mb-1,
Same as input port I1, the output has
Valid,
2-16
2-D Convolution
2-17
2-D Convolution
Rounding mode
Overflow mode
Product output
Select the rounding mode f or fixed-point operations.
Select the overflow mode for fixed-point operations.
Use this parameter to specify how to designate the product output word and fraction lengths. Refer to “Fixed-Point Data Types” on page 2-9 and “Multiplication Data Types” in the Signal Pro cessing Blockset documentation for illustrations depicting the use of the product output data type in this block:
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the product output, in bits.
When you select
word length, in bits, and the slope of the product output. The bias of all signals in theVideo and Image Processing Blockset software is 0.
The Product Output inherits its sign according to the inputs. If either or both input I1 and I2 aresigned,theProductOutput 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
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Output
2-18
2-D Convolution
Accumulator
Use this parameter to specify how to designate the accumulator word and fraction lengths. Refer to “Fixed-Point Data Types” on page 2-9 and “Multiplication Data Types” in the Signal Pro cessing Blockset 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
characteristics match those of the product output.
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the accumulator, in bits.
When you select
word length, in bits, and the slope of the accumulator. The bias of all signals in the Video and Image Processing Blockset software is 0.
Output
Choose how to specify the word length and fraction length of the output of the block:
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the output, in bits.
When you select
word length, in bits, and the slope of the output. The bias of all signals in the Video and Image Processing Blockset software is 0.
Same as product output,these
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
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
2-19
2-D Convolution
information, see fxptdlg, a reference page on the Fixed-Point Tool in th e Simulink documentation.
See Also
2-D FIR Filter Video and Image Processing Blockset
software
2-20
2-D Correlation
Purpose Compute 2-D cross-correlation of two input matrices
Library Statistics
vipstatistics
Description The 2-D Correlation block computes the two-dimensional
cross-correlation of two input matrices. Assume that matrix A hasdimensions(Ma,Na)andmatrixBhasdimensions(Mb,Nb). When the block calculates the full output size, the equation f or the two-dimensional discrete cross-correlation is
Na
Ma
Ci j Amn conjBm in j
(, ) ( , ) ( ( , ))
=⋅++
m
1
()()
1
n
=
=
0
0
01≤< + −iMaMb
Port
I1
where
Input/Output Supported Data Types
Vector or matrix of intensity values
I2
Scalar, vector, or matrix of intensity values or a scalar, vector, or matrix that represents one plane oftheRGBvideostream
Output Convolution of the input
matrices
01≤< + −jNaNb
and
.
Double-precision floating point
Single-precision floating point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit unsigned integer
Same as I1 port
Same as I1 port
Complex Valu es Supported
Yes
Yes
Yes
2-21
2-D Correlation
If the data type of the input is floating point, the output of the block is thesamedatatype.
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 with dimensions (Ma+Mb-1, Na+Nb-1). If, for the Output size parameter, you choose central part of the cross-correlation with the same dimensions as the inputatportI1. If,fortheOutput size parameter, you choose 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 errors out.
If you select the Normalized output check box, the block’s output is divided by
I1p is the portion of the I1 matrix that aligns with the I2 matrix. See
“Example 2” on page 2-25 for more information.
Full, the output is the full two-dimensional cross-correlation
Same as input port I1, the output is the
Valid,
all(size(I1)<size(I2)),theblock
sqrt(sum(dot(I1p,I1p))*sum(dot(I2,I2))),where
2-22
Note When you select the Normalized output check box , the block inputcannotbefixedpoint.
Fixed-Point Data Types
The following diagram shows the data types used in the 2-D Correlation block for fixed-point signals.
2-D Correlation
You can set the product output, accumulator, and output data types in the block mask as discussed in “Dialog Box” on page 2-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” in the Signal Processing Blockset documentation.
Example
s
Example
Suppose input ma you cho the num
The r
1
I1, the first input matrix, has dimensions (4,3). I2, the second
trix, has dimensions (2,2). If, for the Output size parameter,
ose
Full, the block uses the following equations to determine
ber of rows and columns of the output matrix:
esulting matrix is
2-23
2-D Correlation
If, for the Output size parameter, you choose Same as input port
I1
the input at port I1, (4,3). However, since a 4-by-3 matrix cannot be
extracted from the exact center of columns on the top and left side of the
, the output is the central part of
Cfull
with the same dimensions as
Cfull
, the block leaves more rows and
Cfull
matrix and outputs:
2-24
If, for the Output size parameter, you choose Valid, the block uses the following e quations to determine the number of rows and columns of the output matrix:
2-D Correlation
In this case, it is always possible to extract the exact center of
Cfull
.
Therefore, the block outputs
Example 2
In cross-correlation, the value of an output element is computed as a weighted sum of neighboring elements.
For example, su p p ose the first inp u t 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=[816
357 492]
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-25
2-D Correlation
The ( 2,4) output element from the cross-correlation is
2 Multiply each weight in I2 by the element of I1 underneath.
3 Sum the individual products from step 2.
1 8 8 1 15 6 7 3 14 5 16 7 13 4 20 9 22 2 585⋅+⋅+ ⋅+⋅+ ⋅+ ⋅+ ⋅+ ⋅+ ⋅=
.
2-26
2-D Correlation
Values of I2 matrix
Image pixel values
Alignment of I2 matrix
17
23
4
10
11 9
24
5
6
12
18
1
7
13
19
25
8
14
20
21
2
8
3
4
15
16
22
3
Alignment of center element of I2
1
5
9
6
7
2
Computing the (2,4) Output of Cross-Correlation
2-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].
2-28
2-D Correlation
Dialog Box
The Main pane of the 2-D Correlation dialog box appears as shown in the following figure.
2-29
2-D Correlation
Output size
Normalized output
The Data Types pane of the 2-D Correlation dialog box appears as shown in the following figure.
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 (Ma+Mb-1, Na+Nb-1). If you choose output has the same dimensions as the input at port I1. If you choose
If you select this check box, the block’s output is normalized.
Valid, output has dimensions (Ma-Mb+1, Na-Nb+1).
Full, the output has dimensions
Same as input port I1,the
2-30
2-D Correlation
2-31
2-D Correlation
Rounding mode
Overflow mode
Product output
Select the rounding mode f or fixed-point operations.
Select the overflow mode for fixed-point operations.
Use this parameter to specify how to designate the product output word and fraction lengths. Refer to “Fixed-Point Data Types” on page 2-22 and “Multiplication Data Types” in the Signal Processing Blockset documentation for illustrations depicting the use of the product output data type in this block:
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the product output, in bits.
When you select
word length, in bits, and the slope of the product output. The bias of all signals in the Video and Image Processing Blockset software is 0.
The Product Output inherits its sign according to the inputs. If either or both input I1 and I2 aresigned,theProductOutput 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
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Output
2-32
2-D Correlation
Accumulator
Use this parameter to specify how to designate the accumulator word and fraction lengths. Refer to “Fixed-Point Data Types” on page 2-22 and “Multiplication Data Types” in the Signal Processing Blockset 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
characteristics match those of the product output.
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the accumulator, in bits.
When you select
word length, in bits, and the slope of the accumulator. The bias of all signals in the Video and Image Processing Blockset software is 0.
Output
Choose how to specify the word length and fraction length of the output of the block:
When you select
match those of the first input to the block.
When you select
word length and the fraction length of the output, in bits.
When you select
word length, in bits, and the slope of the output. The bias of all signals in the Video and Image Processing Blockset software is 0.
Same as product output,these
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Same as first input, these characteristics
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
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
2-33
2-D Correlation
information, see fxptdlg, a reference page on the Fixed-Point Tool in th e Simulink documentation.
See Also
2-D Autocorrelation
Histogram Video and Image Processing Blockset
Mean
Median Video and Image Processing Blockset
Standard Deviation
Variance Video and Image Processing Blockset
Maximum
Minimum
VideoandImageProcessingBlockset software
software
VideoandImageProcessingBlockset software
software
VideoandImageProcessingBlockset software
software
Signal Processing Blockset software
Signal Processing Blockset software
2-34
2-D DCT
Purpose Compute 2-D discrete cosine transform ( DCT)
Library Transforms
viptransforms
Description The 2-D DCT block calculates the two-dimensional discrete cosine
transform of the input signal. T he equation for the two-dimensional DCT is
N
M
1
Fmn
(,) ()() (,)cos
221
=
CmCn f x y
MN
1
y
x
=
=
0
0
xmMy
()
++
2
2
π 112)n
(
cos
where
Cm Cn(),() /= 12
for
mn, = 0
and
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.
Port
Input
Input/Output Supported Data Types
Vector or matrix of intensity values
Double-precision floating point
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
If the data type of the input signal is floating point, the output of the block is the same data type.
Cm Cn(),()= 1
otherwise.
Complex Values Supported
No
No
2-35
2-D DCT
Use the Sine and cosine computation parameter to specify how the block computes the sine and cosine terms in the D CT algorithm. If you select values during the simulation. If you select computes and stores the trigonometric values before the simulation starts. In this case, the block requires extra memory.
Trigonometric fcn, the block computes the sine and cosine
Table lookup,theblock
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.
2-36
2-D DCT
2-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” in the Signal Processing Blockset documentation. You can set the sine table, product output, accumulator, and output data types in the block mask as discussed in the next section.
2-38
2-D DCT
Dialog Box
The Main pane of the 2-D DCT dialog box appears as shown in the following figure.
and cosine computation
Sine
ify how the block computes the sine and cosine terms in the
Spec
lgorithm. If you select
DCT a
utes the sine and cosine values during the simulation. If
comp
select
you
Table lookup, the block computes and stores the
Trigonometric fcn,theblock
2-39
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.
2-40
Rounding mode
Select the rounding mode for fixed-point operations. The sine table values do not obey this parameter; they always round to
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:
2-D DCT
Nearest.
A rule that inherits a data type, for example,
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 Roun ding mode and Overflow mode parameters; instead, they are always saturated
and rounded to
Product output data type
Specify the product output data type. See “Fixed-Point Data Types” on page 2-36 and “Multiplication Data Types” for illustrations depicting the use of the product output d a ta type in this block. You can set this parameter to:
A rule that inherits a data type, for example,
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.
Nearest.
Inherit: Same
Inherit:
2-41
2-D DCT
See “Using the Data Type Assistant” in Simulink User’s Guide for more information.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types” on page 2-36 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 via internal rule
Inherit:
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 “Using the Data Type Assistant” in Simulink User’s Guide for more information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on page 2-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 via internal rule
When you select
Inherit: Inherit via internal rule,the
.
Inherit:
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:
2-42
WL WL floor DCT length
ideal output input
FL FL
ideal output input
=+ +(log ( ))211
=
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 “Specifying Block Output Data Types” in Simulink User’s Guide 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-Po int Tool. For more information, see
fxptdlg, a reference page on the Fixed-Point Tool in the
Simulink documentation.
2-D DCT
Refere
nces
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 Tool in th e Simulink documentation.
[1] Che algor vol. C
[2] Wa the d
Proc
n, W.H, C.H. Smith, and S.C. Fralick, “A fast computational
ithm for the discrete cosine transform,” IEEE Trans. Commun.,
OM-25, pp. 1004-1009. 1977.
ng, Z. “Fast algorithms for the discrete W transform and for
iscrete Fourier transform,” IEEE Trans. Acoust., Speech, Signal
essing, vol. ASSP-32, pp. 803-816, Aug. 1984.
fxptdlg, a reference page on the Fixed-Point
2-43
2-D DCT
See Also
2-D IDCT Video and Image Processing Blockset software
2-D FFT
2-D IFFT
Video and Image Processing Blockset software
Video and Image Processing Blockset software
2-44
2-D FFT
Purpose Compute 2-D FFT of input
Library Transforms
viptransforms
Description The 2-D FFT b lock computes the fast Fourier transform (FFT) 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 dimensions of the input matrix, M and N, must be powers of two. To work with other input sizes, use the Pad block to pad or truncate these dimensions to powers of two.
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:
ny
N
M
1
1
Fmn f xye e
where
(,) (,)=
01≤≤−mM
y
x
0
0
=
=
01≤≤ −nN
and
2
j
M
mx
2ππ
j
N
.
2-45
2-D FFT
Port
Description
Supported Data Types
Complex Values Supported
Input
Output 2-D FFT of the input Same as input port
Vector or matrix of intensity v alues
Double-precision floating
point
Single-precision floating point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit unsigned
integer
Yes
Yes
2-46
2-D FFT
If the input signal data type is floating point, the data type of the output signal uses the same floating-point data type. Otherwise, the output can be any fixed-point data type.
Optimizing the Table of Trigonometric Values
The block computes all the possible trigonometric values of the twiddle factor
k
2π
j
K
e
where K is the greater value of either M or N and
kK=−01,,
Theblockstoresthesevaluesinatableandretrievesthemduring simulation. You can optimize the table of trigonometric values for memory or speed using the Optimize table for parameter. This parameter varies the number of table entries as summarized in the following table.
Optimize Table for Param e ter Setting Num ber of Table Entries for N-Point FFT
Speed
3N/4-floating point
.
Memory
N -fixedpoint
N/4 -floating point
Not supported for fixed point
Ordering Output Column Entries
Use the Output in bit-reversed order parameter to specify the ordering of the column elements of the output as either linear or bit-reversed. If you select the Output in bit-reversed order check box, the row and column elements are output in bit-reversed order. Thus, the mth row element appears at the kth position, where k is the bit reversed value of m.Also,thenth column element appears at the lth position, where l is the bit reversed value of n.Ifyouclearthe Output in bit-reversed order check box, the channel elements are output in linear order.
2-47
2-D FFT
Note The 2-D FF T block calculates its output in bit-reversed order.
Linearly ordering the 2-D FFT block output requires an extra bit-reversal operation. Thus, in many situations, you can increase the speed of the 2-D FFT block by selecting the Output in bit-reversed order check box.
For more information ordering of the output, see “Bit-Reversed Order” on page 2-50. The 2-D FFT block bit-reverses the order of both the columns and the rows.
Algorithms Used for FFT Computation
Which algorithms the block uses depends on whether the block input is floating-point or fixed-point, real or complex. The choice of algorithms is also affected by whether you want the output in linear or bit-reversed order. Based on these specifications, the block can use any of the following algorithms:
2-48
Bit-reversal operation
Double-signal algorithm
Half-length algorithm
Radix-2 decimation-in-time (DIT) algorithm
Radix-2 decimation-in-frequency (DIF) algorithm

Floating-Point Signals

Complexity of Input
Complex
Complex
Output Ordering
Linear Bit-reversal operation and radix-2
Bit-reversed Radix-2 DIF
Algorithms Used for FFT Computation
DIT
Floating-Point Signals ( Con tinued)
2-D FFT
Complexity of Input
Real Linear Bit-reversal operation and radix-2
Real Bit-reversed Radix-2 DIF in conjunction with

Fixed-Point Signals

Complexity of Input
Real or complex Line ar Bit-reversal operation and radix-2
Real or complex Bit-reversed Radix-2 DIF
Output Ordering
Output Ordering
Algorithms Used for FFT Computation
DIT in conjunction with the half-length and double-signal algorithms
the half-length and double-signal algorithms
Algorithms Used for FFT Computation
DIT
Fixed-Point Data Types
The follo wing diagrams s how the data types used in the 2-D 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 2-D FFT dialog box as discussed in “Dialog Box” on page 2-53.
The block first casts inputs to the output data type and stores them 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 twiddle factor values before each butterfly stageinadecimation-in-time FFT and after each butterfly stage in a decimation-in-frequency FFT.
2-49
2-D FFT
The output of the multiplier 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 Signal Processing Blockset documentati on .
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 syste m , 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
2-50
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 in
minimum number bits is three be
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 indi
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.
dices into their binary representation with the
of bits. In this example, the minimum number of
cause the binary representation of 7 is 111.
ces now appear in bit-reversed order.
2-51
2-D FFT
Input to FFT block (must be linear order)
76713623
⎡ ⎢
13787016
⎢ ⎢
44313516
36743354
⎢ ⎢
77026623
65214447
⎢ ⎢
31601516
030055355
⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
Output in linear order
Output in bit-reversed order
Output in linear order
Linearly ordered row and column indices
0 1 2
3 4 5
6 7
⎡ ⎢
−−
⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢
−+ − + + −−
Bit-reversed row and column indices
0 1 2 3
4 5 6 7
⎡ ⎢ ⎢ ⎢
18 5 6 3 19
18 5 6 3 5
⎢ ⎢
43 103 11
−−
...iiii ii ii−+ − − − − −+ +
84 2
..44 11 9 184 251 45 11 34 54 176 94 22 13 1 2ii i i i i i+− − −− −+ −−.. .. .. .. . .77
⎢ ⎢
84 24 11 9 45 11 184 251 06 27 22 13 176
4 4 10 3 1 1 11 5 11 5 6 13 1 6 2 13 3 4 8
... . .. . .
−+ + − + −− −−... ..7 26 276 66ii i−+
0
245 13 9 0 4 10 5 15 9 21 6 13 15 9 21 6 10 5 13 9
43 10
.
iii iiii18 5 4 3 10 4 19 24 12 4 11 4 6 3 5 7 16 4 5 4 5 5 1 4−− −−+ + +.. . . .. ..ii
9 163 59 14 31 177 239 1 177 239 14 31 16
−+− + − +3359
84 24 34 54 184 251 22 131 11 9 176 94
+−++−
.. .. . . . . ..
+− −−−++
18 5 5 5 1 4 5 4 5 7 16 4 6 3 12 5 11 3
iii iii119 24 4 3 10 4
44 103 62 13 115 11 26 11 34 8
.. . . . . .......75613127666iii−− − +
1
.. . . . . .
...... ... . . .3 276 66 56 131 34 87 11 26 115 11 62 13ii i iii i−− −+ −+ − − −− +ii
−−+− +
iii iii84 24 06 27 45 11 176 94 11 9 22 13 184 25.. .. .. .. . .−−+−+ + −−−−+...
.. . . . . .
ii i iii−−− −−
.. . . . .
ii ii i
2
ii i ii
ii i ii
3
4
5
6 7
13405
ii
+
45 11 1 27
.. .
+−+
ii
ii
..
Output in bit-reversed order
0
245 13 10 5 10 5 13 9 0 4 15 9 21 6 15 9 21 6 13 9
91143
−−
−− ++ −
+
1
+ − −− −+
ii
ii
i
ii i i i i.. .. . . .. . . − −+ − + −+ −− +994 34 05
ii i i
2
ii i ii.. . . . . .
11 14 31 163 59 177 239 177 239 163 59
ii iiii
−− + −− −+ +
24 5 4 4 3 10 4 5 7 16 4 12 4 11 4 5 5 1 4
ii i i ii
44 19 24 55 14 125 113 57 164 34 05
iiiiii
5 6 13 1 11 5 11 27 6 6 6 2 6 3 4 8 7 6 2 13
.. . .. . .. .
3
++−+−
+−+−+
4
.. . . . . ..
.. .. .. ..
.. . . . . .
5
6 7
..
ii
+
⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
.
i
⎥ ⎥ ⎥ ⎥ ⎥
⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥
i
⎥ ⎥ ⎥ ⎥
2-52
2-D FFT
Dialog Box
The Main pane of the 2-D FFT dialog box a ppears as shown in the following figure.
2-53
2-D FFT
Optimize table for
Optimize the table of twiddle factor values for This parameter must be set to
Output in bit-reversed order
Designate the order of the output channel elements relative to the ordering of the input elements. When selected, the output channel elements appear in bit-reversed order relative to the input ordering. Otherwise, the output column elements display in linear order relative to the input ordering. Linearly ordering the output requires extra data sorting manipulation. For more information, s ee “Bit-Reversed Order” on page 2-50.
Divide butterfly outputs by two
When you select this parameter, the output of each butterfly of the FFT is divided by two.
The Data Types pane of the 2-D FFT dialog box appears as shown in the following figure.
Speed for fixed-point signals.
Speed or Memory.
2-54
2-D FFT
Roun
ding mode
ect the rounding mode for fixed-point operations. The sine
Sel
le values do not obey this parameter; instead, they always
tab
nd to
rou
Nearest.
2-55
2-D FFT
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,
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 Roun ding mode and Overflow mode parameters; instead, they are always saturated
and rounded to
Product output data type
Specify the product output data type. See “Fixed-Point Data Types” on page 2-49 and “Multiplication Data Types” for illustrations depicting the use of the product output d a ta type in this block. You can set this parameter to:
A rule that inherits a data type, for example,
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.
Nearest.
Inherit: Same
Inherit:
2-56
See “Using the Data Type Assistant” in Simulink User’s Guide for more information.
Accumulator data type
Specify the accumulator data type. See “Fixed-Point Data Types” on page 2-49 for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:
2-D FFT
A rule that inherits a data type, for example,
Inherit via internal rule
Inherit:
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 “Using the Data Type Assistant” in Simulink User’s Guide for more information.
Output data type
Specify the output data type. See “Fixed-Point Data Types” on page 2-49 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 via internal rule
When you select
Inherit: Inherit via internal rule,the
.
Inherit:
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:
WL WL floor FFT length
ideal output input
FL FL
ideal output input
g these ideal results, the internal rule then selects word
Usin
gths and fraction lengths that are appropriate for your
len
=+ +(log ( ))211
=
2-57
2-D FFT
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 “Specifying Block Output Data Types” in Simulink User’s Guide 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 Tool in th e Simulink documentation.
fxptdlg, a reference page on the Fixed-Point
2-58
See Also
2-D DCT Video and Image Processing Blockset software
2-D IDCT Video and Image Processing Blockset software
2-D IFFT
FFT
IFFT
Pad
bitrevorder
fft
ifft
Video and Image P roces sing Blockset softw are
Signal Processing Blockset software
Signal Processing Blockset software
Signal Processing Blockset software
Signal Processing Toolbox software
MATLAB
MATLAB
2-D FIR Filter
Purpose Perform 2-D FIR filtering on input matrix
Library Filtering
Description The2-DFiniteImpulseResponse(FIR)filterblockfilterstheinput
Port
matrix and HV.
Input/Output Supported Data Types
I using the coefficient matrix H or the coefficient vectors HH
Complex Valu es Supported
I
H
HH
HV
PVa
Output Scalar, vector, or matrix
Vector or matrix of intensity values
Matrix of filter coefficients Same as I port.
Vector of filter coefficients Same as I port. The input to ports
Vector of filter coefficients Same as I port. The input to ports
l
Scalar value that represents the constant pad value
of filtered values
Double-precision floating point
Single-precision floating point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit unsigned integer
HH and HV must be the same data type.
HH and HV must be the same data type.
ut must have the same data
Inp
eastheinputtoIport.
typ
Same as I port.
Yes
Yes
Yes
Yes
Yes
Yes
2-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,itwouldtake
xyMN⋅⋅ ⋅
multiply-accumulate (MAC) operations for the block to calculate the output. For a separable filter, it would only take
()xyMN+⋅⋅
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,
isfilterseparable(H)
filter kernel,
H, and returns S, HCOL and HROW. Here, S is a Boolean
.Theisfilterseparable function takes the
variable that is 1 if the filter is separable and 0 if it is not. vector of vertical filter coefficients, and
[S, HCOL, HROW] =
HCOL is a
HROW is a vector of horizontal
filter coefficients.
Use the Coefficient source parametertospecifyhowtodefineyour 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
isfilterseparable function, for these parameters. If you select the
HCOL and HROW, the output of 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.
2-60
2-D FIR Filter
If you clear the Separable filter coefficients check b ox and select a Coefficient source of 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 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 hasdimensions(Mi+Mh-1,Ni+Nh-1). IfyouselectanOutput size of
Same as input port I, the output has the same dimensions as the
inputatportI.IfyouselectanOutput size of the input image only where the coefficient matrix f its entirely within it, so no padding is required. The output has dimensions (Mi-Mh+1, Ni-Nh+1). However, if
Specify via dialog,theCoefficients
Input port,portH appears on the block. Use
Full, the output
Valid,theblockfilters
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 values, select image, select repetition of its elements, select
Constant. To pad y our input matrix by repeating its border
Replicate. To pad your input matrix with its mirror
Symmetric. To pad your input matrix using a circular
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 t he dialog box. If you select
Specify via dialog,thePad 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 of
Input port,thePVal
port appears on the block. Use this port to specify the constant value with which to pad your matrix. T he 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.
2-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 set the Output size parameter to
Full, the block filters your input
Convolution and
using the following algorithm
Na
Ma
Ci j Amn Hi m j n
(, ) ( , )* ( , )
=−
m
1
()()
1
n
=
=
0
0
Input (A) data type
Filter coefficient (H) data type
where
Correlation and set the Output size parameter to Full,theblock
01≤< + −iMaMh
and
01≤< + −jNaNh
.Ifyouselect
filters your input using the following algorithm
Na
Ma
Ci j Amn conjHm in j
(, ) ( , ) ( ( , ))
=⋅++
m
where
01≤< + −iMaMh
1
()()
1
n
=
=
0
0
and
01≤< + −jNaNh
.
The imfilter function from the Image Processing Toolbox™ product similarly performs N-D filtering of multidimension al im ages.
Fixed-Point Data Types
Thefollowingdiagramshowsthedatatypesusedinthe2-DFIRFilter block for fixed-point signals.
The result of each addition remains in the accumulator data type
COMPLEX
MULTIPLIER
Accumulator or Product output data type
CAST
Accumulator data type
ADDER
CAST
Accumulator data type
Output (C) data type
2-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 2-64.
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” in the Signal Processing Blockset software documentation.
2-63
2-D FIR Filter
Dialog Box
The Main pane of the 2-D FIR Filter dialog box appears as shown in the following figure.
2-64
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 h ow to define your filter coefficients. Select
dialog
box. Select
to enter your coefficients in the block parameters dialog
Input port to specify your filter coefficient matrix
using port H or ports HH and HV.
Coefficients
Enter your real or co m plex -valued filter coefficient matrix. This parameter appears if you clear the Separable filter coefficients check box and then select a Coefficient source of
dialog
. Tunable.
Vertical coefficients (across height)
Enter the vector of vertical filter coefficients for your separable filter. This parameter appe ars if you select the Separable filter coefficients check box and then select aCoefficient source of
Specify via dialog.
Specify via
Specify via
Horizontal coefficients (across width)
Enter the vector o f horizontal filter coefficients for your separable filter. This parameter appe ars 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 If you choose dimensions as the input at port I If you choose
Full, the output has dimensions (Ma+Mh-1, Na+Nh-1).
Same as input port I, the output has the same
Valid,outputhas
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
2-65
2-D FIR Filter
values. Select Symmetricto pad your input matrix with its mirror image. Select repetition of its elements. This parameter appears if you select an
Output size of
Pad value source
Use this parameter to specify how to define your constant boundary value. Select in the block parameters dialog box. Select your constant value using the PVal port. This parameter appears if you select a Padding options of
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 w ill get an error message if the pad value is complex when the input image is real.
Filtering based on
Specifythealgorithmbywhichthe block filters the input matrix. You can select
Circular to pad your input matrix using a circular
Full or Same as input port I.
Specify via dialog to enter your value
Input port to specify
Constant.
Convolution or Correlation.
2-66
The Data Types pane of the 2-D FIR Filter dialog box appears as shown in the following figure.
2-D FIR Filter
2-67
2-D FIR Filter
Rounding mode
Select the rounding mode f or 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
length of the filter coefficients match that of the input to the block. 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
word length of the coefficients, in bits. I n 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
word length and the fraction length of the coefficients, in bits.
When you select
the word length, in bits, and the slope of the coefficients. All signals in the Video and Image Processing Blockset software have a bias of 0.
The filter coefficients do not obey the Rounding mode and the Overflow mode parameters; instead, they always satur a t ed and rounded to
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 2-62 and “Multiplication Data Types” in the Signal
Nearest.
Same word length as input ,theword
Specify word length,youcanenterthe
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenter
2-68
2-D FIR Filter
Processing Blockset documentation for illustrations depicting the use of the product output data type in this block:
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the product output, in bits.
When you select
word length, in bits, and the slope of the product output. All signals in the Video and Image Processing Blockset software have a bias of 0.
If you set the Coefficent source (on the Main tab) to
the Product Output will inherit its sign according to the
port
inputs. If either or both input I1 and I2 aresigned,theProduct 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
unsigned unsigned unsigned
unsigned signed signed
signed unsigned signed
signed signed signed
Same as input, these characteristics match
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Input
Output
Accumulator
Use this parameter to specify how to designate the accumulator word and fraction lengths. Refer to “Fixed-Point Data Types” on page 2-62 and “Multiplication Data Types” in the Signal Processing Blockset 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:
2-69
2-D FIR Filter
When you select Same as product output,these
characteristics match those of the product output.
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the accumulator, in bits.
When you select
word length, in bits, and the slope of the accumulator. All signals in the Video and Image Processing Blockset software have a bias of 0.
Output
Choose how to specify the word length and fraction length of the output of the block:
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the output, in bits.
When you select
word length, in bits, and the slope of the output. All signals in the Video and Image Processing Blockset software have 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 Tool in th e Simulink documentation.
Same as input, these characteristics match
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
Same as input, these characteristics match
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
fxptdlg, a reference page on the Fixed-Point
2-70
See Also
imfilter
Image Processing Toolbox
2-D Histogram (Obsolete)
Purpose Generate histogram of each input m atrix
Library Statistics
Description
Note The 2-D Histogram block is obsolete. It may b e removed in a
future version of the Video and Image Processing Blockset software. Use the replacement block Histogram.
The 2-D Histogram block computes the frequency distribution of the elements in each input matrix or in a sequence of inputs over a period of time. Use the Running histogram check box to select between the block’s basic and running operation.
The output of the 2-D Histogram block is different than the output of the
imhist function in the Image Processing Toolbox. For intensity
images, the
imhist function defines the pth bin boundaries as
Ap
(.)
15
N
()
1
where A is maximum value of the data type, N is the number of bins in the histogram, and p starts from 1. The 2-D Histogram block defines bin boundaries as
Ap
()
1
<≤
N
where A corresponds to the Maximum value of input parameter and the Minimum value of input parameter is assumed to be 0.
x
≤<
Ap
x
N
Ap
(.)
05
N
()
1
2-71
2-D Histogram (Obsolete)
Port
Input/Output Supported Data Types
Complex Values Supported
Input / I
Rst
Output Sample-based 1-by-N
Vector or matrix of intensity values
Signal that triggers a reset event
vector that represents the frequency distribution of each M-by-N input matrix or the frequency distributions in a series of M-by-N inputs
Length-M 1-D vector inputs are tr eated as M-by -1 column vectors.
Double-precision floating p oint
Single-precision floating point
Fixed point
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Double-precision floating p oint
Single-precision floating point
Boolean
8-, 16-, and 32-bit signed integer
8-, 16-, and 32-bit unsigned integer
Same as Input port
Yes
No
No
2-72
The block sorts the elements of each input matrix into the number of discrete bins, n,specifiedbytheNumber of bins parameter. Complex inputs are sorted by their magnitude squared values.
The histogram value for a given bin represents the frequency of occurrence of the input values bracketed by that bin. You specify the upper b oundary of the highest-valued bin in the Maximum value of input parameter, B
, and the lower boundary of the lowest-valued
M
2-D Histogram (Obsolete)
bin in the Minimum value of input parameter, Bm. The bins have equal width of
where n isthenumberofbins. Thecentersarelocatedat
Input values that fall on the border between two bins are sorted 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 input value 7, but not the input value 3. Input values greater than the
Maximum value of input parameterorlessthanMinimum value of input parameter are sorted into the highest-valued or lowest-valued bin, respectively. The values you enter for the Maximum value of input and Minimum value of input parameters must be real-valued
scalar values.
Basic Operation
If you clear the Running histogram check box, the block computes the f requency distribution of each M-by-N input matrix and outputs a sample-based 1-by-N vector.
111
⎡ ⎢
Forexample,ifyourinputis parameters as follows:
Minimum value of input =
Maximum value of input = 4
Number of bins = 4
222
⎢ ⎢
333
⎤ ⎥
and you set the block
⎥ ⎥
0
2-73
2-D Histogram (Obsolete)
The block outputs [3330].
If you select the Normalized check box, the block scales each element oftheoutputsothat
Running Operation
If you select the Running histogram check box, the block computes the f requency distributions in a series of M-by-N inputs.
For example, if your first input is
222
input is
⎡ ⎢
333
⎢ ⎢
444
⎤ ⎥ ⎥ ⎥
sum(v) is 1, where v is the o utput vector.
111
⎡ ⎢
222
⎢ ⎢
333
, and you set the block parameters as follows:
⎤ ⎥ ⎥ ⎥
, your second and current
Minimum value of input =
Maximum value of input = 4
Number of bins = 4
The block outputs [3663]. For the next input, the block computes the frequency distribution for the first three inputs, and so on.
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.
To enable the Rst port, select the Reset port parameter. You specify the re set event in the Trigger type parameter, and can be one of the following:
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 0
2-74
2-D Histogram (Obsolete)
- Rises from 0 to a positive value, where the rise is not a continuation
ofarisefromanegativevalueto0(seethefollowingfigure)
Rising edge
Rising edge
Rising edge
Falling edge — Triggers a reset operation when the Rst input does
one of the following:
Rising edge
Not a rising edge because it is a continuation of a rise from a negative value to zero.
- Falls from a positive value to a negative value or 0
- Fallsfromzerotoanegativevalue,wherethefallisnota
continuation of a fall from a positive value to 0 (see the following figure)
Falling edge
Falling edge
Falling edge
Falling edge
Not a falling edge because it is a continuation of a fall from a positive value to zero.
Either edge -- Triggers a reset operation when the Rst input is a
Rising edge or Falling edge (as described previously)
2-75
2-D Histogram (Obsolete)
Non-zero sample -- Triggers a reset operation at each sample time
that the
Note When running simulations in the Simulink MultiTasking mode, sample-based reset signals have a one-sample latency, and frame-based reset signals have one frame of latency. Thus, there is a one-sample or one-frame delay between the time the block detects a reset event, and when it applies the reset. For more information on latency and the Simulink tasking modes, see “Configuration Parameters Dialog Box” in the Simulink documentation.
Rst input is not 0
Dialog Box
The Main pane of the 2-D Histogram dialog box:
2-76
2-D Histogram (Obsolete)
Minimum value of input
Enter a real-valued s calar value for the lower boundary, the lowest-valued bin. Tunable.
Maximum value of input
Enter a real-valued scalar value for the upper boundary, the highest-valued bin. Tunable.
Number of bins
Enter the number of bins, n, in the histogram.
Normalized
If you select this check box, the block normalizes the output vector (1-norm). Tunable.
Use of this parameter is not supported for fixed-point signals.
Running histogram
Select this check box to enable the block’s running histogram operation.
Reset port
Enables the Rst input port when selected. The reset signal and theinputdatasignalmustbethesamerate. Thisparameteris visible if you select the Running histogram check box.
Bm
BM
,of
,of
Trigger type
The type of event that resets the running histogram. For more information, see “Resetting the Running Histogram” on page 2-74. This parameter is enabled only when you set the Reset port parameter.
The Fixed-point pane of the 2-D Histogram dialog bo x:
2-77
2-D Histogram (Obsolete)
2-78
Note The inputs,
Roundi
Overf
Prod
which are sorted by squared magnitude.
ng mode
Selec
low mode
Selec
uct output
Use t word
Whe
fixed-point paramete rs are only used for fixed-point complex
t the rounding mode for fixed-point operations.
t the overflow mode for fixed-point operations.
his parameter to specify how to designate the product output
and fraction lengths:
nyouselect
se of the input to the block.
tho
Same as input, these characteristics match
2-D Histogram (Obsolete)
When you select Binary point scaling,youcanenterthe
word length and the fraction length of the product output, in bits.
When you select
word length, in bits, and the slope of the product output. This block requires power-of-two slope and a bias of 0.
Accumulator
Use this parameter to specify the accumulator word and fraction lengths resulting from a complex-complex multiplication in the block:
When you select
characteristics match those of the product output.
When you select
thoseoftheinputtotheblock.
When you select
word length and the fraction length of the accumulator, in bits.
When you select
word length, in bits, and the slope of the accumulator. This block requires power-of-two slope and a bias of 0.
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-Po int Tool. For more information, see
fxptdlg, a reference page on the Fixed-Point Tool in the
Simulink documentation.
Slope and bias scaling,youcanenterthe
Same as product output,these
Same as input, these characteristics match
Binary point scaling,youcanenterthe
Slope and bias scaling,youcanenterthe
See Also
2-D Autocorrelation
2-D Correlation
Video and Image Processing Blockset software
Video and Image Processing Blockset software
2-79
2-D Histogram (Obsolete)
Mean
Median Video and Image Processing Blockset
Standard Deviation
Variance Video and Image Processing Blockset
Histogram
Maximum
Minimum
hist
imhist
Video and Image Processing Blockset software
software
Video and Image Processing Blockset software
software
Signal Processing Blockset software
Signal Processing Blockset software
Signal Processing Blockset software
MATLAB application
Image P roces sing Toolbox software
2-80
Purpose Compute 2-D inverse discrete cosine transform (IDCT)
Library Transforms
viptransforms
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
N
M
1
fxy
(, ) ( ) () ( , )cos
221
=
MN
1
CmCnFmn
n
m
=
=
0
0
xmMy
()
π 112)n
++
2
cos
2-D IDCT
2
(
Port
Input
where F(m,n) is the DCT of the signal f(x,y) and
mn, = 0
Cm Cn(),()= 1
and
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.
Input/Output Supported Data Types
Vector or matrix of intensity values
Double-precision floating
point
Single-precision floating
point
Fixed point
8-, 16-, 32-bit signed integer
8-, 16-, 32-bit un sign ed
integer
Cm Cn(),()=
Complex Valu es Supported
No
1
2
for
2-81
2-D IDCT
Port
Input/Output Supported Data Types
Complex Valu es Supported
Output 2-D IDCT of the input Same as Input port
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 values during the simulation. If you select computes and stores the trigonometric values before the simulation starts. In this case, the block requires extra memory.
Trigonometric fcn, the block computes the sine and cosine
Fixed-Point Data Types
Thefollowingdiagramshowsthedatatypesusedinthe2-DIDCTblock 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.
No
Table lookup,theblock
2-82
2-D IDCT
2-83
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 intheaccumulatordatatype. Fordetails on the com plex multiplication performed, refer to “Multiplication Data Types” in the Signal Processing Blockset documentation. You can set the sine table, product output, accumulator, and output data types in the block mask as discussed in the next section.
2-84
Loading...