countEachLabel
(Not recommended) Count number of pixel labels for each class of
bigimageDatastore
object
Since R2020a
The countEachLabel
function of the
bigimageDatastore
object is not recommended. Use the countEachLabel
function associated with the blockedImageDatastore
object instead. For more information, see Compatibility Considerations.
Description
Examples
Input Arguments
Output Arguments
Tips
You can use the label information returned by countEachLabel
to
calculate class weights for class balancing. For example, for labeled pixel data
information in tbl
:
Uniform class balancing weights each class such that each contains a uniform prior probability:
numClasses = height(tbl) prior = 1/numClasses; classWeights = prior./tbl.PixelCount
Inverse frequency balancing weights each class such that underrepresented classes are given higher weight:
totalNumberOfPixels = sum(tbl.PixelCount) frequency = tbl.PixelCount / totalNumberOfPixels; classWeights = 1./frequency
Median frequency balancing weights each class using the median frequency:
imageFreq = tbl.PixelCount ./ tbl.ImagePixelCount classWeights = median(imageFreq) ./ imageFreq
You can pass the calculated class weights to a pixelClassificationLayer
(Computer Vision Toolbox).