Plotting positive and negative pixels of image separately on subplots












0















Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.



So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
enter image description here










share|improve this question



























    0















    Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.



    So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
    enter image description here










    share|improve this question

























      0












      0








      0








      Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.



      So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
      enter image description here










      share|improve this question














      Suppose have an image like this, that consists of two images, 1 and 6 which are kind of superimposed on each other, if you look closely at it.



      So, I need to visualize each of these digits separately by having all positive pixels of original image in one image, and all negative pixels in the second one. Is there any way to achieve that in python using matplotlib.pyplot without messing up with the structure of the image? Basically, I need all the white color pixels to be plotted separately from the black color pixels.
      enter image description here







      python matplotlib image-processing plot pixel






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 1:42









      ViniLLViniLL

      216




      216
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You may set all values above or below some threshold to nan, such that they won't appear in the final image.



          The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.



          import numpy as np
          import matplotlib.pyplot as plt

          img = plt.imread("grayscaleimage.png")[:,:,0]

          white = np.copy(img)
          white[white<0.6] = np.nan

          dark = np.copy(img)
          dark[dark>0.4] = np.nan

          fig = plt.figure()
          ax0 = fig.add_subplot(211)
          ax1 = fig.add_subplot(223)
          ax2 = fig.add_subplot(224)

          ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
          ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
          ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")

          for ax in (ax1,ax2):
          ax.set_facecolor("gold")

          plt.show()


          enter image description here






          Here is the test image used in the above:
          enter image description here (right click, save as...)




          share|improve this answer


























          • Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

            – ViniLL
            Nov 15 '18 at 7:42











          • I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

            – ImportanceOfBeingErnest
            Nov 15 '18 at 13:40











          • Ok got you, thanks.

            – ViniLL
            Nov 15 '18 at 18:32











          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%2f53311276%2fplotting-positive-and-negative-pixels-of-image-separately-on-subplots%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














          You may set all values above or below some threshold to nan, such that they won't appear in the final image.



          The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.



          import numpy as np
          import matplotlib.pyplot as plt

          img = plt.imread("grayscaleimage.png")[:,:,0]

          white = np.copy(img)
          white[white<0.6] = np.nan

          dark = np.copy(img)
          dark[dark>0.4] = np.nan

          fig = plt.figure()
          ax0 = fig.add_subplot(211)
          ax1 = fig.add_subplot(223)
          ax2 = fig.add_subplot(224)

          ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
          ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
          ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")

          for ax in (ax1,ax2):
          ax.set_facecolor("gold")

          plt.show()


          enter image description here






          Here is the test image used in the above:
          enter image description here (right click, save as...)




          share|improve this answer


























          • Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

            – ViniLL
            Nov 15 '18 at 7:42











          • I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

            – ImportanceOfBeingErnest
            Nov 15 '18 at 13:40











          • Ok got you, thanks.

            – ViniLL
            Nov 15 '18 at 18:32
















          0














          You may set all values above or below some threshold to nan, such that they won't appear in the final image.



          The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.



          import numpy as np
          import matplotlib.pyplot as plt

          img = plt.imread("grayscaleimage.png")[:,:,0]

          white = np.copy(img)
          white[white<0.6] = np.nan

          dark = np.copy(img)
          dark[dark>0.4] = np.nan

          fig = plt.figure()
          ax0 = fig.add_subplot(211)
          ax1 = fig.add_subplot(223)
          ax2 = fig.add_subplot(224)

          ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
          ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
          ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")

          for ax in (ax1,ax2):
          ax.set_facecolor("gold")

          plt.show()


          enter image description here






          Here is the test image used in the above:
          enter image description here (right click, save as...)




          share|improve this answer


























          • Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

            – ViniLL
            Nov 15 '18 at 7:42











          • I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

            – ImportanceOfBeingErnest
            Nov 15 '18 at 13:40











          • Ok got you, thanks.

            – ViniLL
            Nov 15 '18 at 18:32














          0












          0








          0







          You may set all values above or below some threshold to nan, such that they won't appear in the final image.



          The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.



          import numpy as np
          import matplotlib.pyplot as plt

          img = plt.imread("grayscaleimage.png")[:,:,0]

          white = np.copy(img)
          white[white<0.6] = np.nan

          dark = np.copy(img)
          dark[dark>0.4] = np.nan

          fig = plt.figure()
          ax0 = fig.add_subplot(211)
          ax1 = fig.add_subplot(223)
          ax2 = fig.add_subplot(224)

          ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
          ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
          ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")

          for ax in (ax1,ax2):
          ax.set_facecolor("gold")

          plt.show()


          enter image description here






          Here is the test image used in the above:
          enter image description here (right click, save as...)




          share|improve this answer















          You may set all values above or below some threshold to nan, such that they won't appear in the final image.



          The following code leaves out the range between 0.4 and 0.6 completely. The yellow background is chosen to show that there are no pixels in that area.



          import numpy as np
          import matplotlib.pyplot as plt

          img = plt.imread("grayscaleimage.png")[:,:,0]

          white = np.copy(img)
          white[white<0.6] = np.nan

          dark = np.copy(img)
          dark[dark>0.4] = np.nan

          fig = plt.figure()
          ax0 = fig.add_subplot(211)
          ax1 = fig.add_subplot(223)
          ax2 = fig.add_subplot(224)

          ax0.imshow(img, vmin=0, vmax=1, cmap="Greys")
          ax1.imshow(white, vmin=0, vmax=1, cmap="Greys")
          ax2.imshow(dark, vmin=0, vmax=1, cmap="Greys")

          for ax in (ax1,ax2):
          ax.set_facecolor("gold")

          plt.show()


          enter image description here






          Here is the test image used in the above:
          enter image description here (right click, save as...)





          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 13:39

























          answered Nov 15 '18 at 2:40









          ImportanceOfBeingErnestImportanceOfBeingErnest

          135k13151226




          135k13151226













          • Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

            – ViniLL
            Nov 15 '18 at 7:42











          • I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

            – ImportanceOfBeingErnest
            Nov 15 '18 at 13:40











          • Ok got you, thanks.

            – ViniLL
            Nov 15 '18 at 18:32



















          • Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

            – ViniLL
            Nov 15 '18 at 7:42











          • I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

            – ImportanceOfBeingErnest
            Nov 15 '18 at 13:40











          • Ok got you, thanks.

            – ViniLL
            Nov 15 '18 at 18:32

















          Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

          – ViniLL
          Nov 15 '18 at 7:42





          Thanks a lot, it worked pretty well! I had to change some values though, but I got the point. Could you also share where did you get your testing image? it looks much sharper and it is very relevant to my ML perceptron algorithm that I am implementing

          – ViniLL
          Nov 15 '18 at 7:42













          I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

          – ImportanceOfBeingErnest
          Nov 15 '18 at 13:40





          I added the test image. It's created via inkscape by placing a white 1 and a black 6 on gray background.

          – ImportanceOfBeingErnest
          Nov 15 '18 at 13:40













          Ok got you, thanks.

          – ViniLL
          Nov 15 '18 at 18:32





          Ok got you, thanks.

          – ViniLL
          Nov 15 '18 at 18:32




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311276%2fplotting-positive-and-negative-pixels-of-image-separately-on-subplots%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

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues