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:


  • $\begingroup$ @rm-rf I read both similar articles but non of them can be applied to my situation for different reasons. $\endgroup$ – Vaggelis_Z Jun 23 '13 at 10:10
  • 2
    $\begingroup$ And why is that? $\endgroup$ – Sjoerd C. de Vries Jun 23 '13 at 12:45
  • 1
    $\begingroup$ 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. $\endgroup$ – J. M.'s ennui Jun 23 '13 at 14:44
  • 2
    $\begingroup$ 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. $\endgroup$ – Sjoerd C. de Vries Jun 23 '13 at 14:54

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:


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!

  • $\begingroup$ Heh, you got lucky with one of those rare "answers posted after the question was closed" :) $\endgroup$ – rm -rf Jun 23 '13 at 15:20
  • $\begingroup$ @rm-rf Can I have a "Got hungry halfway through an answer" badge ...? :) $\endgroup$ – cormullion Jun 23 '13 at 15:26
  • $\begingroup$ 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. $\endgroup$ – Vaggelis_Z Jun 23 '13 at 16:12
  • $\begingroup$ 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! $\endgroup$ – Vaggelis_Z Jun 23 '13 at 16:53
  • 1
    $\begingroup$ Honestly, I don't really understand it. I replaced i in your code with P0 of mine but I cannot interpret the output. What is being measured? Do I have to divide each one with 100? Moreover, I cannot reproduce your exact results. Since you obviously really know what you are doing, I suppose it would be very easy for you to upload a much more detailed edit on you post. I don't think I am asking too much, after all the current answer does not say the exact way used to obtain the five percentages. $\endgroup$ – Vaggelis_Z Jun 23 '13 at 18:16

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