title: Removing Border from the Image
body: <p><a href="https://i.stack.imgur.com/Aobnc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Aobnc.png" alt="enter image description here" /></a>I have a set of images like below, where each image consist of the actual image part with the black borders of varying sizes around it. My objective is to remove those borders and just extract the image, which later can be used for other tasks.</p>
  <p>I have tried using canny edge detector, to identify the border and get only the image out of it, however its not working as expected.</p>
  <p>I have also tried techniques mentioned in other posts like below, but these too doesnot work in my case.</p>
  <pre><code>In [1]: from PIL import Image, ImageChops
  
  In [3]: im = Image.open('iI3ZE.jpg')
  
  In [4]: def trim(im):
     ...:         bg = Image.new(im.mode, im.size, im.getpixel((0,0)))
     ...:         diff = ImageChops.difference(im, bg)
     ...:         diff = ImageChops.add(diff, diff, 2.0, -100)
     ...:         bbox = diff.getbbox()
     ...:         if bbox:
     ...:                 return im.crop(bbox)
  
  </code></pre>
  <p>Any leads for the above query would be helpful.</p>