Label Images for Classification Model Training


The Training Image Labeler provides an easy way to label positive samples that the trainCascadeObjectDetector function uses to create a cascade classifier. Using this app, you can:

  • Interactively specify rectangular regions of interest (ROIs).

  • Using the ROIs, you can detect objects of interest in target images with the vision.CascadeObjectDetector System object.

  • You can load multiple images at one time, draw ROIs, and then export the ROI information in the appropriate format for the trainCascadeObjectDetector. The labeler app supports all image data formats that the trainCascadeObjectDetector function uses.

Open the Training Image Labeler

  • MATLAB® Toolstrip: Open the Apps tab, under Image Processing and Computer Vision, click the app icon.

  • MATLAB command prompt: Enter trainingImageLabeler

App Controls

You can add an unlimited number of images to the Data Browser. You can then select, remove, and create ROIs, and save your session. When you are done, you can export the ROI information to an XML file.

Add Images

Use the Add Images icon to select and add images to the Data Browser. You can add more images at any time during your editing session. The source images remain in the folder where they were originally located. The app does not make copies of the original images or move them. If you rotate the images in the Data Browser, the app overwrites the images in their original location with the modified orientation.

The app provides a list of image thumbnails that you loaded for the session. Next to each thumbnail, you see the file name and number of ROIs created in that image.

Specify Regions of Interest

After you load images, you can delineate ROIs. You can switch between images and continue creating ROIs. Drag the cursor over the object in the image that you want to identify for an ROI. You can modify the size of an ROI by clicking either the corner or side grips. To copy and paste an ROI, left-click within it's border to select it. You can select one or more ROIs to move or to copy and paste. To delete an ROI, click the red x-box, , in the upper-right corner.

You can also use the following shortcuts:

  • Control-C to copy

  • Control-V to paste

  • Control-X to cut

  • Shift key + drag corner to keep aspect ratio of ROI

Remove, Rotate, and Sort Images

You can remove, rotate, or sort the images. Right-click any image to access these options. To select multiple images, press Ctrl+click. To select consecutive images, press Shift+click. To sort images by the number of ROIs, from least amount of ROIs contained in each image, right-click any image and select Sort list by number of ROIs.

New Session

When you start a new session, you can save the current session before clearing it.

Open Session

You can open a new session to replace or add to the current session. The app loads the selected .MAT session file. To replace your current session, from the Open Session options, select Open an existing session. To combine multiple sessions, select Add session to the current session.

Save Session

You can name and save your session to a .MAT file. The default name is LabelingSession. The saved session file contains all the required information to reload the session in the state that you saved it. It contains the paths to the original images, the coordinates for the ROI bounding boxes for each image, file names, and logical information to record the state of the files.

Export ROIs

When you click the Export ROIs button, the app exports the ROI information to the MATLAB workspace in a 1-by-M structure, where M represents the number of images. The structure contains two fields. One field stores the image file location and the other field stores the corresponding ROI information for each image. You are prompted to name the variable or to accept the default positiveInstances name. The first field, imageFileName, contains the full path and file name of the images. The app does not copy and resave images, so the stored path refers to the original image and folder that you loaded the images from. The second field, objectBoundingBoxes, contains the ROI [x, y, width, height] information.


 Train a Five-Stage Stop-Sign Detector

See Also

| | | |

More About

External Websites

Was this topic helpful?