Source: https://blogs.mathworks.com/steve/2008/01/31/counting-occurrences-of-image-colors/
Timestamp: 2019-04-19 08:48:48+00:00

Document:
Blog reader André recently asked me how to count the number of times each color appears in an image. One short solution involves optional output arguments from the function unique, as well as the relatively new function accumarray.
So what do m and n mean? Well, m tells you where you can find the unique values in the original vector. Specifically, m(1) is the index of the last occurrence of the value u(1) in the original vector v. Similarly, m(3) is the index of the last occurrent of the value u(3) in v.
The output argument n gives you indices you can use to reconstruct the original vector from the vector of unique values. In orders, v equals u(n).
A = accumarray(subs, val) creates an array A by accumulating elements of the vector val using the subscript in subs.
Passing n as subs and 1 as val to accumarray gives us a way to count how many times each value of n appears.
counts(1) is the number of times that the value u(1) appears in v. counts(2) is the number of times that the value u(2) appears in v, and so on.
The value 1 appears 2 times in v.
The value 2 appears 3 times in v.
The value 3 appears 2 times in v.
The value 5 appears 2 times in v.
So unique and accumarray help to count the number of occurrences of scalars. How do we adapt this technique to count colors? Specifically, how do we count how many times each unique color occurs in a M-by-N-by-3 truecolor image?
First, we reshape the image so that the columns correspond to three color channels.
Then we use our procedure above with unique and accumarray, except that the we add the 'rows' option to unique.
There are 99059 unique colors in the image.
Finally, let's find out what color occurs most frequently.
The color [254 254 254] occurs 344 times.
And where does this common color occur?
Taking this a step further how could you get matlab to count and display not just the maximum occurring color but the top three color occurrences and their locations? Thank you very much for your time.
Austin—Sort the color_counts vector. Use the second output from sort, the permutation index, to re-order the the colors in the unique_colors matrix. Pick off the first three rows.
I'am a student and this is very intersting to a project that iám working but i have a question this works in MATLAB without the Image Processing Toolbox?
Gustavo—All the functions used in this post except for imshow are in MATLAB.
Undefined function or variable "column_data".
Hi This the same question as Austin, how find the second largest color, as u said i sorted the color_counts. And after that i did not understand . The permutation index, to re-order the the colors in the unique_colors matrix. How to do it can u please tell.. Thank You ..

References: v. 
 v.

 v. 
 v.

 v.

 v.

 v.