Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]

enter image description here

share|improve this question
    
So you want the colour of each tiles of p? –  Öskå Jul 8 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 –  Abdullah Sorathia Jul 8 at 9:48
    
An other question is, do you want the colours of the icons on the some tiles? –  Öskå Jul 8 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 –  Abdullah Sorathia Jul 8 at 10:05
    
Using interpunction can work wonders for the readibility of your question. –  Sjoerd C. de Vries Jul 8 at 10:40

1 Answer 1

up vote 2 down vote accepted

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[]}]}

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.

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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