How to find the rectangle with those text












2














In this image:





I want to find this rectangle with all contents(without those grid's lines)





I think the total of the pixels can help a little like:



img = Import["http://i.stack.imgur.com/lnd5w.png"];
data = Total[ImageData[ImageRotate[ColorNegate[img]]]];
Show[ImageRotate[img],
ListLinePlot[data, PlotRange -> All, PlotStyle -> Red]]




And I have such images:



image2





image3





image4





I have no idea to do this thing. Does anyone have an idea?










share|improve this question


















  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    Dec 28 '18 at 14:36










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    Dec 28 '18 at 14:37










  • @CarlLange It's not very similar...
    – yode
    Dec 28 '18 at 14:37












  • The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
    – Carl Lange
    Dec 28 '18 at 15:10
















2














In this image:





I want to find this rectangle with all contents(without those grid's lines)





I think the total of the pixels can help a little like:



img = Import["http://i.stack.imgur.com/lnd5w.png"];
data = Total[ImageData[ImageRotate[ColorNegate[img]]]];
Show[ImageRotate[img],
ListLinePlot[data, PlotRange -> All, PlotStyle -> Red]]




And I have such images:



image2





image3





image4





I have no idea to do this thing. Does anyone have an idea?










share|improve this question


















  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    Dec 28 '18 at 14:36










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    Dec 28 '18 at 14:37










  • @CarlLange It's not very similar...
    – yode
    Dec 28 '18 at 14:37












  • The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
    – Carl Lange
    Dec 28 '18 at 15:10














2












2








2







In this image:





I want to find this rectangle with all contents(without those grid's lines)





I think the total of the pixels can help a little like:



img = Import["http://i.stack.imgur.com/lnd5w.png"];
data = Total[ImageData[ImageRotate[ColorNegate[img]]]];
Show[ImageRotate[img],
ListLinePlot[data, PlotRange -> All, PlotStyle -> Red]]




And I have such images:



image2





image3





image4





I have no idea to do this thing. Does anyone have an idea?










share|improve this question













In this image:





I want to find this rectangle with all contents(without those grid's lines)





I think the total of the pixels can help a little like:



img = Import["http://i.stack.imgur.com/lnd5w.png"];
data = Total[ImageData[ImageRotate[ColorNegate[img]]]];
Show[ImageRotate[img],
ListLinePlot[data, PlotRange -> All, PlotStyle -> Red]]




And I have such images:



image2





image3





image4





I have no idea to do this thing. Does anyone have an idea?







image-processing signal-processing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 28 '18 at 13:57









yode

10.1k233100




10.1k233100








  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    Dec 28 '18 at 14:36










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    Dec 28 '18 at 14:37










  • @CarlLange It's not very similar...
    – yode
    Dec 28 '18 at 14:37












  • The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
    – Carl Lange
    Dec 28 '18 at 15:10














  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    Dec 28 '18 at 14:36










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    Dec 28 '18 at 14:37










  • @CarlLange It's not very similar...
    – yode
    Dec 28 '18 at 14:37












  • The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
    – Carl Lange
    Dec 28 '18 at 15:10








1




1




Have you asked this question before? It seems very familiar to me...
– Carl Lange
Dec 28 '18 at 14:36




Have you asked this question before? It seems very familiar to me...
– Carl Lange
Dec 28 '18 at 14:36












Ah, I was thinking of this and this. Just for context purposes :)
– Carl Lange
Dec 28 '18 at 14:37




Ah, I was thinking of this and this. Just for context purposes :)
– Carl Lange
Dec 28 '18 at 14:37












@CarlLange It's not very similar...
– yode
Dec 28 '18 at 14:37






@CarlLange It's not very similar...
– yode
Dec 28 '18 at 14:37














The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
– Carl Lange
Dec 28 '18 at 15:10




The question isn't but the images are, so I wanted to make sure it wasn't a duplicate somehow. That's all!
– Carl Lange
Dec 28 '18 at 15:10










2 Answers
2






active

oldest

votes


















3














Binarization and ComponentMeasurements seems the straightforward solution:



img = Import["https://i.stack.imgur.com/lnd5w.png"];    


Selct all components that are less than half as long as the image:



comp = ComponentMeasurements[MorphologicalBinarize[ColorNegate@img], 
"BoundingBox", #CaliperLength < Min[ImageDimensions[img]]*0.5 &];


This selects all digits and boxes, but not the grid lines, because they are longer than height/2:



HighlightImage[img, Rectangle @@@ comp[[All, 2]]]


enter image description here



Then combine the individual bounding boxes to one big bounding box:



HighlightImage[img, 
Rectangle @@
Transpose[MinMax /@ Transpose[Flatten[comp[[All, 2]], 1]]]]


enter image description here



You might have to adjust binarization and the criteria in ComponentMeasurements, but for me, it worked on all the images you posted on the first try.






share|improve this answer





























    2














    This works quite well:



    findRegion[img_] := TextRecognize[img, "BoundingBox", RecognitionPrior -> "SparseText"]

    HighlightImage[#, findRegion@#] & /@ imgs




    As you can see, the result for the first image is not perfect unfortunately, but hopefully this gives you some ideas.






    share|improve this answer





















    • Yes, as your try, the Tesseract not very stable..
      – yode
      Dec 28 '18 at 14:40











    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%2f188497%2fhow-to-find-the-rectangle-with-those-text%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Binarization and ComponentMeasurements seems the straightforward solution:



    img = Import["https://i.stack.imgur.com/lnd5w.png"];    


    Selct all components that are less than half as long as the image:



    comp = ComponentMeasurements[MorphologicalBinarize[ColorNegate@img], 
    "BoundingBox", #CaliperLength < Min[ImageDimensions[img]]*0.5 &];


    This selects all digits and boxes, but not the grid lines, because they are longer than height/2:



    HighlightImage[img, Rectangle @@@ comp[[All, 2]]]


    enter image description here



    Then combine the individual bounding boxes to one big bounding box:



    HighlightImage[img, 
    Rectangle @@
    Transpose[MinMax /@ Transpose[Flatten[comp[[All, 2]], 1]]]]


    enter image description here



    You might have to adjust binarization and the criteria in ComponentMeasurements, but for me, it worked on all the images you posted on the first try.






    share|improve this answer


























      3














      Binarization and ComponentMeasurements seems the straightforward solution:



      img = Import["https://i.stack.imgur.com/lnd5w.png"];    


      Selct all components that are less than half as long as the image:



      comp = ComponentMeasurements[MorphologicalBinarize[ColorNegate@img], 
      "BoundingBox", #CaliperLength < Min[ImageDimensions[img]]*0.5 &];


      This selects all digits and boxes, but not the grid lines, because they are longer than height/2:



      HighlightImage[img, Rectangle @@@ comp[[All, 2]]]


      enter image description here



      Then combine the individual bounding boxes to one big bounding box:



      HighlightImage[img, 
      Rectangle @@
      Transpose[MinMax /@ Transpose[Flatten[comp[[All, 2]], 1]]]]


      enter image description here



      You might have to adjust binarization and the criteria in ComponentMeasurements, but for me, it worked on all the images you posted on the first try.






      share|improve this answer
























        3












        3








        3






        Binarization and ComponentMeasurements seems the straightforward solution:



        img = Import["https://i.stack.imgur.com/lnd5w.png"];    


        Selct all components that are less than half as long as the image:



        comp = ComponentMeasurements[MorphologicalBinarize[ColorNegate@img], 
        "BoundingBox", #CaliperLength < Min[ImageDimensions[img]]*0.5 &];


        This selects all digits and boxes, but not the grid lines, because they are longer than height/2:



        HighlightImage[img, Rectangle @@@ comp[[All, 2]]]


        enter image description here



        Then combine the individual bounding boxes to one big bounding box:



        HighlightImage[img, 
        Rectangle @@
        Transpose[MinMax /@ Transpose[Flatten[comp[[All, 2]], 1]]]]


        enter image description here



        You might have to adjust binarization and the criteria in ComponentMeasurements, but for me, it worked on all the images you posted on the first try.






        share|improve this answer












        Binarization and ComponentMeasurements seems the straightforward solution:



        img = Import["https://i.stack.imgur.com/lnd5w.png"];    


        Selct all components that are less than half as long as the image:



        comp = ComponentMeasurements[MorphologicalBinarize[ColorNegate@img], 
        "BoundingBox", #CaliperLength < Min[ImageDimensions[img]]*0.5 &];


        This selects all digits and boxes, but not the grid lines, because they are longer than height/2:



        HighlightImage[img, Rectangle @@@ comp[[All, 2]]]


        enter image description here



        Then combine the individual bounding boxes to one big bounding box:



        HighlightImage[img, 
        Rectangle @@
        Transpose[MinMax /@ Transpose[Flatten[comp[[All, 2]], 1]]]]


        enter image description here



        You might have to adjust binarization and the criteria in ComponentMeasurements, but for me, it worked on all the images you posted on the first try.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 28 '18 at 15:12









        Niki Estner

        30.6k374132




        30.6k374132























            2














            This works quite well:



            findRegion[img_] := TextRecognize[img, "BoundingBox", RecognitionPrior -> "SparseText"]

            HighlightImage[#, findRegion@#] & /@ imgs




            As you can see, the result for the first image is not perfect unfortunately, but hopefully this gives you some ideas.






            share|improve this answer





















            • Yes, as your try, the Tesseract not very stable..
              – yode
              Dec 28 '18 at 14:40
















            2














            This works quite well:



            findRegion[img_] := TextRecognize[img, "BoundingBox", RecognitionPrior -> "SparseText"]

            HighlightImage[#, findRegion@#] & /@ imgs




            As you can see, the result for the first image is not perfect unfortunately, but hopefully this gives you some ideas.






            share|improve this answer





















            • Yes, as your try, the Tesseract not very stable..
              – yode
              Dec 28 '18 at 14:40














            2












            2








            2






            This works quite well:



            findRegion[img_] := TextRecognize[img, "BoundingBox", RecognitionPrior -> "SparseText"]

            HighlightImage[#, findRegion@#] & /@ imgs




            As you can see, the result for the first image is not perfect unfortunately, but hopefully this gives you some ideas.






            share|improve this answer












            This works quite well:



            findRegion[img_] := TextRecognize[img, "BoundingBox", RecognitionPrior -> "SparseText"]

            HighlightImage[#, findRegion@#] & /@ imgs




            As you can see, the result for the first image is not perfect unfortunately, but hopefully this gives you some ideas.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 28 '18 at 14:13









            Lukas Lang

            6,1131928




            6,1131928












            • Yes, as your try, the Tesseract not very stable..
              – yode
              Dec 28 '18 at 14:40


















            • Yes, as your try, the Tesseract not very stable..
              – yode
              Dec 28 '18 at 14:40
















            Yes, as your try, the Tesseract not very stable..
            – yode
            Dec 28 '18 at 14:40




            Yes, as your try, the Tesseract not very stable..
            – yode
            Dec 28 '18 at 14:40


















            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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.


            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%2f188497%2fhow-to-find-the-rectangle-with-those-text%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

            Terni

            A new problem with tex4ht and tikz

            Sun Ra