Python PIL crop based on whitespace bounding box around possible characters

Thursday, July 10, 2014

How would I go about finding the bounding box, x-bound, y-bound, coordinates for a region?


Example code using pyplot adapted from (Using python and PIL how can I grab a block of text in an image?):



Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> from PIL import Image
>>> im = Image.open("C:/Python27/Lib/site-packages/100_1673.JPG")
>>> pix = np.array(im)
>>> pix = pix[:,:,0:3]
>>> pix = 255 - pix
>>> H = pix.sum(axis=2).sum(axis=1)
>>> import matplotlib.pyplot as plt
>>> plt.plot(H)
[<matplotlib.lines.Line2D object at 0x0520E4F0>]
>>> plt.show()


From : http://ift.tt/1lYhgNE but using matplotlib.pyplot


enter image description here


enter image description here Related posts:








http://ift.tt/W1FW2Z