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["https://i.sstatic.net/ubuPp.jpg"];
p = ImagePartition[s, {50, 69}]

enter image description here

  • $\begingroup$ So you want the colour of each tiles of p? $\endgroup$
    – Öskå
    Commented Jul 8, 2014 at 9:45
  • $\begingroup$ 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 $\endgroup$ Commented Jul 8, 2014 at 9:48
  • $\begingroup$ An other question is, do you want the colours of the icons on the some tiles? $\endgroup$
    – Öskå
    Commented Jul 8, 2014 at 9:56
  • $\begingroup$ 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 $\endgroup$ Commented Jul 8, 2014 at 10:05
  • $\begingroup$ Using interpunction can work wonders for the readibility of your question. $\endgroup$ Commented Jul 8, 2014 at 10:40

1 Answer 1


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["https://i.sstatic.net/ubuPp.jpg"];
p = Flatten[ImagePartition[s, {50, 69}], 1]
colors = PixelValue[#, .5*ImageDimensions@#] & /@ p;
GraphicsRow@{p[[1]], Graphics[{RGBColor@colors[[1]], Disk[]}]}

Mathematica graphics

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.