How to remove specific shade of grey from a greyscale image in python PILHow can I remove a trailing newline in Python?How do I remove an element from a list by index in Python?How do I trim whitespace from a Python string?How to remove items from a list while iterating?Remove specific characters from a string in PythonPIL convert('L') to greyscale distorts some imagesPython Image Library fails with message “decoder JPEG not available” - PILPython: Cannot open converted bitmap image file, converted using PILHow to remove a key from a Python dictionary?Replicating ImageMagicks 'Badge using Lighting Effects' using PIL

Did Shadowfax go to Valinor?

What is the word for reserving something for yourself before others do?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?

Dragon forelimb placement

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Theorems that impeded progress

Modeling an IPv4 Address

Why Is Death Allowed In the Matrix?

How old can references or sources in a thesis be?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?

How can bays and straits be determined in a procedurally generated map?

LaTeX closing $ signs makes cursor jump

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

TGV timetables / schedules?

Is it important to consider tone, melody, and musical form while writing a song?

Which models of the Boeing 737 are still in production?

How to test if a transaction is standard without spending real money?

Why are 150k or 200k jobs considered good when there are 300k+ births a month?

How does one intimidate enemies without having the capacity for violence?

Today is the Center

Can I make popcorn with any corn?

Arthur Somervell: 1000 Exercises - Meaning of this notation



How to remove specific shade of grey from a greyscale image in python PIL


How can I remove a trailing newline in Python?How do I remove an element from a list by index in Python?How do I trim whitespace from a Python string?How to remove items from a list while iterating?Remove specific characters from a string in PythonPIL convert('L') to greyscale distorts some imagesPython Image Library fails with message “decoder JPEG not available” - PILPython: Cannot open converted bitmap image file, converted using PILHow to remove a key from a Python dictionary?Replicating ImageMagicks 'Badge using Lighting Effects' using PIL






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a python PIL script that is turning an image into greyscale and then removing a specific shade of grey. I can do this by converting first to rgb and then removing the grey, but I'd like to only be in greyscale.



color = [149, 149, 149]
white = [255, 255, 255]
im2 = Image.open('example-files/step1.jpg')
im = im2.convert('RGB')
data = np.array(im)
rgb = data[:, :, :3]
mask = np.all(rgb == color, axis=-1)
data[mask] = white
new_im = Image.fromarray(data).convert('L')
new_im.save('example-files/step3.png')


This works, except I don't ever want to .convert('RGB'), I always want to remain in greyscale, as I want to make this as fast as possible and I found that that extra convert add about .04 seconds. I tried using the data[mask] method while in greyscale and it doesn't work:



color = [149]
white = [255]
im = Image.open('example-files/step1.jpg').convert('L')
data = np.array(im)
mask = np.all(data == color, axis=-1)
data[mask] = white
new_im = Image.fromarray(data)
new_im.save('example-files/step6.png')


What can I do to either remove that color of grey as fast as possible or get it to remove while remaining in greyscale?










share|improve this question




























    0















    I have a python PIL script that is turning an image into greyscale and then removing a specific shade of grey. I can do this by converting first to rgb and then removing the grey, but I'd like to only be in greyscale.



    color = [149, 149, 149]
    white = [255, 255, 255]
    im2 = Image.open('example-files/step1.jpg')
    im = im2.convert('RGB')
    data = np.array(im)
    rgb = data[:, :, :3]
    mask = np.all(rgb == color, axis=-1)
    data[mask] = white
    new_im = Image.fromarray(data).convert('L')
    new_im.save('example-files/step3.png')


    This works, except I don't ever want to .convert('RGB'), I always want to remain in greyscale, as I want to make this as fast as possible and I found that that extra convert add about .04 seconds. I tried using the data[mask] method while in greyscale and it doesn't work:



    color = [149]
    white = [255]
    im = Image.open('example-files/step1.jpg').convert('L')
    data = np.array(im)
    mask = np.all(data == color, axis=-1)
    data[mask] = white
    new_im = Image.fromarray(data)
    new_im.save('example-files/step6.png')


    What can I do to either remove that color of grey as fast as possible or get it to remove while remaining in greyscale?










    share|improve this question
























      0












      0








      0








      I have a python PIL script that is turning an image into greyscale and then removing a specific shade of grey. I can do this by converting first to rgb and then removing the grey, but I'd like to only be in greyscale.



      color = [149, 149, 149]
      white = [255, 255, 255]
      im2 = Image.open('example-files/step1.jpg')
      im = im2.convert('RGB')
      data = np.array(im)
      rgb = data[:, :, :3]
      mask = np.all(rgb == color, axis=-1)
      data[mask] = white
      new_im = Image.fromarray(data).convert('L')
      new_im.save('example-files/step3.png')


      This works, except I don't ever want to .convert('RGB'), I always want to remain in greyscale, as I want to make this as fast as possible and I found that that extra convert add about .04 seconds. I tried using the data[mask] method while in greyscale and it doesn't work:



      color = [149]
      white = [255]
      im = Image.open('example-files/step1.jpg').convert('L')
      data = np.array(im)
      mask = np.all(data == color, axis=-1)
      data[mask] = white
      new_im = Image.fromarray(data)
      new_im.save('example-files/step6.png')


      What can I do to either remove that color of grey as fast as possible or get it to remove while remaining in greyscale?










      share|improve this question














      I have a python PIL script that is turning an image into greyscale and then removing a specific shade of grey. I can do this by converting first to rgb and then removing the grey, but I'd like to only be in greyscale.



      color = [149, 149, 149]
      white = [255, 255, 255]
      im2 = Image.open('example-files/step1.jpg')
      im = im2.convert('RGB')
      data = np.array(im)
      rgb = data[:, :, :3]
      mask = np.all(rgb == color, axis=-1)
      data[mask] = white
      new_im = Image.fromarray(data).convert('L')
      new_im.save('example-files/step3.png')


      This works, except I don't ever want to .convert('RGB'), I always want to remain in greyscale, as I want to make this as fast as possible and I found that that extra convert add about .04 seconds. I tried using the data[mask] method while in greyscale and it doesn't work:



      color = [149]
      white = [255]
      im = Image.open('example-files/step1.jpg').convert('L')
      data = np.array(im)
      mask = np.all(data == color, axis=-1)
      data[mask] = white
      new_im = Image.fromarray(data)
      new_im.save('example-files/step6.png')


      What can I do to either remove that color of grey as fast as possible or get it to remove while remaining in greyscale?







      python numpy python-imaging-library






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 4:23









      EricEric

      1116




      1116






















          0






          active

          oldest

          votes












          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%2f55056698%2fhow-to-remove-specific-shade-of-grey-from-a-greyscale-image-in-python-pil%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f55056698%2fhow-to-remove-specific-shade-of-grey-from-a-greyscale-image-in-python-pil%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

          1928 у кіно

          Захаров Федір Захарович

          Ель Греко