edge detection and image overlay -凯发k8网页登录
this example shows how to detect and highlight object edges in a video stream. the behavior of the pixel-stream sobel edge detector block, video stream alignment, and overlay, is verified by comparing the results with the same algorithm calculated by the full-frame blocks from the computer vision toolbox™.
this example model provides a hardware-compatible algorithm. you can implement this algorithm on a board using a xilinx® zynq® reference design. see (vision hdl toolbox support package for xilinx zynq-based hardware).
structure of the example
the system is shown below.
the difference in the color of the lines feeding the full-frame behavioral model and pixel-stream hdl model subsystems indicates the change in the image rate on the streaming branch of the model. this rate transition is because the pixel stream is sent out in the same amount of time as the full video frames and therefore it is transmitted at a higher rate.
full-frame behavioral model
the following diagram shows the structure of the full-frame behavioral model subsystem, which employs the frame-based edge detection block.
given that the frame-based edge detection block does not introduce latency, image overlay is performed by weighting the source image and the edge detection output image, and adding them together in a straightforward manner.
one frame of the source video, the edge detection result, and the overlaid image are shown from left to right in the diagram below.
it is a good practice to develop a behavioral system using blocks that process full image frames, the full-frame behavioral model subsystem in this example, before moving forward to working on an fpga-targeting design. such a behavioral model helps verify the video processing design. later on, it can serve as a reference for verifying the implementation of the algorithm targeted to an fpga. specifically, the psnr (peak signal-to-noise ratio) block at the top level of the model compares the results from full-frame processing with those from pixel-stream processing.
frame to pixels: generating a pixel stream
the task of the frame to pixels is to convert a full frame image to pixel stream. to simulate the effect of horizontal and vertical blanking periods found in real life hardware video systems, the active image is augmented with non-image data. for more information on the streaming pixel protocol, see streaming pixel interface (vision hdl toolbox). the frame to pixels block is configured as shown:
the number of components field is set to 1 for grayscale image input, and the video format field is 240p to match that of the video source.
in this example, the active video region corresponds to the 240x320 matrix of the dark image from the upstream corruption block. six other parameters, namely, total pixels per line, total video lines, starting active line, ending active line, front porch, and back porch specify how many non-image data will be augmented on the four sides of the active video. for more information, see the (vision hdl toolbox) block reference page.
note that the sample time of the video source is determined by the product of total pixels per line and total video lines.
pixel-stream edge detection and image overlay
the pixel-stream hdl model subsystem is shown in the diagram below. you can generate hdl code from this subsystem.
due to the nature of pixel-stream processing, unlike the edge detection block in the full-frame behavioral model, the edge detector block from the vision hdl toolbox™ will introduce latency. the latency prevents us from directly weighting and adding two images to obtain the overlaid image. to address this issue, the pixel stream aligner block is used to synchronize the two pixel streams before the sum.
to properly use this block, refpixel and refctrl must be connected to the pixel and control bus that are associated with a delayed pixel stream. in our example, due to the latency introduced by the edge detector, the pixel stream coming out of the edge detection subsystem is delayed with respect to that feeding into it. therefore, the upstream source of refpixel and refctrl are the pixelout and ctrlout signals from the edge detection subsystem.
pixels to frame: converting pixel stream back to full frame
as a companion to frame to pixels that converts a full image frame to pixel stream, the pixels to frame block, reversely, converts the pixel stream back to the full frame by making use of the synchronization signals. since the output of the pixels to frame block is a 2-d matrix of a full image, there is no need to further carry on the bus containing five synchronization signals.
the number of components field and the video format fields of both frame to pixels and pixels to frame are set at 1 and 240p, respectively, to match the format of the video source.
verifying the pixel stream processing design
while building the streaming portion of the design, the psnr block continuously verifies results against the original full-frame design. the delay block on the top level of the model time-aligns the 2-d matrices for a fair comparison. during the course of the simulation, the psnr block should give inf output, indicating that the output image from the full-frame behavioral model matches the image generated from the stream processing pixel-stream hdl model.
exploring the example
the example allows you to experiment with different threshold and alpha values to examine their effect on the quality of the overlaid images. specifically, two workspace variables and with initial values 7 and 0.8, respectively, are created upon opening the model. you can modify their values using the matlab® command line as follows:
thresholdvalue=8 alpha=0.5
the updated will be propagated to the threshold field of the edge detection block inside the full-frame behavioral model and the edge detector block inside pixel-stream hdl model/edge detection. the value will be propagated to the gain1 block in the full-frame behavioral model and pixel-stream hdl model/image overlay, and the value of goes to gain2 blocks. closing the model clears both variables from your workspace.
in this example, the valid range of is between 0 and 256, inclusive. setting equal to or greater than 257 triggers a message parameter overflow occurred for 'threshold'. the higher you set the , the smaller the amount of edges the example finds in the video.
the valid range of is between 0 and 1, inclusive. it determines the weights for edge detection output image and the original source image before adding them. the overlay operation is a linear interpolation according to the following formula.
overlaid image = alpha*source image (1-alpha)*edge image.
therefore, when , the overlaid image is the edge detection output, and when it becomes the source image.
generate hdl code and verify its behavior
to check and generate the hdl code referenced in this example, you must have an hdl coder™ license.
to generate the hdl code, use the following command:
makehdl('edgedetectionandoverlayhdl/pixel-stream hdl model');
to generate a test bench, use the following command:
makehdltb('edgedetectionandoverlayhdl/pixel-stream hdl model');