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.

As the title says, I want to measure the area of different closed regions in a plot. Let me be more specific by giving a characteristic example. In the following figure, we observe that inside the black closed curve several regions (islands) depicted with different colors appear.

enter image description here

The outermost black limiting curve has an analytical expression and can be obtained by a simple contour plot. On the other hand, all the internal color islands do not have analytical expressions and are created using ListPlot for plotting all the consecutively points forming each island. Now, I want to obtain, at least a rough estimation about the percentage of the total area occupied by the different islands. In other words, to know how "big" are the different sets of islands. In the particular example we can distinguish five different types of islands: (i) the central blue one; (ii) the central green one; (iii) the set of four purple islands; (iv) the set of three orange islands; (v) the set of two elongated red islands.

So, my question: Is there a way to compute the percentage of the total area occupied by each of these sets of islands using Mathematica?

Using a FORTRAN code I can compute these percentages. However, this is a very time consuming procedure, since I have to define a dense grid of points inside the closed curve, then integrate each one and finally classifying them into different types thus counting the required percentages. So, I would be really very grateful, if I could speed up this task by using Mathematica. The exact percentages as they have computed by the FORTRAN code are:

blue ---> 15.44%, green ---> 15.76%, red ---> 5.82%, magenta ---> 1.76%, orange ---> 9.66%,

All the data files and the Mathematica notebook used to create the above plot can be found here:

Files

share|improve this question

marked as duplicate by cormullion, Artes, Sjoerd C. de Vries, rm -rf Jun 23 '13 at 13:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
    
@rm-rf I read both similar articles but non of them can be applied to my situation for different reasons. –  Vaggelis_Z Jun 23 '13 at 10:10
2  
And why is that? –  Sjoerd C. de Vries Jun 23 '13 at 12:45
1  
I don't see you mentioning your "different reasons"; if you have the points comprising your curves, you can at the very least use the "shoelace formula" or fancier methods to get a good estimate of the area. –  J. M. Jun 23 '13 at 14:44
2  
If you don't mention the reasons for why the existing solutions don't work for you, how are we supposed to know in what direction to think? Please edit your question, adding the reasons and your question may quite probably be reopened. –  Sjoerd C. de Vries Jun 23 '13 at 14:54
show 1 more comment

1 Answer 1

up vote 1 down vote accepted

Comment: I think the linked questions show that a component-based solution, for example, should work. A quick check here using MorphologicalComponents and friends suggests that, once you've isolated a color, you can find the area using ComponentMeasurements. For example here's the orange areas:

components

However, rather than having to crop the axes from your plot, and separate the colors, perhaps you can re-factor your code so as to make it easier to generate the images needed.

A quick 'back of the envelope' calculation using ComponentMeasurements suggests the following pixel counts for {blue, green, red, magenta, orange}:

{13502., 15753.5, 5611.63, 973.875, 2930.}

which is similar to your values (although the orange looks a little off..).

Have a go - it's not too hard!

share|improve this answer
    
Heh, you got lucky with one of those rare "answers posted after the question was closed" :) –  rm -rf Jun 23 '13 at 15:20
    
@rm-rf Can I have a "Got hungry halfway through an answer" badge ...? :) –  cormullion Jun 23 '13 at 15:26
    
Yes, your values are very close to mines! However, I would really appreciate, if you could post the code used to obtain the percentage of just one color as an example. Then I could play along easier. –  Vaggelis_Z Jun 23 '13 at 16:12
    
Here, I have to say that I am not familiar with the ComponentMeasurements module therefore, a good example in this case, would be very beneficial for me. So, please illuminate me by posting the lines of code you used in order to obtain the percentages. Many thanks in advance! –  Vaggelis_Z Jun 23 '13 at 16:53
    
Well, it's beyond the scope of me, this answer, and this site, but here's a thing to play with: Manipulate[Column[{mc = MorphologicalComponents[Graphics[{Point[PixelValuePositions[i, col, t]]}]] // Colorize,ComponentMeasurements[mc, "Area", 50 < # < 150000 &]}] , {t, 0, 1}, {col, {Blue, Green, Red, Magenta, Orange}}]. The quality of the image (i) is important... You will have to refer to the documentation a lot for the morphology and segmentation tools...:) –  cormullion Jun 23 '13 at 16:56
show 1 more comment

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