# How can I extract data from a diagram?

Below you will see a diagram containing three curves.

How can I extract data points from the three colored curves? I need to use the original data.

• mathematica.stackexchange.com/questions/44355/… – Alex Trounev Oct 31 '18 at 13:09
• ……同学，你到底是想从图片（Image）上挖点呢，还是想从Plot之类的函数画出的图（Graphics）里面挖点？实在说不清楚的话可以用中文表达下。 – xzczd Oct 31 '18 at 14:32
• @xzczd, Ren Qi Pan is a new contributor ............. – ABCDEMMM Oct 31 '18 at 23:20
• @ABCDEMMM I know, and that's the reason why I'm trying to communicate in Chinese. Given that the original version of this question isn't that clear, and OP doesn't reply to the question in (now deleted) comment for quite a while, I suppose (s)he is having difficulty in saying what (s)he wants to say. – xzczd Nov 1 '18 at 0:47
• Thanks, but I don't have language barriers. I wanna get the original data(containing lots of points) of the image. In the following answers, someone have solved the problem. Thank you agian, anyhow. – Ren Qi Pan Nov 1 '18 at 14:28

this code produces the three lists of data that you want orange,blue and green

s = Import["https://i.stack.imgur.com/bR8Gg.gif"];
t = ImageData@s;
h = Union@Flatten[t, 1];
p = FindClusters@h;
F[x_] := (# - {20, 29}) {3/350, 3/100} & /@
Select[Flatten[PixelValuePositions[s, RGBColor[#]] & /@ p[[x]],
1], #[[1]] > 20 && #[[2]] > 29 &]
orange = F[5];
blue = F[1];
green = F[2];

ListPlot[{blue, orange, green}]


Here is the second approach for clustering which was proposed in the comments section

s = Import["https://i.stack.imgur.com/bR8Gg.gif"];
t = ImageData@s;
h = Union@Flatten[t, 1];
p = FindClusters[RGBColor @@@ h];
F[x_] := (# - {21, 29}) {3/350, 3/100} & /@
Select[Flatten[PixelValuePositions[s, #] & /@ p[[x]],
1], #[[1]] > 21 && #[[2]] > 29 &]
orange = F[3];
blue = F[1];
green = F[2];


this gives the same picture but returns more data points in every list
using

Length /@ {blue, orange, green}


first version

{1375, 1228, 1259}

second version

{1534, 1440, 1502}

• Works great on 10.4, fails on 11.3, where I only get 4 clusters in p. – AxelF Oct 31 '18 at 14:12
• You just have to try another cluster by changing the value p[[5]].. – J42161217 Oct 31 '18 at 14:14
• This is interesting. I just compared FindClusters on lists of 3 numbers vs colors. It works better when it knows it is clustering colors. That is FindClusters[RGBColor @@@ h] instead of just FindClusters[h] – Gustavo Delfino Oct 31 '18 at 14:15
• very nice. I also fixed the scale. I really have to go now so I will implement your idea later. (or feel free to edit yourself) – J42161217 Oct 31 '18 at 14:22