Main Content


Implements the blocked image automation algorithm

Since R2021a


    res = blockedImageAutomationAlgorithm(algObj,bstruct) computes labels based on the algorithm you specify in this method. The Image Labeler app invokes this method on each image you choose for blocked image automation in the app. algObj is a vision.labeler.AutomationAlgorithm object. bstruct is a structure. The format of the output, res, depends on the type of automation algorithm specified.


    Sample Blocked Image Algorithm Automation Function

    • Here is an example of a blocked image algorithm automation function.

      function res = blockedImageAutomationAlgorithm(algObj,bstruct)
         % Detect people using aggregate channel features
         detector = peopleDetectorACF('inria-100x41');
         [bboxes, scores] = detect(detector, bstruct.Data,...
                  'SelectStrongest', false);
         % Apply non-maximum suppression to select the strongest bounding boxes.
         [selectedBboxes, selectedScores] = selectStrongestBbox(bboxes, scores,...
                  'RatioType', 'Min',...
                  'OverlapThreshold', 0.65);
         % Consider only detections that meet specified score threshold
         selectedBboxes = selectedBboxes(selectedScores > 0, :);
         selectedBboxes(:,1) = selectedBboxes(:,1)+bstruct.Start(2);
         selectedBboxes(:,2) = selectedBboxes(:,2)+bstruct.Start(1);
         if algObj.SelectedLabelDefinitions.Type == "Rectangle"
            % Add the selected label at the bounding box position(s)
            res = struct(...
                'Type', labelType.Rectangle,...
                'Name', algObj.SelectedLabelDefinitions.Name,...
                'Position', selectedBboxes);

    Input Arguments

    collapse all

    Automation algorithm, specified as a vision.labeler.AutomationAlgorithm object.

    Structure of data passed to the blocked image apply object function, specified as a scalar struct with these fields.

    DataA block of array data from the blocked image.
    StartArray subscripts of the first element in the block. If BorderSize is specified, this subscript can be out-of-bounds for edge blocks.
    EndArray subscripts of the last element in the block. If BorderSize is specified, this subscript can be out-of-bounds for edge blocks.
    BlocksubThe block subscripts of the current block
    BorderSizeThe value of the BorderSize parameter
    BlockSizeThe value of the BlockSize parameter. Note: size(data) can be less than this value for border blocks PadPartialValue is false.
    BatchSizeThe value of the BatchSize parameter

    Output Arguments

    collapse all

    Result of processing, returned as a scalar struct. The format of the structure depends on the type of automation algorithm.

    For automation algorithms without pixel labels, the struct has fields described in this table.

    TypeA labelType enumeration that defines the type of label. Type can have values: Rectangle, Line, Projected cuboid, Cuboid, or Scene.
    NameA character vector specifying a label name that returns true for checkLabelDefinition. Only existing label names previously defined in the Image Labeler app can be used.

    Positions of the labels. The type of label determines the format of the position data.

    Label TypeDescription
    RectangleP-by-1 cell array specifying P Rectangles, each containing a 1-by-4 vector specifying position of the bounding box locations as [x y w h] or multiple Rectangle ROIs specified as an M-by-4 matrix.
    LineP-by-1 cell array specifying P polylines each containing N-by-2 vector specifying N points along each polyline as: [x1,y1; x2,y2;...xN,yN]
    PolygonsP-by-1 cell array specifying P polygons each containing N-by-2 vector specifying N points along each polygon as: [x1,y1; x2,y2;...xN,yN]
    Projected CuboidP-by-1 cell array specifying P projected cuboids each containing 1-by-8 vector specifying position of primary and secondary faces as: [x1 y1 w1 h1 x2 y2 w2 h2] or multiple projected cuboid ROIs can be specified as an M-by-8 matrix.
    AttributesAn array of structs representing the attributes contained by the automated labels. Each attribute is specified as a field of the struct with the name of the field representing the name of the attribute and the value of the field representing the value of the attribute. This is an optional field, only present if the labels defined have attributes.

    For automation algorithms with pixel labels, res is a categorical label matrix, where each category represents a pixel label.


    • For automation algorithms without pixel labels, the Position field in res must be in a world coordinate system. This can be achieved by adding the X and Y indices in the bstruct.Start field to the output of the automation algorithm. To get the correct X coordinate, add bstruct.Start(2) to get the position of the automation output in world coordinates. To get the correct Y coordinate, add bstruct.Start(1) to get the position of the automation output in world coordinates.

    Version History

    Introduced in R2021a