i'm new here. i using python 3.7 with pillow. i have a lot of images which contain a combination of math formula and arabic word, and i want to crop these image according to the getbbox() function which calculates the boundary box of the non zero region example1. it work well but in the case of long formula doesn't crop all the content of the image example2.
im = Image.open(buf)
bg = Image.new(im.mode, im.size, white)
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff)
bbox = diff.getbbox()
im.crop(bbox).save('output\\original_data\\'+str(i)+'_'+str(j)+'_original.png')