Reputation: 355
Otsu's method performs binary image thresholding and consists of maximising the variance between the two subclasses (foreground/background) created by splitting the image at a given threshold. Mathematically, this is expressed as:
variance12 = weight1 * (mean1 - meanT)**2 + weight2 * (mean2 - meanT)**2
(meanT is the overal mean of the image histogram). However, I'm having trouble with understanding how this is implemented in the threshold_otsu
function in scikit-image
which writes this as:
variance12 = weight1 * weight2 * (mean1 - mean2)**2
.
Though the definitions of the weights and means are slightly different in this function, I can't see how these two formulations are the same - even though they give the same answers. Would someone care to clarify?
Thank you for your help.
Upvotes: 1
Views: 343
Reputation: 636
You can prove the two formulations are the same by using the definitions of the weights and meanT.
meanT = weight1*mean1 + weight2*mean2 (1)
weight1 + weight2 = 1 (2)
If you insert (1) into your first formula, you end up with something like this
[(mean1-mean2)**2]*[weight1*weight2**2] + [(mean1-mean2)**2]*[weight2*weight1**2]
If you factor that and use (2), you'll get your result.
The complete proof is below, and the definitions can be checked in Otsu's original paper here.
Upvotes: 3