# Identifying the color in Image

This has mad me Crazy for a while Can any one please Help me solving this this is the Image that I am working on . Basically this image is made up of 98 different color patches 7 patch on each level and there are 14 such level

I want to get the colour of each patch on each level in something like an array
like this

colorPatch={{#524,#521,#124,#897,#365,#489,#546},   -->Level 1
{#124,#524,#897,#365,#546,#514,#687},   -->Level2
.
.}                                   -->nth Level
this is what i did till now

s = Import["http://i.stack.imgur.com/ubuPp.jpg"];
p = ImagePartition[s, {50, 69}]


• So you want the colour of each tiles of p?
– Öskå
Jul 8, 2014 at 9:45
• Yes I want to identify the color of each tiles in P I am trying to use DominantColors[image, n] but my implentation is not correct Jul 8, 2014 at 9:48
• An other question is, do you want the colours of the icons on the some tiles?
– Öskå
Jul 8, 2014 at 9:56
• No I don't want to find the color of that icon those will be used latter on to group tiles in P based on the icon..but for now just to find the color of the tiles Jul 8, 2014 at 10:05
• Using interpunction can work wonders for the readibility of your question. Jul 8, 2014 at 10:40

I just take the value of the pixel in the middle of the tile, if you want the mean value of the whole tile just use Mean@Flatten[ImageData[#], 1] & /@ p.

s = Import["http://i.stack.imgur.com/ubuPp.jpg"];
p = Flatten[ImagePartition[s, {50, 69}], 1]
colors = PixelValue[#, .5*ImageDimensions@#] & /@ p;
GraphicsRow@{p[[1]], Graphics[{RGBColor@colors[[1]], Disk[]}]}


DominantColors is a v9 feature, so I can not check what I'm doing right now but

DominantColors[#, 5] & /@ p


should give you the 5 first dominant colours in each tiles.

If you want to preserve the structure of p:

p = ImagePartition[s, {50, 69}];
dom = DominantColors[#, 5] &;
colors = Map[dom, p, {2}]


should give you the 5 first dominant colours in each tiles, with Dimensions@colors === Dimensions@p.

• Can you please Explain me according to syntax for DominantColors is DominantColors[image, n] but what is the meaning of # &/a in your code Jul 8, 2014 at 10:08
• /@ is the shorthand of Map so the function DominantColors[#, 5] is mapped through all the elements of p.
– Öskå
Jul 8, 2014 at 10:10
• Simpler way to preserve the structure: Map[PixelValue[#, .5*ImageDimensions@#] &, p, {2}]
– user484
Jul 8, 2014 at 10:18
• @RahulNarain Thank you :) I knew there was something but I never remember the Map[,{2}] :)
– Öskå
Jul 8, 2014 at 10:20
• Thanks a lot Guy for your assistance and guidance :D Jul 8, 2014 at 10:28