How to get the coordinates of the extrema from a plot?












1












$begingroup$


I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?



I am interested in getting the coordinates as pairs of x and y, for each color in the plot.



Here is an example of such an image:



enter image description here










share|improve this question









$endgroup$












  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    12 hours ago










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    11 hours ago
















1












$begingroup$


I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?



I am interested in getting the coordinates as pairs of x and y, for each color in the plot.



Here is an example of such an image:



enter image description here










share|improve this question









$endgroup$












  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    12 hours ago










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    11 hours ago














1












1








1





$begingroup$


I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?



I am interested in getting the coordinates as pairs of x and y, for each color in the plot.



Here is an example of such an image:



enter image description here










share|improve this question









$endgroup$




I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?



I am interested in getting the coordinates as pairs of x and y, for each color in the plot.



Here is an example of such an image:



enter image description here







plotting






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 13 hours ago









user3318424user3318424

874




874












  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    12 hours ago










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    11 hours ago


















  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    12 hours ago










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    11 hours ago
















$begingroup$
You mean a Graphics-object or a pixel image?
$endgroup$
– Ulrich Neumann
12 hours ago




$begingroup$
You mean a Graphics-object or a pixel image?
$endgroup$
– Ulrich Neumann
12 hours ago












$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago




$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago










3 Answers
3






active

oldest

votes


















4












$begingroup$

If "image" is a Graphics-object try



pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}]  (*two functions*) 

lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)


Evaluate all extrema and plot



extrema = Map[Cases[
Partition[#, 3,1], {{_, a_}, p : {_, b_}, {_, c_}} /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
    $endgroup$
    – user3318424
    12 hours ago










  • $begingroup$
    I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
    $endgroup$
    – Ulrich Neumann
    12 hours ago










  • $begingroup$
    All the extrema.
    $endgroup$
    – user3318424
    12 hours ago



















4












$begingroup$

If "image" is a pixel image
(named pic , sorry, don't know how to include pic="image" in the coding ) try:



dc = Rest@DominantColors[pic] (* dominant colors without white*)

curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)


Get the points of the different curves



points = Cases[curves  , Point[pi_] -> pi, Infinity];


...see my first answer






share|improve this answer









$endgroup$





















    3












    $begingroup$

    Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks to also catch the end points.



    pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}];  (*two functions*)

    lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)

    max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];

    min = Flatten[(#[[FindPeaks[(# /. {x_?NumericQ, y_?NumericQ} :> {x, -y})[[All,
    2]]][[All, 1]]]] & /@ lines), 1];

    Show[pic, Epilog -> {AbsolutePointSize[4],
    Red, Point[max],
    Blue, Point[min]}]


    enter image description here






    share|improve this answer









    $endgroup$













      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "387"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190664%2fhow-to-get-the-coordinates-of-the-extrema-from-a-plot%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4












      $begingroup$

      If "image" is a Graphics-object try



      pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}]  (*two functions*) 

      lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)


      Evaluate all extrema and plot



      extrema = Map[Cases[
      Partition[#, 3,1], {{_, a_}, p : {_, b_}, {_, c_}} /; a < b && c < b || a > b && c > b -> p] &, lines]
      Show[pic, Graphics[Point[extrema ]]]


      enter image description here






      share|improve this answer











      $endgroup$













      • $begingroup$
        Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
        $endgroup$
        – user3318424
        12 hours ago










      • $begingroup$
        I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
        $endgroup$
        – Ulrich Neumann
        12 hours ago










      • $begingroup$
        All the extrema.
        $endgroup$
        – user3318424
        12 hours ago
















      4












      $begingroup$

      If "image" is a Graphics-object try



      pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}]  (*two functions*) 

      lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)


      Evaluate all extrema and plot



      extrema = Map[Cases[
      Partition[#, 3,1], {{_, a_}, p : {_, b_}, {_, c_}} /; a < b && c < b || a > b && c > b -> p] &, lines]
      Show[pic, Graphics[Point[extrema ]]]


      enter image description here






      share|improve this answer











      $endgroup$













      • $begingroup$
        Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
        $endgroup$
        – user3318424
        12 hours ago










      • $begingroup$
        I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
        $endgroup$
        – Ulrich Neumann
        12 hours ago










      • $begingroup$
        All the extrema.
        $endgroup$
        – user3318424
        12 hours ago














      4












      4








      4





      $begingroup$

      If "image" is a Graphics-object try



      pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}]  (*two functions*) 

      lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)


      Evaluate all extrema and plot



      extrema = Map[Cases[
      Partition[#, 3,1], {{_, a_}, p : {_, b_}, {_, c_}} /; a < b && c < b || a > b && c > b -> p] &, lines]
      Show[pic, Graphics[Point[extrema ]]]


      enter image description here






      share|improve this answer











      $endgroup$



      If "image" is a Graphics-object try



      pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}]  (*two functions*) 

      lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)


      Evaluate all extrema and plot



      extrema = Map[Cases[
      Partition[#, 3,1], {{_, a_}, p : {_, b_}, {_, c_}} /; a < b && c < b || a > b && c > b -> p] &, lines]
      Show[pic, Graphics[Point[extrema ]]]


      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 11 hours ago

























      answered 12 hours ago









      Ulrich NeumannUlrich Neumann

      8,380516




      8,380516












      • $begingroup$
        Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
        $endgroup$
        – user3318424
        12 hours ago










      • $begingroup$
        I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
        $endgroup$
        – Ulrich Neumann
        12 hours ago










      • $begingroup$
        All the extrema.
        $endgroup$
        – user3318424
        12 hours ago


















      • $begingroup$
        Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
        $endgroup$
        – user3318424
        12 hours ago










      • $begingroup$
        I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
        $endgroup$
        – Ulrich Neumann
        12 hours ago










      • $begingroup$
        All the extrema.
        $endgroup$
        – user3318424
        12 hours ago
















      $begingroup$
      Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
      $endgroup$
      – user3318424
      12 hours ago




      $begingroup$
      Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
      $endgroup$
      – user3318424
      12 hours ago












      $begingroup$
      I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
      $endgroup$
      – Ulrich Neumann
      12 hours ago




      $begingroup$
      I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
      $endgroup$
      – Ulrich Neumann
      12 hours ago












      $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      12 hours ago




      $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      12 hours ago











      4












      $begingroup$

      If "image" is a pixel image
      (named pic , sorry, don't know how to include pic="image" in the coding ) try:



      dc = Rest@DominantColors[pic] (* dominant colors without white*)

      curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)


      Get the points of the different curves



      points = Cases[curves  , Point[pi_] -> pi, Infinity];


      ...see my first answer






      share|improve this answer









      $endgroup$


















        4












        $begingroup$

        If "image" is a pixel image
        (named pic , sorry, don't know how to include pic="image" in the coding ) try:



        dc = Rest@DominantColors[pic] (* dominant colors without white*)

        curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)


        Get the points of the different curves



        points = Cases[curves  , Point[pi_] -> pi, Infinity];


        ...see my first answer






        share|improve this answer









        $endgroup$
















          4












          4








          4





          $begingroup$

          If "image" is a pixel image
          (named pic , sorry, don't know how to include pic="image" in the coding ) try:



          dc = Rest@DominantColors[pic] (* dominant colors without white*)

          curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)


          Get the points of the different curves



          points = Cases[curves  , Point[pi_] -> pi, Infinity];


          ...see my first answer






          share|improve this answer









          $endgroup$



          If "image" is a pixel image
          (named pic , sorry, don't know how to include pic="image" in the coding ) try:



          dc = Rest@DominantColors[pic] (* dominant colors without white*)

          curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)


          Get the points of the different curves



          points = Cases[curves  , Point[pi_] -> pi, Infinity];


          ...see my first answer







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 11 hours ago









          Ulrich NeumannUlrich Neumann

          8,380516




          8,380516























              3












              $begingroup$

              Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks to also catch the end points.



              pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}];  (*two functions*)

              lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)

              max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];

              min = Flatten[(#[[FindPeaks[(# /. {x_?NumericQ, y_?NumericQ} :> {x, -y})[[All,
              2]]][[All, 1]]]] & /@ lines), 1];

              Show[pic, Epilog -> {AbsolutePointSize[4],
              Red, Point[max],
              Blue, Point[min]}]


              enter image description here






              share|improve this answer









              $endgroup$


















                3












                $begingroup$

                Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks to also catch the end points.



                pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}];  (*two functions*)

                lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)

                max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];

                min = Flatten[(#[[FindPeaks[(# /. {x_?NumericQ, y_?NumericQ} :> {x, -y})[[All,
                2]]][[All, 1]]]] & /@ lines), 1];

                Show[pic, Epilog -> {AbsolutePointSize[4],
                Red, Point[max],
                Blue, Point[min]}]


                enter image description here






                share|improve this answer









                $endgroup$
















                  3












                  3








                  3





                  $begingroup$

                  Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks to also catch the end points.



                  pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}];  (*two functions*)

                  lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)

                  max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];

                  min = Flatten[(#[[FindPeaks[(# /. {x_?NumericQ, y_?NumericQ} :> {x, -y})[[All,
                  2]]][[All, 1]]]] & /@ lines), 1];

                  Show[pic, Epilog -> {AbsolutePointSize[4],
                  Red, Point[max],
                  Blue, Point[min]}]


                  enter image description here






                  share|improve this answer









                  $endgroup$



                  Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks to also catch the end points.



                  pic = Plot[{Sin[x]/x, Exp[-.1 x] Sin[x]}, {x, 0, 20}];  (*two functions*)

                  lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)

                  max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];

                  min = Flatten[(#[[FindPeaks[(# /. {x_?NumericQ, y_?NumericQ} :> {x, -y})[[All,
                  2]]][[All, 1]]]] & /@ lines), 1];

                  Show[pic, Epilog -> {AbsolutePointSize[4],
                  Red, Point[max],
                  Blue, Point[min]}]


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 10 hours ago









                  Bob HanlonBob Hanlon

                  59.5k33596




                  59.5k33596






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Mathematica Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f190664%2fhow-to-get-the-coordinates-of-the-extrema-from-a-plot%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      數位音樂下載

                      格利澤436b

                      When can things happen in Etherscan, such as the picture below?