How to find the rectangle with those text












1














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
    1 hour ago










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    1 hour ago










  • @CarlLange It's not very similar...
    – yode
    1 hour ago












  • 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
    43 mins ago
















1














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
    1 hour ago










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    1 hour ago










  • @CarlLange It's not very similar...
    – yode
    1 hour ago












  • 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
    43 mins ago














1












1








1







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 1 hour ago









yode

10.1k233100




10.1k233100








  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    1 hour ago










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    1 hour ago










  • @CarlLange It's not very similar...
    – yode
    1 hour ago












  • 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
    43 mins ago














  • 1




    Have you asked this question before? It seems very familiar to me...
    – Carl Lange
    1 hour ago










  • Ah, I was thinking of this and this. Just for context purposes :)
    – Carl Lange
    1 hour ago










  • @CarlLange It's not very similar...
    – yode
    1 hour ago












  • 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
    43 mins ago








1




1




Have you asked this question before? It seems very familiar to me...
– Carl Lange
1 hour ago




Have you asked this question before? It seems very familiar to me...
– Carl Lange
1 hour ago












Ah, I was thinking of this and this. Just for context purposes :)
– Carl Lange
1 hour ago




Ah, I was thinking of this and this. Just for context purposes :)
– Carl Lange
1 hour ago












@CarlLange It's not very similar...
– yode
1 hour ago






@CarlLange It's not very similar...
– yode
1 hour ago














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
43 mins ago




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
43 mins ago










2 Answers
2






active

oldest

votes


















1














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
    1 hour ago



















1














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





















    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









    1














    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
      1 hour ago
















    1














    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
      1 hour ago














    1












    1








    1






    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 1 hour ago









    Lukas Lang

    5,6131626




    5,6131626












    • Yes, as your try, the Tesseract not very stable..
      – yode
      1 hour ago


















    • Yes, as your try, the Tesseract not very stable..
      – yode
      1 hour ago
















    Yes, as your try, the Tesseract not very stable..
    – yode
    1 hour ago




    Yes, as your try, the Tesseract not very stable..
    – yode
    1 hour ago











    1














    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


























      1














      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
























        1












        1








        1






        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 41 mins ago









        Niki Estner

        30.5k374132




        30.5k374132






























            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

            サソリ

            広島県道265号伴広島線

            Setup Asymptote in Texstudio