Determine maximum and minimum pixel value to draw bounding box












0














Given an image with semantic map,



enter image description here



enter image description here



In python, How can I draw a bounding-box around the person standing for instance?



I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.










share|improve this question



























    0














    Given an image with semantic map,



    enter image description here



    enter image description here



    In python, How can I draw a bounding-box around the person standing for instance?



    I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.










    share|improve this question

























      0












      0








      0







      Given an image with semantic map,



      enter image description here



      enter image description here



      In python, How can I draw a bounding-box around the person standing for instance?



      I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.










      share|improve this question













      Given an image with semantic map,



      enter image description here



      enter image description here



      In python, How can I draw a bounding-box around the person standing for instance?



      I've done some research and understood that I need to choose the maximum and minimum pixel value to get the bounding box information. But I don't understand how to implement this.







      python image-processing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 9 hours ago









      user3641381

      455617




      455617
























          1 Answer
          1






          active

          oldest

          votes


















          0















          1. Redraw the object you want to box in unique for that semantic map color. For instance I've used green:


          semantic map




          1. Run following script:


          .



          from PIL import Image, ImageDraw

          IMAGE = 't5XM4.png'
          IMAGE_MAP = 'Gz8b7.png'
          IMAGE_OUTPUT = 'Result.png'
          GREEN = (0, 255, 0)
          OFFSET = 10

          image_map = Image.open(IMAGE_MAP)
          image = Image.open(IMAGE)
          pixels = image_map.load()
          size_sm = image_map.size
          size = image.size
          ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
          x_list =
          y_list =

          for x in range(size_sm[0]):
          for y in range(size_sm[1]):
          if pixels[x, y] == GREEN:
          x_list.append(x)
          y_list.append(y)

          draw = ImageDraw.Draw(image)
          draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
          (max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
          width=5, outline=GREEN)
          image.save(IMAGE_OUTPUT, 'PNG')



          1. You've got following image at the end:


          result image with bounding box






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fstackoverflow.com%2fquestions%2f53942508%2fdetermine-maximum-and-minimum-pixel-value-to-draw-bounding-box%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0















            1. Redraw the object you want to box in unique for that semantic map color. For instance I've used green:


            semantic map




            1. Run following script:


            .



            from PIL import Image, ImageDraw

            IMAGE = 't5XM4.png'
            IMAGE_MAP = 'Gz8b7.png'
            IMAGE_OUTPUT = 'Result.png'
            GREEN = (0, 255, 0)
            OFFSET = 10

            image_map = Image.open(IMAGE_MAP)
            image = Image.open(IMAGE)
            pixels = image_map.load()
            size_sm = image_map.size
            size = image.size
            ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
            x_list =
            y_list =

            for x in range(size_sm[0]):
            for y in range(size_sm[1]):
            if pixels[x, y] == GREEN:
            x_list.append(x)
            y_list.append(y)

            draw = ImageDraw.Draw(image)
            draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
            (max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
            width=5, outline=GREEN)
            image.save(IMAGE_OUTPUT, 'PNG')



            1. You've got following image at the end:


            result image with bounding box






            share|improve this answer




























              0















              1. Redraw the object you want to box in unique for that semantic map color. For instance I've used green:


              semantic map




              1. Run following script:


              .



              from PIL import Image, ImageDraw

              IMAGE = 't5XM4.png'
              IMAGE_MAP = 'Gz8b7.png'
              IMAGE_OUTPUT = 'Result.png'
              GREEN = (0, 255, 0)
              OFFSET = 10

              image_map = Image.open(IMAGE_MAP)
              image = Image.open(IMAGE)
              pixels = image_map.load()
              size_sm = image_map.size
              size = image.size
              ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
              x_list =
              y_list =

              for x in range(size_sm[0]):
              for y in range(size_sm[1]):
              if pixels[x, y] == GREEN:
              x_list.append(x)
              y_list.append(y)

              draw = ImageDraw.Draw(image)
              draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
              (max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
              width=5, outline=GREEN)
              image.save(IMAGE_OUTPUT, 'PNG')



              1. You've got following image at the end:


              result image with bounding box






              share|improve this answer


























                0












                0








                0







                1. Redraw the object you want to box in unique for that semantic map color. For instance I've used green:


                semantic map




                1. Run following script:


                .



                from PIL import Image, ImageDraw

                IMAGE = 't5XM4.png'
                IMAGE_MAP = 'Gz8b7.png'
                IMAGE_OUTPUT = 'Result.png'
                GREEN = (0, 255, 0)
                OFFSET = 10

                image_map = Image.open(IMAGE_MAP)
                image = Image.open(IMAGE)
                pixels = image_map.load()
                size_sm = image_map.size
                size = image.size
                ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
                x_list =
                y_list =

                for x in range(size_sm[0]):
                for y in range(size_sm[1]):
                if pixels[x, y] == GREEN:
                x_list.append(x)
                y_list.append(y)

                draw = ImageDraw.Draw(image)
                draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
                (max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
                width=5, outline=GREEN)
                image.save(IMAGE_OUTPUT, 'PNG')



                1. You've got following image at the end:


                result image with bounding box






                share|improve this answer















                1. Redraw the object you want to box in unique for that semantic map color. For instance I've used green:


                semantic map




                1. Run following script:


                .



                from PIL import Image, ImageDraw

                IMAGE = 't5XM4.png'
                IMAGE_MAP = 'Gz8b7.png'
                IMAGE_OUTPUT = 'Result.png'
                GREEN = (0, 255, 0)
                OFFSET = 10

                image_map = Image.open(IMAGE_MAP)
                image = Image.open(IMAGE)
                pixels = image_map.load()
                size_sm = image_map.size
                size = image.size
                ratio = (size_sm[0]/size[0], size_sm[1]/size[1])
                x_list =
                y_list =

                for x in range(size_sm[0]):
                for y in range(size_sm[1]):
                if pixels[x, y] == GREEN:
                x_list.append(x)
                y_list.append(y)

                draw = ImageDraw.Draw(image)
                draw.rectangle(((min(x_list)/ratio[0]-OFFSET, min(y_list)/ratio[1]-OFFSET),
                (max(x_list)/ratio[0]+OFFSET,max(y_list)/ratio[1]+OFFSET)),
                width=5, outline=GREEN)
                image.save(IMAGE_OUTPUT, 'PNG')



                1. You've got following image at the end:


                result image with bounding box







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 4 hours ago

























                answered 4 hours ago









                Alderven

                518317




                518317






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


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





                    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%2fstackoverflow.com%2fquestions%2f53942508%2fdetermine-maximum-and-minimum-pixel-value-to-draw-bounding-box%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

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'