def gen_regions(image, dims, pad, ks):

    print "Generating cropped regions..."
    assert(len(dims) == 3)
    regions = selective_search(image, ks=[ks], feature_masks=[features.SimilarityMask(
        size=1,
        color=1,
        texture=1,
        fill=1,
    )])

    crops = []
    for conf, (y0, x0, y1, x1) in regions:
        if x0 - pad >= 0:
            x0 = x0 - pad
        if y0 - pad >= 0:
            y0 = y0 - pad
        if x1 + pad <= dims[0]:
            x1 = x1 + pad
        if y1 + pad <= dims[0]:
            y1 = y1 + pad
        # Images are rows, then columns, then channels.
        region = image[y0:y1, x0:x1, :]
        candidate = resize(region, dims)
        crops.append((conf, candidate, region, (x0, y0, x1, y1)))

    print "Generated {} crops".format(len(crops))

    return crops
Generates candidate regions for object detection using selective search.
dataset/ETHPy150Open BradNeuberg/cloudless/src/cloudless/inference/localization.py/gen_regions