Perform 2-D FIR filtering on input matrix
Filtering
visionfilter
The 2-D Finite Impulse Response (FIR) filter block filters the input matrixI
using the coefficient matrixH
or the coefficient vectorsHH
andHV
.
Port | Input/Output | Supported Data Types | Complex Values Supported |
---|---|---|---|
I |
Vector or matrix of intensity values |
|
Yes |
H |
Matrix of filter coefficients |
Same as I port. |
Yes |
HH |
Vector of filter coefficients |
Same as I port. The input to ports HH and HV must be the same data type. |
Yes |
HV |
Vector of filter coefficients |
Same as I port. The input to ports HH and HV must be the same data type. |
Yes |
PVal |
Scalar value that represents the constant pad value |
Input must have the same data type as the input to I port. |
Yes |
Output |
Scalar, vector, or matrix of filtered values |
Same as I port. |
Yes |
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 theSeparable filter coefficientscheck 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 isM-by-Nand your filter coefficient matrix is x-by-y. For a nonseparable filter with theOutput sizeparameter set toSame as input port I
, it would take
multiply-accumulate (MAC) operations for the block to calculate the output. For a separable filter, it would only take
MAC operations. If you do not know whether or not your filter coefficients are separable, use theisfilterseparable
function.
Here is an example of the function syntax,[S, HCOL, HROW] = isfilterseparable(H)
. Theisfilterseparable
function takes the filter kernel,H
, and returnsS
,HCOL
andHROW
. 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, andHROW
is a vector of horizontal filter coefficients.
Use theCoefficient sourceparameter to specify how to define your filter coefficients. If you select theSeparable filter coefficientscheck box and then select aCoefficient sourceofSpecify via dialog
,Vertical coefficients (across height)andHorizontal 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 variablesHCOL
andHROW
,output of theisfilterseparable
function, for these parameters. If you select theSeparable filter coefficientscheck box and then select aCoefficient sourceofInput port
, ports HV and HH appear on the block. Use these ports to specify vectors of vertical and horizontal filter coefficients.
If you clear theSeparable filter coefficientscheck box and select aCoefficient sourceofSpecify via dialog
,Coefficientsparameter appears in the dialog box. Use this parameter to enter your matrix of filter coefficients.
If you clear theSeparable filter coefficientscheck box and select aCoefficient sourceofInput port
, portHappears 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. TheOutput sizeparameter and the sizes of the inputs at portsIandHdictate 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 sizeofFull
,output has dimensions (Mi+Mh-1,Ni+Nh-1). If you select anOutput sizeofSame as input port I
,output has the same dimensions as the input at port I. If you select anOutput sizeofValid
,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, ifall(size(I)
Use thePadding optionsparameter to specify how to pad the boundary of your input matrix. To pad your matrix with a constant value, selectConstant
. To pad your input matrix by repeating its border values, selectReplicate
. To pad your input matrix with its mirror image, selectSymmetric
. To pad your input matrix using a circular repetition of its elements, selectCircular
. For more information on padding, see theImage Padblock reference page.
If, for thePadding optionsparameter, you selectConstant
,Pad value sourceparameter appears in the dialog box. If you selectSpecify via dialog
,Pad valueparameter appears in the dialog box. Use this parameter to enter the constant value with which to pad your matrix. If you selectPad value sourceofInput port
,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.
Use theFiltering based onparameter to specify the algorithm by which the block filters the input matrix. If you selectConvolution
and set theOutput sizeparameter toFull
,block filters your input using the following algorithm
where
and
. If you selectCorrelation
and set theOutput sizeparameter toFull
,block filters your input using the following algorithm
where and .
Theimfilter
function from the Image Processing Toolbox™ product similarly performs N-D filtering of multidimensional images.
The following diagram shows the data types used in the 2-D FIR Filter block for fixed-point signals.
You can set the coefficient, product output, accumulator, and output data types in the block mask as discussed inParameters.
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 toMultiplication Data Types.
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.
Specify how to define your filter coefficients. SelectSpecify via dialog
to enter your coefficients in the block parameters dialog box. SelectInput port
to specify your filter coefficient matrix using port H or ports HH and HV.
Enter your real or complex-valued filter coefficient matrix. This parameter appears if you clear theSeparable filter coefficientscheck box and then select aCoefficient sourceofSpecify via dialog
. Tunable.
Enter the vector of vertical filter coefficients for your separable filter. This parameter appears if you select theSeparable filter coefficientscheck box and then select aCoefficient sourceofSpecify via dialog
.
Enter the vector of horizontal filter coefficients for your separable filter. This parameter appears if you select theSeparable filter coefficientscheck box and then select aCoefficient sourceofSpecify via dialog
.
This parameter controls the size of the filtered output. If you chooseFull
,output has dimensions (Ma+Mh-1,Na+Nh-1). If you chooseSame as input port I
,output has the same dimensions as the input at port I If you chooseValid
, output has dimensions (Ma-Mh+1,Na-Nh+1).
Specify how to pad the boundary of your input matrix. SelectConstant
to pad your matrix with a constant value. SelectReplicate
to pad your input matrix by repeating its border values. SelectSymmetric
to pad your input matrix with its mirror image. SelectCircular
to pad your input matrix using a circular repetition of its elements. This parameter appears if you select anOutput sizeofFull
orSame as input port I
.
Use this parameter to specify how to define your constant boundary value. SelectSpecify via dialog
to enter your value in the block parameters dialog box. SelectInput port
to specify your constant value using the PVal port. This parameter appears if you select aPadding optionsofConstant
.
Enter the constant value with which to pad your matrix. This parameter is visible if, for thePad value sourceparameter, you selectSpecify 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.
Specify the algorithm by which the block filters the input matrix. You can selectConvolution
orCorrelation
.
Select theRounding Modes为定点操作。
Select the overflow mode for fixed-point operations. SeePrecision and Range.
Choose how to specify the word length and the fraction length of the filter coefficients.
When you selectInherit: Same word length as input
,word 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 selectfixdt(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 selectfixdt(1,16,0)
, you can enter the word length and the fraction length of the coefficients, in bits.
When you select, you can enter the data type expression.
The filter coefficients do not obey theRounding modeand theSaturate on integer overflowparameters; instead, they are always saturated and rounded toNearest
.
Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set theProduct output data typeparameter.
SeeSpecify Data Types Using Data Type Assistant(Simulink)for more information.
Use this parameter to specify how to designate the product output word and fraction lengths. Refer toFixed-Point Data TypesandMultiplication Data Typesfor illustrations depicting the use of the product output data type in this block:
When you selectInherit: Same as input
,se characteristics match those of the input to the block.
When you selectfixdt([],16,0)
, you can enter the word length and the fraction length of the product output, in bits.
When you select, you can enter the data type expression.
If you set theCoefficient source(on theMaintab) toInput port
根据产品的输出将继承其标志to the inputs. If either or both inputI1andI2are 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 theShow data type assistantbuttonto display theData Type Assistant, which helps you set theProduct output data typeparameter.
SeeSpecify Data Types Using Data Type Assistant(Simulink)for more information.
Use this parameter to specify how to designate the accumulator word and fraction lengths. Refer toFixed-Point Data TypesandMultiplication Data Typesfor 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 selectInherit: Same as input
,se characteristics match those of the input to the block.
When you selectInherit: Same as product output
,se characteristics match those of the product output.
When you selectfixdt([],16,0)
, you can enter the word length and the fraction length of the accumulator, in bits.
When you selectSlope and bias scaling
, you can enter the word length, in bits, and the slope of the accumulator. All signals in the Computer Vision Toolbox™ software have a bias of 0.
Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set theProduct output data typeparameter.
SeeSpecify Data Types Using Data Type Assistant(Simulink)for more information.
Choose how to specify the word length and fraction length of the output of the block:
When you selectInherit: Same as input
,se characteristics match those of the input to the block.
When you selectfixdt([],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 toAuto
,Signed
orUnsigned
.
When you select, you can enter the a data type expression.
Click theShow data type assistantbuttonto display theData Type Assistant, which helps you set theProduct output data typeparameter.
SeeSpecify Data Types Using Data Type Assistant(Simulink)for more information.
Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block mask. For more information, seefxptdlg
(Fixed-Point Designer), a reference page on the Fixed-Point Tool in the Simulink®documentation.
Image Processing Toolbox |