'handleSubRectangles(images)
Handle the sub-rectangle stuff. If the rectangles are given by the
user, the values are checked. Otherwise the subrectangles are
calculated automatically.'

def handleSubRectangles(self, images, subRectangles):

    if isinstance(subRectangles, (tuple, list)):
        xy = subRectangles
        if (xy is None):
            xy = (0, 0)
        if hasattr(xy, '__len__'):
            if (len(xy) == len(images)):
                xy = [xxyy for xxyy in xy]
            else:
                raise ValueError("len(xy)    doesn't    match    amount    of    images.")
        else:
            xy = [xy for im in images]
        xy[0] = (0, 0)
    else:
        if (np is None):
            raise RuntimeError('Need    Numpy    to    use    auto-subRectangles.')
        for i in range(len(images)):
            im = images[i]
            if isinstance(im, Image.Image):
                tmp = im.convert()
                a = np.asarray(tmp)
                if (len(a.shape) == 0):
                    raise MemoryError('Too    little    memory    to    convert    PIL    image    to    array')
                images[i] = a
        (images, xy) = self.getSubRectangles(images)
    return (images, xy)
