If you put the image in a numpy array, just find the edges that you can use PIL to crop. Here, I assume that the space is the color (255,255,255) , you can adapt to your needs:
from PIL import Image import numpy as np im = Image.open("test.png") pix = np.asarray(im) pix = pix[:,:,0:3]
To show what the results look like, I left the axis labels so you can see the size of the box :
from pylab import * subplot(121) imshow(pix) subplot(122) imshow(region_pix) show()

source share