How many colors with their name present in the image.
Ältere Kommentare anzeigen
I am looking for a way to find the number and name of certain colors present in the image so that I can use them to count for each pixel. I am doing it but actually some other colors or can say mixed colors are also present in the image which when I count are left in the counting and it counts less and as I increase the size of image pixels the uncounted number increase. I am giving the color ranges for the visible 13 colors in the image but their are some other colors present too which I am missing. How can I find them? Thanks in advane for the help, I am stuck with the problem since long time. My image is 

1 Kommentar
Adam Danz
am 12 Sep. 2020
Perhaps better than my just-for-fun approach, check out imhist().
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 12 Sep. 2020
0 Stimmen
Like Adam showed you, there are many, many colors, not just 13. Here is a scatterplot of them:

If you want just 13 you should do cluster analysis. I'm attaching some demos that you may find instructive.
5 Kommentare
Image Analyst
am 12 Sep. 2020
You could also use
[indexedImage, map] = rgb23ind(rgbImage, 13); % Reduce to just 13 colors.
Adam Danz
am 12 Sep. 2020
Now that's a cool visualization!
Atique Khan
am 15 Sep. 2020
Image Analyst
am 15 Sep. 2020
If you look up rgb2ind() in the help, you can see that the second argument can either be the number of colors you want or the actual colors you want.
If you pass in 13, it will give you an indexed image, and the 13 colors will be listed in map.
[indexedImage, map] = rgb2ind(rgbImage, 13); % Reduce to just 13 colors.
map is a 13 by 3 list of what colors it thinks best represent your image.
If you pass in some map you've created, then it will assign the pixel to the color in the map that is closest to its original color
myCustomMap = jet(13); % Whatever you specify. It's a N by 3 matrix.
indexedImage = rgb2ind(rgbImage, myCustomMap);
Now you're specifying the map so it doesn't have to figure it out on its own. You will get an image where the value of the image is the index (row) into the colormap you told it. So if the indexedImage(4, 9) is 5, then color of the original RGB image pixel at row 4, column 9, is best described by the color you put into row 5 of your custom color map matrix.
Walter Roberson
am 28 Jan. 2025
[indexedImage, map] = rgb23ind(rgbImage, 13); % Reduce to just 13 colors.
I think you meant
[indexedImage, map] = rgb2ind(rgbImage, 13); % Reduce to just 13 colors.
Kategorien
Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




