visionhdl.PixelStreamAligner

Align two streams of pixel data

Description

The visionhdl.PixelStreamAligner System object™ synchronizes two pixel streams by delaying one stream to match the timing of a reference stream. Many Vision HDL Toolbox™ algorithms delay the pixel stream, and the amount of delay can change as you adjust algorithm parameters. You can use this object to align streams for overlaying, comparing, or combining two streams such as in a Gaussian blur operation. Use the delayed stream as the refPixel and refCtrl arguments. Use the earlier stream as the pixelIn and ctrlIn arguments.

This waveform diagram shows the input streams, pixelIn and refPixelIn, and their associated control signals. The reference input frame starts later than the pixelIn frame. The output signals show that the object delays pixelIn to match the reference stream, and that both output streams share control signals. There is a short latency between the input refCtrl and the output refCtrl. In this simulation, to accommodate the delay of four lines between the input streams, the MaxNumberofLines must be set to at least 4.

For details on the pixel control bus and the dimensions of a video frame, see Streaming Pixel Interface.

Construction

align = visionhdl.PixelStreamAligner returns a System object, align, that synchronizes a pixel stream with a reference pixel stream.

Properties

expand all

Choose a power of two that accommodates the number of active pixels in a horizontal line. If you specify a value that is not a power of two, the object uses the next largest power of two. The object implements a circular buffer of 2M, where M is MaxNumberofLines + log2(LineBufferSize) pixels.

The object implements a circular buffer of 2M, where M is MaxNumberofLines + log2(LineBufferSize) pixels, and a line address buffer of MaxNumberofLines locations. The circular memory stores the earlier input lines until the reference control signals arrive. The line address buffer stores the address of the start of each line. When the reference control signals arrive, the object uses the stored address to read and send the delayed line. This parameter must accommodate the difference in timing between the two input streams, including internal latency before the object reads the first line. During simulation, the object warns when an overflow occurs. To avoid the overflow condition, increase MaxNumberofLines. The delay between streams cannot exceed an entire frame.

Methods

stepAlign two streams of pixel data
Common to All System Objects
release

Allow System object property value changes

Examples

collapse all

Overlay a processed video stream on the input stream.

Prepare a test image by selecting a portion of an image file.

frmActivePixels = 64;
frmActiveLines = 48;
frmOrig = imread('rice.png');
frmInput = frmOrig(1:frmActiveLines,1:frmActivePixels);
figure
imshow(frmInput,'InitialMagnification',300)
title 'Input Image'

Create a serializer and specify the size of inactive pixel regions.

frm2pix = visionhdl.FrameToPixels( ...
      'NumComponents',1, ...
      'VideoFormat','custom', ...
      'ActivePixelsPerLine',frmActivePixels, ...
      'ActiveVideoLines',frmActiveLines, ...
      'TotalPixelsPerLine',frmActivePixels+10, ...
      'TotalVideoLines',frmActiveLines+10, ...
      'StartingActiveLine',6, ...
      'FrontPorch',5);

Serialize the test image using the object you created. pixIn is a vector of intensity values. ctrlIn is a vector of control signal structures. Preallocate vectors for the output signals.

[pixIn,ctrlIn] = frm2pix(frmInput);

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
ctrlOut = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
overlayOut = zeros(numPixelsPerFrame,1,'uint8');

Write a function that creates and calls the System objects to detect edges and then align the edge data with the original pixel data. The edge results are delayed by the latency of the EdgeDetector object. The associated control signals become the reference for the aligned stream. You can generate HDL from this function.

function [pixelOut,ctrlOut] = EdgeDetectandOverlay(pixelIn,ctrlIn)
%EdgeDetectandOverlay 
% Detects edges in an input stream, and overlays the edge data onto the 
% original stream. 
% pixelIn, ctrlIn are a scalar pixel and its associated pixelcontrol structure
% You can generate HDL code from this function.

  persistent align
  if isempty(align)
    align = visionhdl.PixelStreamAligner;
  end    
  
  persistent find_edges
  if isempty(find_edges)
    find_edges = visionhdl.EdgeDetector;
  end
  
  [edgeOut,edgeCtrl] = find_edges(pixelIn,ctrlIn);
  [origOut,alignedEdgeOut,ctrlOut] = align(pixelIn,ctrlIn,edgeOut,edgeCtrl);
  if (alignedEdgeOut)
      pixelOut = uint8(0); % set edge pixels to black
  else
      pixelOut = origOut;
  end
end

For each pixel in the frame, call your function to search for edges and align with the input stream.

for p = 1:numPixelsPerFrame
    [overlayOut(p),ctrlOut(p)] = EdgeDetectandOverlay(pixIn(p),ctrlIn(p));
end

Create a deserializer object with a format matching that of the serializer. Convert the pixel stream to an image frame by calling the deserializer object. Display the resulting image.

pix2frm = visionhdl.PixelsToFrame( ...
      'NumComponents',1, ...
      'VideoFormat','custom', ...
      'ActivePixelsPerLine',frmActivePixels, ...
      'ActiveVideoLines',frmActiveLines);
[frmOutput,frmValid] = pix2frm(overlayOut,ctrlOut);
if frmValid
    figure
    imshow(frmOutput, 'InitialMagnification',300)
    title 'Output Image'
end

Introduced in R2017a