11
$\begingroup$

Below you will see a diagram containing three curves.

enter image description here

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

$\endgroup$
  • 1
    $\begingroup$ mathematica.stackexchange.com/questions/44355/… $\endgroup$ – Alex Trounev Oct 31 '18 at 13:09
  • 1
    $\begingroup$ ……同学,你到底是想从图片(Image)上挖点呢,还是想从Plot之类的函数画出的图(Graphics)里面挖点?实在说不清楚的话可以用中文表达下。 $\endgroup$ – xzczd Oct 31 '18 at 14:32
  • $\begingroup$ @xzczd, Ren Qi Pan is a new contributor ............. $\endgroup$ – ABCDEMMM Oct 31 '18 at 23:20
  • $\begingroup$ @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. $\endgroup$ – xzczd Nov 1 '18 at 0:47
  • $\begingroup$ 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. $\endgroup$ – Ren Qi Pan Nov 1 '18 at 14:28
17
$\begingroup$

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

enter image description here

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}

$\endgroup$
  • $\begingroup$ Works great on 10.4, fails on 11.3, where I only get 4 clusters in p. $\endgroup$ – AxelF Oct 31 '18 at 14:12
  • $\begingroup$ You just have to try another cluster by changing the value p[[5]].. $\endgroup$ – J42161217 Oct 31 '18 at 14:14
  • 2
    $\begingroup$ 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] $\endgroup$ – Gustavo Delfino Oct 31 '18 at 14:15
  • 2
    $\begingroup$ 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) $\endgroup$ – J42161217 Oct 31 '18 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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