title: Remove Image background and create a transparent Image using Python's PIL
body: <p>I'm working on a project in which I need to remove the background of an Image, the only Information we have is that it's an Image which has some (one or more) objects in it, and I need to remove the background and make it a transparent image.</p>
  
  <p><strong>Here's a sample Image:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/uSoJa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uSoJa.png" alt="enter image description here"></a></p>
  
  <p>And, here's what I have tried using PIL:</p>
  
  <pre><code>img = Image.open(url)
  img = img.convert("RGBA")
  datas = img.getdata()
  print('Old Length is: {}'.format(len(datas)))
  # print('Exisitng Data is as: {}'.format(datas))
  newData = []
  for item in datas:
      # print(item)
      if item[0] == 255 and item[1] == 255 and item[2] == 255:
          newData.append((255, 255, 255, 0))
      else:
          newData.append(item)
  img.putdata(newData)
  print('New Length is: {}'.format(len(datas)))
  img.show()
  img.save("/Users/abdul/PycharmProjects/ImgSeg/img/new.png", "PNG")
  print('Done')
  </code></pre>
  
  <p>It saves the same image as input with the name as <code>new.png</code>, nothing has been removed from the image.</p>
  
  <p>When I printed the <code>datas</code> and <code>newData</code> it prints the same values:</p>
  
  <pre><code>Old Length is: 944812
  New Length is: 944812
  </code></pre>
  
  <p>Thanks in advance!</p>