countEachLabel
Description
specifies additional name-value arguments.counts
= countEachLabel(___,Name,Value
)
If bimds
contains categorical data,
countEachLabel
obtains the class names from the categories specified
in the InitialValue
property of the first blocked image. In this case, do
not specify the Classes
and PixelLabelIDs
name-value arguments. If bimds
contains numeric data, you must provide
values for the Classes
and PixelLabelIDs
name-value arguments.
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. The weight for each class
c
is defined asmedian(imageFreq)/imageBlockFreq(c)
, whereimageBlockFreq(c)
is the number of pixels of a given class divided by the total number of pixels in image blocks that had an instance of the given classc
.imageBlockFreq = tbl.PixelCount ./ tbl.BlockPixelCount classWeights = median(imageBlockFreq) ./ imageBlockFreq
Version History
Introduced in R2021a