Q:

How can I calculate center of mass after floodfill? 

I have an image like this one 
with 3 distinct regions.  Using a breath first 4 neighbor queue, I have implemented a basic flood fill that distinguishes between the 3. 
Now I need to find the center of mass of these regions with each pixel weighing one unit of weight. 
Whats the best way of going about that? 

A:

The simplest way is to keep three arrays, sumx, sumy and count, each with one entry per label (3 in your case), and all initialized to 0.  Then run through the image once, and for each labeled pixel add the x coordinate to the corresponding bin in sumx, the y coordinate to the corresponding bin in sumy, and 1 to the corresponding bin in count. 
At the end, for each label l you can compute sumx[l]/count[l] and sumy[l]/count[l].  These are the unweighted centers of gravity (centroids).