0

Is there a way to remove ALL colors in the picture except white and subsequently replace the color white to black? Basically I want to remove the fuzz and I realised that only the color white is needed to decode the message.

Any help in python would be appreciated!

Original image:

original


Edited image:

sample edited

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
Candy4
  • 39
  • 1
  • 2
  • 3
    This question (asked by me 6 years ago) and the answers should provide a solution. http://stackoverflow.com/questions/3752476/python-pil-replace-a-single-rgba-color – sberry Sep 06 '16 at 06:03

1 Answers1

5

Here is a simple solution using numpy and PIL:

from PIL import Image
import numpy as np

img = Image.open('pic.jpg')
data = np.array(img)

converted = np.where(data == 255, 0, 255)

img = Image.fromarray(converted.astype('uint8'))
img.save('new_pic.jpg')
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
a.smiet
  • 1,727
  • 3
  • 21
  • 36