balancePixelLabels
Balance pixel labels by oversampling block locations in large images
Since R2020a
Syntax
Description
creates a list of block locations in the large labeled images,
blockLocations
= balancePixelLabels(blockedImages
,blockSize
,numObservations
)blockedImages
, that result in a class balanced data set by
oversampling image regions that contain less-common labels.
numObservations
is the required number of block locations, and
blockSize
specifies the block size.
A balanced dataset can produce better results when used for training workflows such as semantic segmentation in deep learning.
specifies additional aspects of the selected blocks using name-value arguments.blockLocations
= balancePixelLabels(blockedImages
,blockSize
,numObservations
,Name,Value
)
Examples
Input Arguments
Output Arguments
Algorithms
To balance pixel labels, the function oversamples the minority classes in the input images. The minority class is determined by calculating the overall pixel label counts for the complete dataset. The algorithm follows these steps.
The images in the input image array are divided into macro blocks, which is a multiple of the
blockSize
input value.The function counts pixel labels for all classes in each macro block. Then, it selects the macro block with the greatest occurrences of minority classes using weighted random selection.
The algorithm uses a random block location within the selected macro block to perform oversampling. The origin of the block location must always be fully within the limits of the macro block.
The function updates the overall label counts based on the pixel label counts of the classes found for the selected macro block.
The function includes the new (oversampled) classes to compute new minority class.
This process repeats until the number of block locations processed equals the value specified by the
numObservations
input value.