Find edges of objects in grayscale pixel stream
Vision HDL Toolbox / Analysis & Enhancement
The Edge Detector block finds the edges in a grayscale pixel stream by using the Sobel, Prewitt, or Roberts method. The block convolves the input pixels with derivative approximation matrices to find the gradient of pixel magnitude along two orthogonal directions. It then compares the sum of the squares of the gradients to the square of a configurable threshold to determine if the gradients represent an edge.
By default, the block returns a binary image as a stream of pixel values. A pixel value of 1 indicates that the pixel is an edge. You can disable the edge output. You can also enable output of the gradient values in the two orthogonal directions at each pixel.
This block uses a streaming pixel interface with a
bus for frame control signals. This interface enables the block to operate independently
of image size and format. The pixel, Edge, and
gradient ports on this block support single pixel streaming or multipixel streaming.
Single pixel streaming accepts and returns a single pixel value each clock cycle.
Multipixel streaming accepts and returns a vector of 4 or 8 pixels per clock cycle to
support high-frame-rate or high-resolution formats. Along with the pixel, the block
accepts and returns a pixelcontrol
bus containing five control
signals. The control signals indicate the validity of each pixel and their location in
the frame. For multipixel streaming, one set of control signals applies to all four or
eight pixels in the vector. To convert a frame (pixel matrix) into a serial pixel stream
and control signals, use the Frame To Pixels block. For a full
description of the interface, see Streaming Pixel Interface.
pixel
— Input pixel or multipixel vectorThis block supports single pixel streaming or multipixel streaming. For single pixel streaming, specify a single input pixel as a scalar intensity value. For multipixel streaming, specify a vector of four or eight pixel intensity values. For details of how to set up your model for multipixel streaming, see Filter Multipixel Video Streams.
This block does not support multicomponent streaming. To process multicomponent
streams, replicate the block for each component. The pixelcontrol
bus
for all components is identical, so you can connect a single bus to multiple replicated
blocks.
double
and single
data
types are supported for simulation, but not for HDL code generation.
Data Types: uint8
| uint16
| uint32
| int8
| int16
| int32
| fixed point
| Boolean
| double
| single
ctrl
— Control signals associated with pixel streampixelcontrol
busSpecify a pixelcontrol
bus that contains
five signals. The signals describe the validity of the pixel and its location in the frame. For
more information, see Pixel Control Bus.
For multipixel streaming, each vector of pixel values has one set of control signals.
Because the vector has only one valid
signal, the pixels in the
vector must be either all valid or all invalid. The hStart
and
vStart
signals apply to the pixel with the lowest index in the
vector. The hEnd
and vEnd
signals apply to the
pixel with the highest index in the vector.
Data Types: bus
Th
— Threshold valueThreshold value that defines an edge, specified as a scalar. The block compares the square of this value to the sum of the squares of the gradients.
double
and single
data
types are supported for simulation, but not for HDL code generation.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fixed point
Edge
— Boolean pixel value, indicating whether pixel is an edgeFor single pixel streaming, Edge is a Boolean scalar. For multipixel streaming, Edge is a vector of NumberOfPixels-by-1 Boolean values. NumberOfPixels can be four or eight. Each pixel value indicates whether the pixel is an edge.
Data Types: Boolean
Gv,Gh
— Vertical and horizontal gradientVertical and horizontal gradient values calculated over the kernel centered at a pixel location.
For single pixel streaming, the block returns Gv and Gh as scalar values. For multipixel streaming, the block returns Gv and Gh as vectors of NumberOfPixels-by-1 values. NumberOfPixels can be four or eight.
double
and single
data
types are supported for simulation, but not for HDL code generation.
These ports are visible when you set Method
to Sobel
or
Prewitt
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fixed point
G45,G135
— Orthogonal gradient Orthogonal gradient values calculated over the kernel centered at a pixel location.
For single pixel streaming, the block returns G45 and G135 as scalar values. For multipixel streaming, the block returns G45 and G135 as vectors of NumberOfPixels-by-1 values. NumberOfPixels can be four or eight.
double
and single
data
types are supported for simulation, but not for HDL code generation.
These ports are visible when you set Method
to Roberts
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fixed point
ctrl
— Control signals associated with pixel streampixelcontrol
busSpecify a pixelcontrol
bus that contains
five signals. The signals describe the validity of the pixel and its location in the frame. For
more information, see Pixel Control Bus.
For multipixel streaming, each vector of pixel values has one set of control signals.
Because the vector has only one valid
signal, the pixels in the
vector are either all valid or all invalid. The hStart
and
vStart
signals apply to the pixel with the lowest index in the
vector. The hEnd
and vEnd
signals apply to the
pixel with the highest index in the vector.
Data Types: bus
Method
— Edge detection algorithmSobel
(default) | Prewitt
| Roberts
When you select Sobel
or
Prewitt
, the block calculates horizontal
and vertical gradients, Gv
and Gh
.
When you select Roberts
, the block calculates
orthogonal gradients, G45
and
G135
. For details of each method, see Algorithms.
Note
If you select Prewitt
, the
full-precision internal data type is large due to the 1/6
coefficient. Consider selecting Output the gradient
components, so that you can customize the data
type to a smaller size.
Output the binary image
— Enable edge output portWhen this parameter is selected, the block returns a stream of binary pixels representing the edges detected in the input frame.
You must select at least one of Output the binary image and Output the gradient components.
Output the gradient components
— Enable gradient output portsWhen this parameter is selected, the block returns a stream of values
representing the gradients calculated in the two orthogonal directions
at each pixel. When you set Method to
Sobel
or
Prewitt
, the output ports
Gv and Gh appear on the
block. When you set Method to
Roberts
, the output ports
G45 and G135 appear on the
block.
You must select at least one of Output the binary image and Output the gradient components.
Source of threshold value
— Source for gradient threshold that indicates an edgeProperty
(default) | Input port
You can set the threshold from an input port or from the dialog box.
The default value is Property
. Selecting
Input port
enables the
Th port.
Threshold value
— Gradient threshold value that indicates an edge20
(default) | scalarThe block compares the square of this value to the sum of the squares of the gradients. The block casts this value to the data type of the gradients.
This option is visible when you set Source of threshold
value to Property
.
Line buffer size
— Size of the line memory buffer2048
(default) | integerSpecify a power of two that accommodates the number of active pixels in a single horizontal line.
If you specify a value that is not a power of two, the block uses the
next largest power of two. The block allocates (N –
1)-by-Line buffer size memory
locations to store the pixels, where N is the number
of lines in the differential approximation matrix. If you set
Method to Sobel
or
Prewitt
, then N is 3.
If you set Method to
Roberts
, then N is
2.
Padding method
— Method for paddingSymmetric
(default) | None
Select one of these methods for padding the boundary of the input image. For more information about these methods, see Edge Padding.
Symmetric
— Set the value of
the padding pixels to mirror the edge of the image. This
option prevents edges from being detected at the boundaries
of the active frame.
None
— Exclude padding logic. The block does not set the pixels
outside the image frame to any particular value. This option reduces the hardware resources
used by the block and the blanking required between frames but affects the accuracy of the
output pixels at the edges of the frame. To maintain pixel stream timing, the output frame
is the same size as the input frame. However, to avoid using pixels calculated from
undefined padding values, mask off the KernelSize/2 pixels around the
edge of the frame for downstream operations. For details, see Increase Throughput with Padding None.
Rounding mode
— Rounding method for internal fixed-point calculationsFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Zero
Specify a rounding method for internal fixed-point calculations.
Saturate on integer overflow
— Overflow action for internal fixed-point calculationsoff
(default) | on
When you clear this parameter, fixed-point and integer values wrap around to zero when the value overflows what is representable with that data type. When you select this parameter, the value saturates at the maximum representable value.
Gradient Data Type
— Data type for gradient output portsInherit via internal rule
(default) | data type expressionData type for the two gradient output ports. By default, the block automatically chooses full-precision data types.
To enable this parameter, on the Main tab, select Output the gradient components.
The Edge Detector block provides three methods for detecting edges in an input image. The methods use different derivative approximation matrices to find two orthogonal gradients. The Sobel and Prewitt methods calculate the gradient in horizontal and vertical directions. The Roberts method calculates the gradients at 45 degrees and 135 degrees. The block uses the same matrices as the Edge Detection block in Computer Vision Toolbox™.
When you use multipixel streaming, the block uses a single line memory and implements NumberOfPixels filters in parallel. This increase in hardware resources is a trade off for increasing throughput compared to single-pixel streaming.
Method | Direction 1 | Direction 2 |
---|---|---|
Sobel | ||
Prewitt | ||
Roberts |
Note
The Prewitt coefficients require extra bits of precision because they are not powers of two. The block uses 16 bits to represent the Prewitt coefficients. For 8-bit input, the default size of the full-precision gradients is 27 bits. When using the Prewitt method, a good practice is to reduce the word length used for the gradient calculation. Select the Output the gradient components check box, and then on the Data Types tab, specify a smaller word length using Gradient Data Type.
The block convolves the neighborhood of the input pixel with the derivative matrices, D1 and D2. It then compares the sum of the squares of the gradients to the square of the threshold. Computing the square of the threshold avoids constructing a square root circuit. The block casts the gradients to the type you specified on the Data Types tab. The type conversion on the square of the threshold matches the type of the sum of the squares of the gradients.
The latency of the block is the line buffer latency plus the
latency of the kernel calculation. The line buffer latency includes edge padding by default. The
latency of the padding operation depends on the size of the kernel. If edge padding is not
necessary for your design, you can reduce the latency by setting the Padding
method parameter to None
. When you use this option, the block
latency does not depend on your kernel size. To determine the exact latency for any
configuration of the block, measure the number of time steps between the input and output
control signals.
Note
When you use edge padding, use a horizontal blanking interval greater than twice the kernel width. This interval lets the block finish processing one line before it starts processing the next one, including adding padding pixels before and after the active pixels in the line. Standard streaming video formats use a horizontal blanking interval of about 25% of the frame width. This interval is much larger than the filters applied to each frame. When you disable edge padding, the horizontal blanking interval must be at least 12 cycles and is independent of the kernel size. If you are using a custom video format, set the horizontal blanking interval by using the Frame To Pixels block parameters. The horizontal blanking interval is equal to Total pixels per line – Active pixels per line or, equivalently, Front porch + Back porch. For more information, see Configure Blanking Intervals.
This block supports C/C++ code generation for Simulink® accelerator and rapid accelerator modes and for DPI component generation.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
This block has a single, default HDL architecture.
ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is
|
InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
You cannot generate HDL for this block inside a Resettable Synchronous Subsystem (HDL Coder).