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

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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
    Feb 1 at 16:07










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    Feb 1 at 16:45















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
    Feb 1 at 16:07










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    Feb 1 at 16:45













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 Feb 1 at 15:14









user3318424user3318424

874




874











  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    Feb 1 at 16:07










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    Feb 1 at 16:45
















  • $begingroup$
    You mean a Graphics-object or a pixel image?
    $endgroup$
    – Ulrich Neumann
    Feb 1 at 16:07










  • $begingroup$
    @UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
    $endgroup$
    – MassDefect
    Feb 1 at 16:45















$begingroup$
You mean a Graphics-object or a pixel image?
$endgroup$
– Ulrich Neumann
Feb 1 at 16:07




$begingroup$
You mean a Graphics-object or a pixel image?
$endgroup$
– Ulrich Neumann
Feb 1 at 16:07












$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45




$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45










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
    Feb 1 at 15:41










  • $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
    Feb 1 at 15:42










  • $begingroup$
    All the extrema.
    $endgroup$
    – user3318424
    Feb 1 at 15:46


















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$












    • $begingroup$
      @ BobHanlon Thanks, I didn't know FindPeaks
      $endgroup$
      – Ulrich Neumann
      Feb 2 at 9:35










    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
      Feb 1 at 15:41










    • $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
      Feb 1 at 15:42










    • $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      Feb 1 at 15:46















    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
      Feb 1 at 15:41










    • $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
      Feb 1 at 15:42










    • $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      Feb 1 at 15:46













    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 Feb 1 at 16:33

























    answered Feb 1 at 15:37









    Ulrich NeumannUlrich Neumann

    9,001516




    9,001516











    • $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
      Feb 1 at 15:41










    • $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
      Feb 1 at 15:42










    • $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      Feb 1 at 15:46
















    • $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
      Feb 1 at 15:41










    • $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
      Feb 1 at 15:42










    • $begingroup$
      All the extrema.
      $endgroup$
      – user3318424
      Feb 1 at 15:46















    $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
    Feb 1 at 15:41




    $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
    Feb 1 at 15:41












    $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
    Feb 1 at 15:42




    $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
    Feb 1 at 15:42












    $begingroup$
    All the extrema.
    $endgroup$
    – user3318424
    Feb 1 at 15:46




    $begingroup$
    All the extrema.
    $endgroup$
    – user3318424
    Feb 1 at 15:46











    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 Feb 1 at 17:06









        Ulrich NeumannUlrich Neumann

        9,001516




        9,001516





















            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$












            • $begingroup$
              @ BobHanlon Thanks, I didn't know FindPeaks
              $endgroup$
              – Ulrich Neumann
              Feb 2 at 9:35















            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$












            • $begingroup$
              @ BobHanlon Thanks, I didn't know FindPeaks
              $endgroup$
              – Ulrich Neumann
              Feb 2 at 9:35













            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 Feb 1 at 17:45









            Bob HanlonBob Hanlon

            60.6k33597




            60.6k33597











            • $begingroup$
              @ BobHanlon Thanks, I didn't know FindPeaks
              $endgroup$
              – Ulrich Neumann
              Feb 2 at 9:35
















            • $begingroup$
              @ BobHanlon Thanks, I didn't know FindPeaks
              $endgroup$
              – Ulrich Neumann
              Feb 2 at 9:35















            $begingroup$
            @ BobHanlon Thanks, I didn't know FindPeaks
            $endgroup$
            – Ulrich Neumann
            Feb 2 at 9:35




            $begingroup$
            @ BobHanlon Thanks, I didn't know FindPeaks
            $endgroup$
            – Ulrich Neumann
            Feb 2 at 9:35

















            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

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay