给出需要二值化的参数,比如灰度,带入Weight
参考文章
https://www.cnblogs.com/kensporger/p/11270452.html
w1 := 0
k := 0
thresIndex := 0
maxVariance := 0
*
tuple_sort_index (Weight, Indices)
tuple_histo_range (int(Weight[Indices]), 0, 255, 256, SortedHisto, BinSize)
Normalized := SortedHisto / real(sum(SortedHisto))
u0 := sum(SortedHisto * [0 : 1 : 255]) / real(|Weight|)
for I := 0 to 255 by 1
w1 := w1 + Normalized[I]
k := k + I * Normalized[I]
if ((w1 == 0) or (w1 == 1))
continue
endif
u1 := k / w1
grayDiff := u1 - u0
variance := w1 / (1 - w1) * grayDiff * grayDiff
if (variance > maxVariance)
maxVariance := variance
thresIndex := thresIndex + SortedHisto[I]
endif
endfor
return ()