def test_getLabel(self):
        rows, cols = (25600, 25600)
        diag = np.zeros((rows, cols), 'uint8')
        np.fill_diagonal(diag, 1)
        block_size = 256
        for i in xrange(0, rows, block_size):
            for j in xrange(0, cols, block_size):
                if diag[i, j] == 1:
                    diag[i:i + block_size, j:j + block_size] = 255

        thresholds = [0, 0.25, 0.5, 0.75, 1.0]
        block_sizes = [2 ** i for i in range(8, 11)]
        success = "1"
        failure = "0"

        for block_size in block_sizes:
            for threshold in thresholds:
                for i in xrange(0, rows, block_size):
                    for j in xrange(0, cols, block_size):
                        temp = diag[i:i + block_size, j:j + block_size]
                        test_percent = np.count_nonzero(temp) / temp.size
                        if test_percent >= threshold:
                            test_label = success
                        else:
                            test_label = failure
                        assert(test_label==le.getLabel(temp, success, success, threshold),True)
def get_labeled_data(filename, training_file, block_size=32):
    """Read input-array (image) and label-images and return it as list of tuples. """

    rows,cols = load_extension.getDims(filename)
    print rows,cols

    image = np.ones((rows, cols), 'uint8')
    label_image = np.ones((rows, cols), 'uint8')
    # x is a dummy to use as a form of error checking will return false on error
    x = load_extension.getImage(image, filename)
    x = load_extension.getTraining(label_image, filename, training_file)
    X = []
    y = []
    for i in xrange(0,rows,block_size):
        for j in xrange(0,cols,block_size):
            try:
                X.append(image[i:i + block_size, j:j + block_size].reshape(1, block_size * block_size))
                y.append(int(load_extension.getLabel(label_image[i:i + block_size, j:j + block_size], "1", "0", 0.75)))
            except ValueError:
                continue

    X = np.array(X).astype(np.float32)
    label_blocks = np.array(y).astype(np.int32)
    test_blocks = X.reshape(-1, 1, block_size, block_size)

    return test_blocks, label_blocks