I would use the Python Image Library. This is a piece of code that computes the number of white pixels/non-white pixels in an image.
import sys
from PIL import Image
im = Image.open(sys.argv[1])
white = 0
black = 0
for i in im.getdata():
if i == (255,255,255):
white += 1
else:
# we assume black everything that is not white:
black += 1
print im.size[0],im.size[1],white,black
In your case, I would do a dictionary to keep every rgb triple against a counter, so I would rework the program like this (not tested)
import sys
from PIL import Image
im = Image.open(sys.argv[1])
count= {}
for i in im.getdata():
if not count.has_key(i):
count[i] = 0
count[i] += 1
You can now check the one with the highest count and get the most used rgb triple. Of course, if you want to check also vicinal colors, you will have to convert to HSV and check the distances between different HSV points, then decide which distance is too much. Points sufficiently near in HSV space (and in particular the hue component) are most likely the same color and consequently can be summed together.