Main Content

visionhdl.GrayscaleDilation

Morphologically dilate grayscale pixel stream

Description

The visionhdl.GrayscaleDilation System object™ morphologically dilates a grayscale pixel stream. This operation replaces each pixel with the local maximum of the neighborhood around the pixel. The object operates on a stream of grayscale pixel intensity values.

You can specify a neighborhood, or structuring element, of up to 32-by-32 pixels. For line, square, or rectangle structuring elements that are more than 8 pixels wide, the object uses the Van Herk algorithm to find the maximum. This algorithm uses only three comparators to find the maximums of all the rows and then uses a comparison tree to find the maximum of the row results.

For structuring elements that are less than 8 pixels wide, or that contain zero elements, the object implements a pipelined comparison tree for each row of the neighborhood. An additional comparison tree finds the maximum value of the row results. If the structuring element contains zeros that mask off pixels, the algorithm saves hardware resources by not implementing comparators for those pixel locations.

To morphologically dilate a grayscale pixel stream:

  1. Create the visionhdl.GrayscaleDilation object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

dilator = visionhdl.GrayDilation creates a System object that morphologically dilates a grayscale pixel stream.

dilator = visionhdl.GrayDilation(Name,Value) sets properties using one or more name-value arguments. For example, 'Neighborhood',getnhood(strel('disk',4)) specifies a 4-by-4 disk-pattern neighborhood.

example

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Pixel neighborhood, specified as a vector or matrix of binary values.

The object supports neighborhoods of up to 32-by-32 pixels. To use a structuring element, set the Neighborhood property to getnhood(strel(shape)), where shape is specified by the input arguments to the strel (Image Processing Toolbox) function. The minimum neighborhood size is a 2-by-2 matrix, or a 2-element column vector. If the neighborhood is a row vector, it must be at least 8 columns wide and contain no zeros.

Size of the line memory buffer, specified as a positive integer. 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 buffer uses the next largest power of two.

The object allocates (n – 1)-by-LineBufferSize memory locations to store the pixels, where n is the number of lines in the Neighborhood property value.

Usage

Description

[pixelout,ctrlout] = dilator(pixelin,ctrlin) returns the next grayscale pixel value, pixelout, resulting from morphologically dilating the neighborhood around each input grayscale pixel, pixelin.

example

This object uses a streaming pixel interface with a structure for frame control signals. This interface enables the object to operate independently of image size and format and to connect with other Vision HDL Toolbox™ objects. The object accepts and returns a scalar pixel value and control signals as a structure containing five signals. The control signals indicate the validity of each pixel and its location in the frame. To convert a pixel matrix into a pixel stream and control signals, use the visionhdl.FrameToPixels object. For a description of the interface, see Streaming Pixel Interface.

Input Arguments

expand all

Input pixel, specified as an unsigned integer.

You can simulate System objects with a multipixel streaming interface, but you cannot generate HDL code for System objects that use multipixel streams. To generate HDL code for multipixel algorithms, use the equivalent Simulink® blocks.

The software supports double and single data types for simulation, but not for HDL code generation.

Data Types: single | double | uint8 | uint16 | uint32 | uint64 | fixdt(0,N,0)

Control signals accompanying the input pixel stream, specified as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Output Arguments

expand all

Output pixel that is transformed by a morphological operation, returned as an unsigned integer.

The data type is the same as the data type of pixelin.

Control signals accompanying the output pixel stream, returned as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Load a source image from a file. Select a portion of the image that matches the desired test size.

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

Figure contains an axes object. The hidden axes object with title Input Image contains an object of type image.

Create a serializer System object™ and define the inactive pixel regions. Set the number of inactive pixels following each active line to at least double the horizontal size of the neighborhood. Set the number of lines following each frame to at least double the vertical size of the neighborhood.

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

Create a morphological dilation System object.

dilator = visionhdl.GrayscaleDilation(...
          'Neighborhood',ones(4,4));

Serialize the test image by calling the serializer object. pixin is a vector of intensity values. ctrlin is a vector of control signal structures.

[pixin,ctrlin] = frm2pix(frmInput);

Prepare to process the pixel stream by preallocating output vectors.

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
pixout = uint8(zeros(numPixelsPerFrame,1));
ctrlout = repmat(pixelcontrolstruct,numPixelsPerFrame,1);

For each pixel in the padded frame, compute the morphed value. Monitor the control signals to determine the latency of the object. The latency of a configuration depends on the number of active pixels in a line and the size of the neighborhood.

foundValIn = false;
foundValOut = false;
for p = 1:numPixelsPerFrame  
    if (ctrlin(p).valid && foundValIn==0)
        foundValIn = p;
    end
    [pixout(p),ctrlout(p)] = dilator(pixin(p),ctrlin(p));
    if (ctrlout(p).valid && foundValOut==0)
        foundValOut = p;
    end
end
objLatency_cycles = foundValOut - foundValIn
objLatency_cycles = 
104

Create a deserializer System object with a format that matches the serializer format. 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, ...
      'TotalPixelsPerLine',frmActivePixels+20);
[frmOutput,frmValid] = pix2frm(pixout,ctrlout);
if frmValid
    figure
    imshow(frmOutput,'InitialMagnification',300)
    title 'Output Image'
end

Figure contains an axes object. The hidden axes object with title Output Image contains an object of type image.

Algorithms

This object implements the algorithms described on the Grayscale Dilation block reference page.

Extended Capabilities

Version History

Introduced in R2016a

expand all

See Also

Objects

Blocks

Functions