Label Pixels for Semantic Segmentation

The Image Labeler, Video Labeler, and Ground Truth Labeler (requires Automated Driving Toolbox™) apps enable you to assign pixel labels manually. Each pixel can have at most one pixel label. The labels are used to create ground truth data for training semantic segmentation algorithms.

Start Pixel Labeling

Begin by loading an image, video, or image sequence into a labeling app and defining pixel ROI labels. For more details, see:

This example shows pixel labeling with the Image Labeler. You use the same tools to label videos and image sequences with the Video Labeler or Ground Truth Labeler.

Select a pixel label definition from the ROI Label Definition pane. A Label Pixels tab opens, containing tools to label pixels manually using polygons, brushes, or flood fill. You can use the labeling tools in any order. This tab also has controls to adjust the display of the image by zooming and panning and to adjust the opacity of the labels.

This example uses two general strategies to label pixels in the highway image:

  • First use the semi-automated tools, such as Flood Fill and Smart Polygon. Then, refine the labels using tools that offer more direct control, such as Polygon, Assisted Freehand and Brush.

  • First label distant objects with a rough estimation of object borders. Then, label nearer objects with more precise object borders.

Label Pixels Using Flood Fill Tool

The Flood Fill tool labels a group of connected pixels that have a similar color. In this image, the sky is a good candidate for flood fill because the boundary of the bright sky is clear against the dark vegetation and overpass. In contrast, flood fill cannot isolate the vegetation because the color of the vegetation is too similar to the adjacent barriers, roads, and vehicles.

To label pixels using Flood Fill:

  1. Select the tool and a label. The pointer changes to a paint can .

  2. Click a starting pixel in the image.

You can undo the flood fill, or any other labeling operation, by pressing Ctrl+Z.

Label Pixels Using Smart Polygon Tool

The Smart Polygon tool estimates the shape of an object of interest within a polygon that you draw. The tool is useful when the shape of the object is not a simple polygon. This example uses Smart Polygon to label the vegetation, which has a complicated boundary with the sky.

To label pixels using Smart Polygon:

  1. Select the tool and a label. The pointer changes to a crosshair .

  2. Click to add polygon vertices. Completely surround the object of interest, with some space between the object and the polygon.

  3. Close the polygon by clicking the first vertex after placing the other vertices. Alternatively, you can double-click to add the last vertex and close the polygon in one step.

    After you close the polygon, the tool draws an initial label.

  4. Adjust the shape and position of the polygon. When the object of interest extends to the edge of the image, drag vertices to the edge of the image to ensure that the smart polygon completely encloses the object. For instance, this example shows the two leftmost vertices placed at the left edge of the image.

    Smart Polygon Actions

    Move vertexClick and drag the vertex.
    Add vertex

    • Right-click the polygon boundary at the position of the new vertex, and select Add Point.

    • Double-click the point on the boundary.

    Delete vertexRight-click the vertex and select Delete Vertex.
    Move polygonClick and drag any point on the polygon boundary (excluding vertices).
    Delete polygonRight-click the polygon boundary and select Delete Polygon.

  5. Use the Smart Polygon Editor tools to refine the label.

    • Select Mark Foreground to mark areas inside the region that you want to label. Foreground marks appear in green.

    • Select Mark Background to mark areas inside the region that you do not want to label. Background marks appear in red.

    • Select Erase Marks to remove foreground or background marks that are no longer needed.

    • See Tips for additional suggestions on using the Smart Polygon tool.

  6. To finalize the label, press Enter or select a new ROI Label Definition. You can no longer edit the polygon vertices or mark foreground and background regions.

Label Pixels Using Polygon Tool

The Polygon tool labels all pixels within a polygon that you draw. The controls for defining and adjusting the vertices of a polygon are similar to the controls of the Smart Polygon tool.

Add additional polygons over structures such as barriers and the road. Many vehicle pixels are incorrectly labeled. The next step shows how to replace the erroneous labels with the correct label.

Label Pixels Using Assisted Freehand Tool

The Assisted Freehand tool enables you to draw an ROI that automatically follows the edge of the subject in the underlying image. You can also adjust the size and position of the ROI by using your mouse.

Replace Pixel Labels

Each pixel can have at most one pixel label. When you apply a label to a pixel, the new label replaces the previous label.

This example uses the Smart Polygon tool to label pixels belonging to the truck. Foreground marks assign the vehicle label to subregions. Background marks revert subregions to their prior label. For instance, in the first pair of images, background marks revert subregions to the sky and vegetation labels. Similarly, in the second pair of images, background marks revert subregions to the road label.

The border of the truck is jagged because Smart Polygon labels entire subregions, not individual pixels. The next step shows how to refine the labels along the border of the truck.

Refine Labels Using Brush Tool

The Brush tool labels pixels when you draw over the image with the mouse. This example uses Brush to remove spurs from the road and to make the edges of the truck smoother.

To label pixels using Brush:

  1. Select the tool and a label. The pointer changes to a pen , and a square appears to indicate the size of the brush.

  2. Adjust the size of the brush by using the Brush Size slider.

  3. Click and drag the mouse to label pixels.

The Erase tool removes pixel labels when you draw over the image with the mouse.

Visualize Pixel Labels

You can modify the view of the image to facilitate pixel labeling. The Zoom In, Zoom Out, and Pan options enable you to zoom and pan the image with the mouse. To resume pixel labeling, click the Label icon.

The Label Opacity slider adjusts the opacity of all pixel labels.

  • Decrease the opacity to see the image more clearly. For instance, decrease the opacity to make it easier to find the border between the bottom of the car and the road.

  • Increase the opacity to see the segmentation more clearly. For instance, increase the opacity to see that edge along the front bumper of the car should be smoothed. Also, observe that the barrier and some distant vehicles have unlabeled pixels.

This is the final pixel-labeled image.


  • The Smart Polygon tool identifies an object of interest by using regional graph-based segmentation ("GrabCut") [1]. The Smart Polygon tool divides the image into subregions. The tool treats all subregions that are fully or partially outside the polygon as belonging to the background. Therefore, to get an optimal segmentation, make sure the object to be labeled is fully contained within the polygon, surrounded by a few background pixels.

    All pixels within a subregion have the same label. Marking pixels outside the polygon has no effect on the label.

  • To delete the most recently labeled ROI, press Ctrl+Z.


  • Pixel labeling is disabled when you pan and zoom the image. You must click the Label button to resume pixel labeling.

  • To ensure that all pixels in an image are labeled, begin by labeling the entire image with a single label. Pick a label that represents a predominant ROI in the image, such as sky, road, or background. Then, use the labeling tools to relabel objects with their correct label.

  • To fill all or all remaining pixels, select an ROI label from your list and press Shift+Click (you can use left- or right-click).


[1] Rother, C., V. Kolmogorov, and A. Blake. "GrabCut - Interactive Foreground Extraction using Iterated Graph Cuts". ACM Transactions on Graphics (SIGGRAPH). Vol. 23, Number 3, 2004, pp. 309–314.

See Also

| |

Related Topics