How to Read the pixels and state what are all the colors that are present in the Image?

1 view (last 30 days)
I have plotted the graph using geoshow.
I need to read the pixels and validate the data by counting the respective colors.
So, I want to know what are the colors present in the Image. I have checked that with paint picker. But, there are number of colors.
Is it possible to read the image and list the colors in the form of color code RGB?
If possible, kindly help me out of this.
  3 Comments
Walter Roberson
Walter Roberson on 6 Jul 2018
Do you want just the list of unique RGB triples? That is quite easy.
Do you want the "color name" for each RGB triple? That is more difficult, but you could start with the over 1500 named colors at https://en.wikipedia.org/wiki/List_of_colors_(compact) and you could read https://blog.xkcd.com/2010/05/03/color-survey-results/ (read it multiple times)
Do you want the named "primary" color for each RGB triple? That is hardest, as we have a very tough time defining exactly where "blue" ends and the next major color starts. Mechanical definitions based upon octant of the RGB color are not very good at aligning with human experience.
Guillaume
Guillaume on 6 Jul 2018
Jotheeshwar V's comment mistakenly posted as an answer moved here:
I don't need the color name. The color indication in redchannel, greenchannel and bluechannel values. Like 255, 255, 255 for white.
and By the way, it is radar-gram of the ground surface and the plot is
https://drive.google.com/open?id=1AHilH-DD7AlSDxrReZ35ZO-06My-G84M
Regards,
Jotheeshwar

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jul 2018
[uniquergb, ~, groupnumber] = unique(reshape(YourImage, [], 3),'row');
groupcounts = accumarray(groupnumber);
Now the RGB triple uniquergb(K,:) occurred groupcounts(K) times.
  5 Comments
Walter Roberson
Walter Roberson on 8 Jul 2018
YourImage = imread('peppers.png');
[uniquergb, ~, groupnumber] = unique(reshape(YourImage, [], 3),'rows');
groupcounts = accumarray(groupnumber, 1);
[sortedcounts, sortidx] = sort(groupcounts, 'descend');
N = 10;
most_common_rgb = double( uniquergb(sortidx(1:N),:) );
most_common_counts = sortedcounts(1:N);
fprintf('The most common colors are:\n count @ [r, g, b]\n');
fprintf('%g @ [%g, %g, %g]\n', [most_common_counts, most_common_rgb].' ); %transpose is important
Jotheeshwar V
Jotheeshwar V on 8 Jul 2018
Edited: Jotheeshwar V on 8 Jul 2018
When I use my image, I am getting the error:
Out of memory. Type HELP MEMORY for your options.
I tried for a small image and that worked out
What should I do for this concern?
and the grid size of my file is, 11521x39842x3

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!