# K-means Cluster: Between-cluster variation = Total variation - within-cluster variation proof?

I'm trying to reduce down the RHS of the below equation to be equal to the LHS

$$\sum_{j=1}^{K}t_j(\mu_j-\mu_T)^2=\sum^t_{i=1}(x_i-\mu_T)^2-\sum^K_{j=1}\sum^t_{i=1}w_{ij}(x_i-\mu_j)^2$$

$$K$$ = predefined number of clusters
$$C_j$$ = is a cluster
$$t$$ = Assume that an $$m\times n$$ gray image of pixel intensities has been flattened into a $$m\times n =t$$ vector
$$w_{ij}$$ = identity function where 1 if $$x_i\in C_j$$ and 0 otherwise
$$\mu_j$$= mean intensity cluster $$j$$
$$\mu_T$$= mean intensity of all pixels
$$t_j$$ = # of elements in cluster $$C_j$$

I'm having trouble deriving this

Just expand the brackets:

$$\sum_{j=1}^K t_j \left( \mu_j^2 + \mu_T^2 - 2 \mu_j \mu_T \right) = \sum_{i=1}^t \left(x_i^2 + \mu_T^2 - 2 x_i \mu_T\right) - \sum_{j=1}^K \sum_{i=1}^t w_{i j} \left( x_i^2 + \mu_j^2 - 2 x_i \mu_j \right)$$

Now use the following manipulations of terms in the sums: $$\sum_{j=1}^K \sum_{i=1}^t w_{i j} x_i^2 = \sum_{i=1}^t x_i^2,$$

$$\sum_{j=1}^K \sum_{i=1}^t w_{i j} x_i \mu_j = \sum_{j=1}^K \mu_j \sum_{i=1}^t w_{i j} x_i = \sum_{j=1}^K t_j \mu_j^2,$$

$$\sum_{i=1}^t x_i \mu_T = t \mu_T^2,$$

$$\sum_{j=1}^K t_j \mu_j \mu_T = t \mu_T^2.$$

Plug them into the expanded equation.