how to count frequency of the color?

hi, i want to convert a color image to a greyscale image by counting the frequency of the color (0-255) and put the frequency in an array but im stuck with putting it into the array. can anyone pls help me what do i have to do next? thx in advance.